LISP Programs. How to insert blocks and files into drawings in AutoCad How to run a lisp application command

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 withdraw text value 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 press OK, or select several from possible options output formatting: 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 far from full list 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 a 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

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.

Advantages Fine tuning interface

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 and drop command line on 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

Note: AutoLISP programs can only be run on full version AutoCAD, they do not work under AutoCAD LT. (excluding cases of loading additional applications type LT Extender and the like, 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 clicking right button mouse 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 graphics window open document AutoCAD.

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 expand 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 necessary files to the autoloading 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.

Now let's look at how to put it into practice.

Applications with the following file extension are available for AutoCAD: *.arx, *.crx, *.lsp, *.dvb, *.dbx, *.vlx, *.fas. Let's look at the example of LISP, which allows you to align text relative to a specified point along the X or Y axis (download the file “Text Alignment.lsp”).

How to install a *.lsp file in AutoCAD?

1. Go to the “Management” tab and in the “Applications” panel, select the “Download application” command. You can use the command system in AutoCAD and enter “_appload”.

2. The “Load/Unload Applications” dialog box will open, through which you need to find a suitable file with the extension *.lsp or others, which was listed above.

3. After completing the steps, click the “Download” button.

4. After a successful download message appears at the bottom of this dialog box, you can test installed application. Click the "Close" button.

How to run a lisp application command?

Commands cannot be viewed in AutoCAD lisp. You should start from the source file that was loaded into the program.

We said earlier that The script file can be opened using regular Notepad. Typically at the very top of this text document developers leave all the necessary information for work, including the name of the team that will run LISP. IN in this example This " z-text-align", so you need to enter just such a request on the command line to call the tool.

How to load lisp into AutoCAD LT?

With the question: “How to install Lisp in AutoCAD” everything is clear. But how to load it into similar programs, for example, AutoCAD Electrical/Mechanical?

Unfortunately, applications written in AutoLISP only work on the full version AutoCAD programs . Therefore, such scripts cannot be implemented in AutoCAD LT or other versions.

The concept that guides the company is the priority of quality in everything due to compliance with the requirements of the modern market, constant improvement of the effectiveness of the management system, quality and monitoring of completed projects

Inventory, accounting of green spaces, entering inventory data into the AIS “Register of Green Spaces” in Moscow, production of a “Passport for Territory Improvement”

Primary activity inventory of green spaces, accounting of green spaces, production of Territory Improvement Passports, entering data into the AIS Register of Green Spaces, approval of Territory Improvement Passports in the Housing and Public Administration and Department of Environmental Protection.

We have been engaged in inventory and certification of green spaces and road facilities in Moscow for 9 years.

During this time, we have inventoried about 5,000 hectares:

Landscaped areas of maintenance categories 1, 2, 3,

Forests, parks, squares, roads, courtyard areas, incl.

Alexander Garden (garden near the Moscow Kremlin),

Kremlin embankment, green areas on Red Square near GUM,

New Arbat, Intercession Cathedral, Shopping and entertainment complex "Manezh",

Solntsevo district, Vernadskogo Avenue district, Dorogomilovo district, Troparevo-Nikulino district,

Area Vykhino-Zhulebino, Lefortovo, Maryino, Nekrasovka, Ryazansky

Southern Administrative District,

South-Eastern Administrative District,

Districts of New Moscow (TiNAO),

Squares and parks of the Central Administrative District,

Green areas along the Moscow Ring Road,

Green areas along the Third Transport Ring,

Vnukovo Airport,

All-Russian dispatch center Vnukovo,

All radial highways of Moscow (Shchelkovskoe highway and Entuziastov highway, Altufevskoe and Yaroslavskoe highways, Kashirskoe and Varshavskoe highways, Mozhaiskoe and Rublevskoe highways, Volokolamskoe and Zvenigorodskoe highways, Mezhdunarodnoe highway, Kyiv highway, etc.)

A large number of hospitals, clinics (GBUZ), schools (GBOU), industrial and commercial areas, and this is not an exhaustive list of territories that we have certified.

Basis for performing work on the inventory of green spaces in Moscow:

Decree of the Moscow Government of August 12, 2014 No. 461-PP “On the automated information system “Register of Green Spaces” (as amended on October 4, 2017)”;

Decree of the Moscow Government of September 10, 2002 N 743-PP (as amended on October 4, 2017) “On approval of the Rules for the creation, maintenance and protection of green spaces in the city of Moscow”;

Decree of the Moscow Government of September 2, 2014 No. 501-PP “On the development of passports for the improvement of courtyard areas, amendments to the legal acts of the city of Moscow and the recognition of the legal acts of the city of Moscow as invalid”;

Moscow City Law No. 17 dated May 5, 1999 “On the protection of green spaces” (as amended on May 7, 2014).

An inventory of the territories of the green fund of the city of Moscow is carried out in order to:

Obtaining reliable data on the condition of green spaces, species, age composition, quantitative and areal characteristics of natural communities, elements of comprehensive improvement for urban management at all levels of management, operation and financing;

Obtaining information about the location of green spaces, elements of comprehensive improvement on the territory of the green fund of the city of Moscow, indicating the legal holders of land plots responsible for its safety and condition;

Determining the compliance of the activities carried out by the rights holders of land plots in the territory of the green fund of the city of Moscow on landscaping objects with the established purpose of the territories;

Conducting an analysis of the state of the green fund of the city of Moscow;

Definitions of areas of land occupied various types plantings, infrastructure or other elements in their composition;

Information support for the preparation of planning projects for natural, specially protected natural (hereinafter - SPNA) (for which there are no planning projects), specially protected green (hereinafter - SPNA), green areas and other territories occupied by green spaces, the city of Moscow;

Development of measures for the conservation and restoration of natural communities and recommendations for management of land plots; infrastructure and improvement elements in specially protected natural and other natural areas for the audit period for management of the State Budgetary Institution "Moscow City Management of Natural Areas";

Determining the effectiveness of reforestation work, the quality of the created forest crops, their compliance with current standards and technical specifications. These materials make it possible to identify measures to improve the condition of crops;

Development of proposals for adjusting planning projects for protected areas, natural, green areas and other areas occupied by green spaces in the city of Moscow, territorial development schemes for protected areas in the city of Moscow;

Regulation of work and determination of costs for the preservation and maintenance of natural communities, green spaces, landscaping elements and comprehensive improvement and major repairs on the territory of the green fund of the city of Moscow (based on the obtained characteristics of the condition of landscaping elements and comprehensive improvement);

Drawing up a title list of green spaces, landscaping elements and comprehensive landscaping to calculate natural indicators for the territories of the green fund of the city of Moscow;

Preparation of data for filling the State Cadastre of Protected Natural Areas of the city of Moscow, the Automated Information System "Register of Green Spaces", Automated system management "United Dispatch Service of the Department of Housing and Communal Services and Improvement of the City of Moscow" (hereinafter - ASU "UDS DZHKhiB"), others information systems of the city of Moscow, if so established by law Russian Federation and the city of Moscow.

Types of work on certification of green spaces:

1.Conduct preparatory work

Obtaining the boundaries of the inventory territory;

Reconnaissance survey of the inventory territory;

Establishing the area of ​​the inventory territory;

Establishing the classification of an inventory item

Determination of the location of trees in nature on the inventory territory;

Determining the location of shrubs in nature on the inventory territory;

Collection general information about the territory being inventoried (including administrative-territorial affiliation;

Indication of the responsible land user;

Establishing the status of the object, the functional purpose of the land plot;

2.Carrying out field work on inventory of green areas:

Geodetic survey of the inventory territory using geodetic equipment and local measurements;

Determination of woody vegetation in kind, numbering in kind, measurement of diameter, age, height, description of condition;

Determination of shrub vegetation in nature, numbering in nature, measurement of diameter, age, height, description of condition;

Determining the condition of lawns, measuring the area, describing quality characteristics, determining the type of lawn;

Description of flower beds, area measurement, assignment serial number, determination of the type of flower garden, plant material planted;

Description of the road and path network, determination of condition, type of coverage, purpose, measurement of area;

Determination of the location of the LFA and improvement elements, their quantity, numbering, characteristics and description of the condition;

Identification of buildings and structures on the inventory territory, their purpose and measurement of area;

Determination of planar structures, their type, area and coverage;

Determination of relief organization elements, their type, area;

Determination of functional support systems, their type and quantity;

Collection of information about repair work;

Collection additional information(date of last repair or reconstruction, mode of urban planning activities);

3.Carrying out desk work on inventory of green areas:

Creation of an inventory plan for the object M1:500, with registration in accordance with the Decree of the Moscow Government dated October 4, 2005 No. 770-PP “On methodological recommendations on the preparation of dendrological plans and accounting statements";

Drawing of tree and shrub vegetation on the plan with assignment of serial numbering in accordance with the list of green spaces;

Calculation of the total area of ​​the object and entering data into the statement;

Drawing flower beds on the plan, calculating their areas and entering them into the statement;

Drawing on the plan of buildings and structures, calculating their areas and entering them into the statement;

Calculation of the operational area of ​​the facility and entering data into the statement;

Drawing planar structures on the plan, calculating their areas and entering them into the statement;

Drawing the road and path network on the plan, calculating its areas and entering it into the statement;

Drawing the lawn on the plan, calculating the area and entering it into the list;

Drawing on the MAF plan, calculation by quantity and entry into the list by type;

Drawing of functional support systems on the plan, calculation of quantity and entry into the list by type;

Drawing on the plan the elements of the organization of the relief, calculating the areas and entering them into the statement;

Typing and printing field report data on a computer;

Calculation of the total number of trees on the site;

Calculation of the total number of shrubs at the site;

Calculation of trees to be transplanted at the site;

Calculation of transplanted shrubs at the site;

Calculation of trees to be cut down at the site;

Calculation of shrubs to be cut down at the site;

Calculation of trees to be saved on the site;

Calculation of preserved shrubs on site;

Drawing up a balance of the territory;

4.Conduct cartographic works:

Providing electronic accounting of landscaping objects and green spaces when maintaining the AIS “Register of Green Spaces” and monitoring green spaces;

Drawing up a topographic plan in in electronic format with reference to the Unified State Cartographic Basis of the City of Moscow in formats that ensure free import of data into geographic information systems;

Drawing up an inventory plan in accordance with existing requirements M1:500;

Approval of the Territory Improvement Passport in electronic form in the Department of Housing and Communal Services and the Department of Natural Resources and Environmental Protection.

We are proud of the work we have done, because... Our main principle in any work is honesty, integrity, and love for the work you do.

Completed projects



News: April 2, 2015 New requirements for approvals of Territory Improvement Passports Instructions on how to approve a passport for the Customer in the Register. March 30, 2015 Explanations on changes in requirements for passports for improvement of territory (registration area) In the passport of the registration area, the name (Passport of Territory Improvement) and the approval procedure have changed. March 29, 2015