Home  >  Article  >  Computer Tutorials  >  How to carry out secondary development of CAD Autolisp?

How to carry out secondary development of CAD Autolisp?

王林
王林forward
2024-01-04 10:18:301329browse

How to do secondary development of CAD autolisp

;;;Lamp T4

(defun C:T4206()

The user enters the T4206 execution command (without any parameters) to load and immediately run the subsequent program.

(graphscr)

(setvar "cmdecho" 0)

;;;Command line display off

(setq P1(getpoint "\nPlease specify the placement location of the lamp (T4 206.5mm 6W):"))

;;;Set an insertion point P1 and return the point

(command "-INSERT" "D:/YZ_ZCAD/TK/DGT/T4206.dwg" "S" "1" P1 "0")

When executing CAD standard commands, you can add "-" (refer to CAD commands) in front of the command to execute the command directly in the command line without using the dialog box.

When the program is executed, you cannot use the dialog box to operate. You can add the "-" symbol before the command or use the variable FILEDIA to control it. There are also some special cases that can be controlled in other ways.

(setvar "cmdecho" 1)

;;;Command line display open

(princ)

;;;Conclusion

)

;;;Put the above text into LISP and save it under any English name

After saving the file, we can use AP to load the file in CAD.

;;; Execute the T4206 command to execute the insert command, (confirm the existence of the file)

As far as my personal opinion is concerned, I think VBA development is more convenient than LISP. To learn LISP, you only need to master basic knowledge, and there is no need to study in depth. LISP dialog box development (DCL) is much more complicated than VBA. However, sometimes we need to use LISP functions to execute VBA functions. In the AutoCAD help document, there is help specially provided for developers, which contains a lot of detailed content. Many editors also use resources directly from these documents. I suggest you take a look, it might help you.

CAD secondary development modification LISP

(defun c:dz (/ oce1 n1 zn h1 sxh1 p1)

(vl-load-com)

(setq oce1 (getvar "cmdecho"))

(setvar "cmdecho" 0)

(setq ms (vla-get-modelspace

(vla-get-activedocument (vlax-get-acad-object)) This line of code is used to get the object of the currently active document in AutoCAD. It uses AutoCAD's VLAX (Visual LISP ActiveX) interface, obtains the AutoCAD application object through the vlax-get-acad-object function, and then uses the vla-get-activedocument method to obtain the object of the currently active document. In this way, we can perform various operations on the current document, such as accessing its properties, modifying objects, etc. This line of code is very common in AutoCAD's LISP programming and is very

when working with document objects.

)

)

(if qz

()

(setq qz """)

)

(if hz

()

(setq hz """)

)

(initget "c")

(setq nqz (getstring (strcat "\nPlease enter the prefix /c (empty): " )))

(cond

((= nqz "") (setq qz ""))

(T (if (/= nqz "")(setq qz nqz)))

)

(setq hz """)

(if (not (setq n1 (getint "\nPlease enter the starting sequence number : ")))

(setq n1 1)

)

(setq zn 1)

(if (not (setq h1 (getreal "\nPlease specify the text height : ")))

(setq h1 2.5)

)

(setq sxh1 (strcat qz (itoa n1) hz)) is a common LISP expression. In this expression, qz, n1, and hz are variables, and a new string sxh1 is created by concatenating their values. I'll explain to you exactly what this expression means. - qz is a variable representing prefix, which stores a string, such as "prefix". - n1 is an integer variable that stores a numeric value, such as 10

(setq p1 (getpoint "\nPlease specify the insertion point: "))

(while (/= p1 nil)

(setq p1 (vlax-3d-point p1))

(setq txt (vla-addtext

ms

sxh1

p1

h1

)

)

(setq

n1 (n1 zn)

sxh1 (strcat qz (itoa n1) hz)

p1 (getpoint "\nPlease specify the next insertion point: ")

)

)

(setvar "cmdecho" oce1)

(vlax-release-object ms)

(princ)

)

CAD secondary development LISP master writes a program

can be changed to the following:

(defun c:sdd (dwg)

(setq dwg (getfiled "Select path and file name" "" "Dwg" 1))

(if (wcmatch dwg "*

#-##-

#:##.dwg")

(setq dwg (substr dwg 1 (vl-string-search " " dwg)))

Given a string variable `dwg`, we can use `(setq dwg (substr dwg 1 (- (strlen dwg) 4)))` to process it. The function of this line of code is to truncate the last four characters of the `dwg` string and reassign the result to the `dwg` variable. This may be done to strip file extensions from file names or other identifiers. Through this line of code, we can modify the `dwg` string so that it meets specific requirements or formats.

)

(setq dwg (strcat dwg " " (menucmd "M=$(edtime,$(getvar,date),YYYY-MO-DD HH:MM)") ".dwg"))

(command "_.saveas" ""” dwg)

(princ)

###)###

The above is the detailed content of How to carry out secondary development of CAD Autolisp?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:docexcel.net. If there is any infringement, please contact admin@php.cn delete