How to install an application in AutoCAD. How to use Lisp posted on the forum. Other examples of using fields in AutoCAD

Note: AutoLISP programs can only be run on the full version of AutoCAD; they do not work under AutoCAD LT. (excluding cases of downloading additional applications such as LT Extender and similar ones, which are specially designed to run lisp and (or) arx applications in the AutoCAD LT environment.)

Saving program code on your computer

Using the cursor, select this code and copy it to the clipboard by right-clicking and selecting Copy(or Ctrl+C).
Launch Notepad and paste our code using the menu Edit >> Insert(or Ctrl+V):

Code:

(defun C:OFF2 (/ d obj ent adoc *error* undo lays Flag) (defun *error* (msg)(vla-EndUndoMark adoc)) (vl-load-com)(setq adoc (vla-get-activedocument ( vlax-get-acad-object)) lays (vla-get-layers adoc))(vla-StartUndoMark adoc)(setvar "CMDECHO" 0) (if (null *OFF2*)(setq *OFF2* (abs (getvar " OFFSETDIST")))) (if (zerop *OFF2*)(setq *OFF2* 1))(setq d (getvar "UNDOCTL")) (cond ((= d 0) (vl-cmdf "_.UNDO" " _All")) ((= d 3) (vl-cmdf "_.UNDO" "_Control" "_All")) (t nil)) ;_ end of cond (princ "\n Offset value: ") (initget 6 )(if (null (setq d (getdist))) (setq d *OFF2*)) (setq *OFF2* d undo 0 Flag t) (initget "Undo Undo G J Exit Exit U D _Undo Undo Undo Undo Exit Exit Exit Exit") (while Flag (setq obj (entsel (strcat "\n Select object [" (if (not (zerop undo)) "Cancel/" "") "Exit] : "))) (cond ((= obj "Undo")(if (not (zerop undo))(progn (vl-cmdf "_UNDO" "_B")(setq undo (1- undo)))(alert "There is nothing more to undo"))) ((= obj "Exit")(setq Flag nil)) ((null obj)(if (= (getvar "ERRNO") 52)(setq Flag nil)(princ " *** Past ***"))) (t (setq ent (vlax-ename->vla-object (car obj))) (cond ((= (vla-get-lock (vla-item lays (vla-get-layer ent))) :vlax-true) (alert " On the locked layer!")) ((vlax-method-applicable-p ent "Offset)(vl-cmdf "_UNDO" "_M")(setq undo (1+ undo)) (vla-offset ent d)(vla- offset ent (- 0 d))) (t (alert "Unable to create an object similar to this"))))) (initget "Undo Undo G J Exit Exit U D _Undo Undo Undo Undo Exit Exit Exit Exit")) ( vla-EndUndoMark adoc)(princ)) (princ "\nType OFF2 at the command line"))

After pasting the code into Notepad, we should have something like this:

Now we must save the file. The file can be called whatever you like, but its extension must be .LSP. It would be more correct (but not necessary) to name the file the same way as the command is named in the code you found. The command is always preceded by a prefix C: after the word defun. In the example above you can see that the command was named OFF2, accordingly we name the file off2.lsp. This way we can avoid confusion because... we will know what is in the file off2.lsp the team is located OFF2.
Sometimes the code contains multiple functions. You need to find the "main one". Such a function either has a prefix WITH:, or the author of the code himself specifies what to “use as”. In the case of multiple "main" file naming may not have any guidelines.

Loading a lisp file

Next, launch AutoCAD and select Service >> Autolisp >> Download (Tools >> AutoLISP >> Load _appload.
We should see a dialog box like below:

Use the following sequence to download off2.lsp:

  1. Navigate to the folder where you saved the lisp file.
  2. Select the file you want to download from the list.
  3. Click the button Download.
    (If everything went well, you should see the message "off2.lsp loaded successfully")
  4. Click the button Close to complete the command.

Command or function?

First, we need to decide what we have: a team or a function?
A little theory.
In the description of almost any code there is a line like

You can call it (provided that it is loaded) from the command line directly:

Command: test

And actions will be carried out
And here it is:

Then on the command line you need to type command_name> without a prefix C:.

Tips: You can also load a lisp file by dragging and dropping ( drag-and-drop) file icons into the graphic window of an open AutoCAD document.

AutoCAD; error: no function definition:

If your function or command does not work or exits with a message like the example below, then a simple method may help you.

Your lisp should now run without errors.

What is this (vl-load-com)?

This function loads a large number of functions included in the AutoLisp extension, which allows you to work with ActiveX objects, properties, methods and events. A sign that you need to download the AutoLisp extension is the presence in the text of your program of functions starting with prefixes vla-(For example vla- get-activedocument), vlax-(For example vlax- get-acad-object), vl-(For example vl- catch-all-apply) and vlr-(For example vlr- pers).
In any case, it never hurts to add (vl-load-com) to the beginning of the file to avoid such errors.

Organizing a library of Lisp files.

What to do if there are enough files? Dial every time _appload to download this or that application? The most effective way would be to organize your own library. To begin with, let's agree that we will put all our files in one folder. For example, D:\MyLisp. Let's register this folder in the AutoCAD access paths. For this we choose Service >> Settings (Tools >> Options) or type on the command line _options. Go to the bookmark Files (Files) and open the list Access path to support files (Support File Search Path).
We should see a dialog box like the one below:

Use the following sequence to register the folder in the access paths:

  1. Click the button Add.
  2. Click the button Review and select the target folder (in our case, D:\MyLisp)
  3. The folder path should appear in the dialog box.
  4. Click the button OK to complete the command.

Now our folder is registered in the AutoCAD access paths. What does this give us? We can upload our files without specifying a specific path, but only the file name.
We can type in the command line (load "") to download the required code, for example (load "off2"). Please note that adding the extension .lsp not required, although not prohibited.
And finally, most importantly, this will allow us to create panels with buttons for loading a particular program. The button will have the following content:

^C^C(if (null C:)(load ""));;

In our case:

^C^C(if (null C:OFF2)(load "off2"));OFF2;

Autoload files.

If there is a need to load your lsp files when opening a drawing, then you need to add the necessary files to the autoload list.
Launch AutoCAD and select Service >> Autolisp >> Download (Tools >> AutoLISP >> Load) or type on the command line _appload.
In the dialog box that opens, click on the button Applications next to the picture of the briefcase

In the next dialog box, click on the button Add and point to the necessary files.

They should appear in the list of applications.
Now the listed files will be downloaded every time you open a picture.
It is important to understand that (at least in the full version of AutoCAD) loading applications placed in Autoload (Startup Suite), as a rule, runs in all AutoCAD profiles and sessions.
In addition, there is one more point. If there are 2 or more files that describe functions with the same names, the one that was loaded last will be executed. Since it is impossible to predict in what order applications will be loaded, such situations should be avoided.

The process of inserting blocks into a drawing is approximately the same as inserting individual objects. At the same time, you can change the scaling or rotate the block to the desired level. You can also develop a dynamic block with a variety of scaling and copy rotation angles. We will talk about blocks of this type a little later.

How to insert blocks into drawings

To insert a block into a drawing file, you will need to complete the following steps:

  1. Call up the block insertion window.

a) enter “Paste” into the command line.

b) execute the commands Insert>Block.

c) Click the corresponding icon in the blocks panel.

  1. We select inserts of a block or a separate file.

a) To insert a block from a working drawing, select the desired option from the “Name” window.

b) Insert the file using the “Browse” option.

3. Place a flag next to the “Indicate on screen” option. We assign it to the insertion point, scale and rotation angle.

  1. We also check the “Equal scales” option.
  2. And finally, check or uncheck the “Explode” function.
  3. We complete the process by selecting the “Ok” option.
  1. The software will automatically ask you to specify the necessary parameters if they have not been specified previously:
  • Specify the insertion point, as described in the first lesson, the insertion point coincides with the base point of the block.
  • Specify the scale of the inserted block; the default scale is 1:1. In order to change the scale along the axes, when prompted to enter a scale, enter X on the command line. After which the command will prompt you to enter the axis scale X and axles Y. For three-dimensional models, entering scales along the axes is similar. Specifying a negative scale along one axis creates a mirror image relative to the second axis.
  • You can specify the rotation angle either by entering the angle value into the command line or by specifying the angle points with the cursor.

When inserting a drawing file, paper space objects are not included in the insertion; in order to insert such objects, you must define them in the block.

How to use DesignCenter

DesignCenter is an explorer window that helps you select one block from already saved drawings or a library with the ability to preview.

Select a block and insert it into the drawings

  1. Open DesignCenter and press ctrl+2.
  2. We indicate the direct path to the folder with the desired file using Explorer.
  3. In the open folder, open the desired drawing.
  4. This way the user will have access to all parameters and attributes.
  5. Select the blocks tab.
  6. We look at a row of icons with blocks of the selected drawing.

To insert a block, you will need to carry out a procedure similar to that described above.

To insert a block, you can simply drag it onto the open drawing field. The program will automatically prompt the user to edit the drawing. You can insert many blocks of different types, sizes and contents into one drawing.

We're finishing up the lesson on inserting blocks and file systems. Next we will talk about working with their management and library sections.

In many cases, it is necessary to insert a scan, picture, map, photograph, diagram in raster format or other image into AutoCAD as a background in order to work on it with vector AutoCAD tools.

Important: To avoid problems when transferring drawing and underlay files, or copying to other folders, place the DWG drawing and insert (image) files together in the same folder. Or underlays in the "Underlays" subfolder.

Although Autodesk Autocad is a vector editor, it has some capabilities for working with raster images. Shown here using Autocad 2013 version as an example.

So, to insert a picture, use the insert menu.

If you are using the Classic AutoCAD interface, to insert a scanned image or picture into AutoCAD, select menu "Insert" - "Raster Image":

In the window that appears, select the desired file:

To insert a picture into AutoCAD correctly- you need to specify the necessary parameters. For example, try to indicate "Relative" path to the image, this will avoid losing the underlay when moving or copying the DWG drawing. When selecting a tick scale "Point to screen"- after clicking the OK button, you can specify the scale manually with the mouse. Usually they indicate 1 (then it can still be changed using AutoCAD scaling tools), or another coefficient. "Insertion point" - you can specify exact coordinates, or simply point on the screen and then move the substrate if necessary.

You have decided on the parameters, click OK. An image frame will appear:

Click the mouse (if the insertion point is selected "Specify on screen") - the picture will appear in the workspace of the AutoCAD model. By the way, substrates are inserted into the “Sheet” space in the same way.

Advice: If possible, try to use black-and-white (monochrome) images in TIF format with compression, for example CCiTT FAX 4, as backgrounds. It is more convenient to work with them visually in AutoCAD, because they have no background, and also take up little space on the disk and in RAM.

Here is an example of an inserted black and white (not to be confused with grayscale) image:

How to remove the outline of an image inserted into AutoCAD?

If the “extra” frame of the inserted picture interferes with printing and work, you can turn it off with the command: " IMAGEFRAME 0". Enable outline: " IMAGEFRAME 1".

Or through the menu "Edit" - "Object" - "Image" - "Outline". You may need to access this menu enable menu bar in AutoCAD, through the item "Show menu bar".

Then “Edit” - “Object” - “Image” - “Outline”. By the way, there are many more interesting menu items for working with various AutoCAD objects.

Keep in mind that after turning off the outline of an image, you will not be able to select it, and therefore move it and do other operations. To do this, you will need to turn on the picture frame again in the same way.

Fine-tuning the user interface allows you to add your own functions, keyboard key combinations, mouse key combinations, and change standard panels to the functionality of the standard AutoCAD interface.

This instruction is useful for an experienced user who understands which tools he uses often, and which tools are not used at all, or which are missing.

Benefits of Interface Fine Tuning

1. Customize the interface specifically for yourself
2. Adding your own commands
3. Removing unnecessary buttons
4. Adding keyboard shortcuts

After installing AutoCAD and initial setup, we get this interface

I will describe the disadvantages of the layout of this interface:
- All panels are scattered around the perimeter of the screen;
- There are buttons in the toolbars that are not used;
- Command line enabled (reduces visible space);
- Included unnecessary toolbars

Interface fine tuning

1. Organizing toolbars
Include all frequently used toolbars. I'll give you my list
As shown in the figure, all panels are grouped in the upper left corner (it seems to me that we are used to perceiving information from left to right)

2. Set up the command line:
- Ctrl+F9(In AutoCAD< 2010 версии)
- Drag the command line onto the model field and set the transparency to 0%.


Fig.3 Command line transparency.
When you hover over the command line, it becomes opaque.

3. Customize the toolbar.
To start customizing the toolbar, run the command: _CUI(Customize User Interface)


Here you can configure:

  1. Quick launch panel;
  2. Ribbon (for the "ribbon" interface);
  3. Toolbar (toolbars);
  4. Keyboard shortcuts, etc.
3.1. Create your own toolbar and add buttons

Let's create our own toolbar and call it "SCSENG_TOOLBAR"

Go to the section: Toolbar -> RMB -> New Toolbar
Only the following can be added to the toolbar: registered functions and commands. How to register a function in the article "Automating routine tasks or using Lisp, ARX, etc. scripts."
Add "SCSENG_TOOLBAR" to the panel
Commands: " dlina", "plus1", "Deselect All".
Drag the created panel.
Button " Deselect All" allows you to quickly reset selected objects (very convenient when you need to copy or select a lot).

All adding buttons is ready.

3.2 Removing unnecessary buttons
In the toolbar, right-click and delete unnecessary buttons.


By removing unnecessary buttons we save panel space. This is especially useful when using screens with a small diagonal.

3.3 Setting up keyboard shortcuts

4. Saving the configured interface
After setting up the location of toolbars and key combinations, you need to save your workplace.

Rice. 12. Job security

There are many variables in any program. They are used in a variety of places and for different purposes. Any object in the drawing is also a set of variables - coordinates, color, layer, area, etc. And the drawing itself also has a number of properties that can be used to display additional and most importantly relevant information on the drawing. It is for these purposes that fields are used in AutoCAD. They allow you to display the text value of certain variables in the drawing.

In this article I will describe some techniques for using fields; you can come up with many more similar techniques; the principle is approximately the same everywhere.

Technique 1: Landfill area

Let's create an AutoCAD object - a polyline. In my case it is a rectangle. In the geometric properties of the object (ctrl+1) we see the value of the area (area). In order to display it in the drawing, we will use fields. To do this, create a text block and add a field to it:

You can do this in three ways using the button add field (insert field), using hot keys (ctrl+f), or RMB (right mouse button) - add a field

As a result, we get the following picture:

  1. Field category - select from the drop-down list - Objects
  2. Field name select an object
  3. Click on the select button select object
  4. Select the desired object in the drawing
  5. Selecting the data output format
  6. We choose the accuracy with which we will display them
  7. Additional Format opens another panel with more subtle settings.
  8. Set in additional parameters Conversion Factor for example, to display the area value not in square millimeters, but in meters. We can also set a prefix, suffix, separators (integer/fractional parts, for example) and suppress extra zeros.

As a result, in the text we will have a field associated with the object selected in the drawing. If we change the dimensions of the polygon, then the value fields the text will also change. True, not immediately, in order to see the changes you need to “update” the drawing, i.e. execute command _regen.

Trick 2: Print the path to the drawing file

Adding a path to a drawing file is generally similar to adding a field from an object in the drawing discussed above, only in this case the data source will not be the object in the drawing, but the drawing itself.

  1. Field Category - Document
  2. Choose File Name
  3. That’s all, you can click OK, or select several of the possible output formatting options: lowercase, uppercase, etc.

As you can see, with the file path everything is extremely simple. But you can also notice that the document, in addition to the path, has several more properties that few people know about. Namely, you can indicate the author, title, description, etc. to the document. These properties can be used, in addition, you can add your own properties here, the so-called UDA (user defined attributes)

Adding custom properties and fields to an Autocad drawing

Drawing properties can be found in the menu item File\Drawing Properties.. (File\Drawing Properties..)

In the tab General You and I can see the same properties that we saw in the document properties in the field editor. Accordingly, you can also use these fields. But there are not many of them, and their names oblige them to be used for their intended purpose. But there is good news in the tab Custom we can add as much as we like.

  1. Select a tab Custom
  2. Press the button Add
  3. In the window that opens, set Custom Property Name
  4. In the next line we set Value

When creating properties, you should take into account a small nuance: after adding a property, you will not be able to change its name, only its value. You can change the name only by deleting the old property and creating a new one.

New custom properties will be available in the same tab as the file path:

Other examples of using fields in AutoCAD.

This is not a complete list of examples of using fields. This way you can apply fields in blocks when they receive their values ​​directly from the block occurrence in the drawing. You can also obtain properties not only from an object in a drawing or a document, but for example from a drawing sheet, or the sheet set in which this sheet is used.

In addition, fields can be added to the table and calculations can be performed with them. As an option, add the area of ​​the polygons to the table and use the formula to calculate the total area.

Ksati, fields exist not only in AutoCAD. They exist in a similar form and can be used in almost all office applications.

Conclusion

Despite some purely technical difficulties in using fields in a project, their use is extremely important in cases where you constantly work with more or less the same type of projects.

However, these difficulties themselves are overcome with the help of scripts; a number of scripts are given for an automated solution to the problem described in example 1

Technology overview