Teach yourself how to write Lisp programs for CAD
How to compile lisp program by yourself in CAD
Constructed two commands: hide and show.
I wrote it simply, but the functions are not complete. You can use it as you like
Copy the following code and create acad.lsp. Place it in the first layer folder of the CAD installation directory and it can be loaded automatically:
; Enter the command hidden on the command line, and then select the graphics elements. As a result, the unselected elements are changed to the hidden layer
(defun C:hidsel(/ all;all primitives
xs;Non-hidden primitive
yc;Hide primitive
n nam dat)
(setvar "CMDECHO" 0); turn off command echo
(command "_layer" "n" "Temporarily hidden layer""")(command "_layer" "off" "Temporarily hidden layer" "")
(setvar "CMDECHO" 1)
(setq all (ssget "x")); select all
(setq xs (ssget)); select non-hidden primitives
(setq n -1 yc all);Operation hidden primitive
(repeat (sslength xs)
(setq n ( n 1))
(setq nam (ssname xs n)); Return the name of the Nth primitive
(setq yc (ssdel nam yc))
)
(setq N -1);Hide
(repeat (sslength yc)
(setq N ( n 1))
(setq nam (ssname yc n)); Return the name of the Nth primitive
(setq dat (entget nam));DAT stores the Nth element data
(entmod (subst (cons 8 "Temporarily hidden layer") (Assoc 8 dat) dat)); Hide the yc collection
)
(setq all nil xs nil yc nil n nil nam nil dat nil); clear data occupied memory
(princ)
)
;Show all primitives
(defun c:shoal(/ all n nam dat)
(setq all (ssget "x")); select all
(setq N -1);Hide
(repeat (sslength all)
(setq N ( n 1))
(setq nam (ssname all n)); Return the name of the Nth primitive
(setq dat (entget nam));DAT stores the Nth element data
(entmod (subst (cons 8 "0") (Assoc 8 dat) dat)); Hide the yc collection
)
(setvar "CMDECHO" 0)
(COMMAND "PURGE" "LA" "Temporarily Hide Layer" "Y" "Y" """)
(setvar "CMDECHO" 1)
(setq all nil n nil nam nil dat nil); clear data occupied memory
(princ)
)
What is the function of lisp in CAD? How to use it? Extra points if I can understand it in detail
Lisp itself is a development program belonging to CAD. It provides some simple function calculations, and the rest is all for the drawing functions of autocad. The lisp program is similar to the stored procedure in the database and can process and draw cad graphics in batches.
Learning lisp is very simple. You only need to master the use of a few main commands. You also need to study the statement format very carefully. Lisp itself has quite a few functions, so you don’t need to memorize them.
Load LISP
1. You can use the APPLOAD command, then find the LISP file to be loaded and load it.
2. You can drag the LISP file from the file manager to the graphics window of ACAD, or you can load it
3. Use it after the command line, (load "c:\\temp\\xxx.lsp") can also be loaded. Please enter the actual path for the path name.
Another: For an LSP program, (what follows defun is a command or function. Generally, the program should have a prompt. If not, the words following the identifier c: are commands that can be used under ACAD, either after COMMAND: Just enter it directly to execute.
How to program several LISP languages in CAD
AutoLISP language is a programming language that is based on the ordinary LISP language and expands many functions suitable for CAD applications. It is an interpretive value language that is slow and difficult to keep secret. It can be edited with any text editing software and saved in plain text format. For example:
(setq i 1); that is, the value of code i is 1
(command "CIRCLE" '(0 0) 100); Command to draw a circle with a radius of 100 at the coordinate origin.
All components in the AutoLISP language are given in the form of functions. It has no statement concepts or other grammatical structures. Executing an AutoLISP program means executing some functions and then calling other functions. For example:
(setq pt1 (getpoint "\nPlease select the center insertion point"))
(command "CIRCLE" pt1 100); Command this insertion point to draw a circle with a radius of 100
AutoLISP expresses data and programs into a unified table structure, so programs can be processed as data, and data can also be executed as programs.
For example: a straight line, starting point coordinates' (0 0), end point coordinates' (1000 0), layer 0, color 1 [red] This is some data of a straight line, how to execute it into program code as follows:
(entmake (list '(0 . "LINE") '(8 . "0") '(62 . 1) '(10 0 0) '(11 1000 0)))
You can view the data visually, or you can paste it into the command line of AutoCAD to draw the straight line you want above.
The program running process in AutoLISP language is the process of processing function values, and the function of the function is realized in the process of processing function values. In AutoCAD, all objects can be regarded as composed of countless points, each point has its own coordinates. The operation of the function is to calculate the values of these points and make judgments based on the obtained values.
The main control structure of AutoLISP language is recursive. The use of recursion makes programming simple and easy to understand. For example:
(setq &k1 (entsel)); select object
(setq &k1 (car &k1)); Extract primitives
(setq #g1 (entget &k1)); Get attribute list
(setq c0 (cdr (assoc 0 #g1))); Get the primitive name
The above is written down one by one, it can be written as follows:
(setq c0 (cdr (assoc 0 (entget (car (entsel)))))); simple and easy to understand
Because autolisp is simple and easy, you can get started quickly. After writing a program, the drawing efficiency can be greatly improved. The famous [Tianzheng] plug-in is a good helper for drawing.
The autolisp program also has shortcomings, such as extracting coordinates. This can only be extracted from the primitive attributes. In this case, there will be limitations. The coordinate values of normal coordinates 1 and -1 are the same, but the positions of the graphics are different, resulting in It is difficult to calculate coordinates, so it is best to use the VLAX function to extract coordinate values.
The above is the detailed content of Teach yourself how to write Lisp programs for CAD. For more information, please follow other related articles on the PHP Chinese website!

What is zlib1.dll? Some people encountered the “zlib1.dll is missing” error or zlib1.dll not found error when they attempt to open an application that includes zlib1.dll. To fix these related errors, this article on php.cn Website can give you some i

Some of you might find that AutoFill is not working in Excel. Can you come up with any solutions on that? If not, then you have come to the right spot. This post on php.cn Website will provide you with 6 ways to solve Excel AutoFill not working.

What is Windows 7 Starter Edition? What are the limitations of Windows 7 Starter Edition? How to get the Windows 7 Starter Edition ISO? This post from php.cn provides detailed information about Windows 7 Starter Edition for you.

When running an App, are you troubled with changing accounts by logging out of the present one and then logging in to another? php.cn has collected some effective ways to help you run apps as a different user in Windows 10 and Windows 11.

Are you suffering from the “Dropbox there was an error downloading your file” error in Windows? Now read this post given by php.cn to get several useful solutions to this problem.

Are you troubled by the problem of “selected files are not highlighted in File Explorer”? Do you know how to fix it? If not, you can read this post on php.cn to get several feasible solutions to make selected files visible in File Explorer.

The language bar is essential if you work with multilanguage. You can change the input language by tweaking the setting from the taskbar. But the language bar might disappear one day when you open the computer. How to fix the language bar missing fro

Want to use an external drive to expand your phone’s storage? It is possible to do this. This php.cn post shows you a guide on how to connect an external drive to a phone. Besides, if you need to recover data from your external drive, you can try php


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools