search
HomeComputer TutorialsComputer KnowledgeTeach yourself how to write Lisp programs for CAD

Teach yourself how to write Lisp programs for CAD

Jan 08, 2024 pm 02:02 PM
cadlisp basic tutorial docHow to compile lisp program by yourself in cadWhat is the function of lisp in 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!

Statement
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
Zlib1.dll Is Missing or Not Found Error? Fix It with Simple Moves - MiniToolZlib1.dll Is Missing or Not Found Error? Fix It with Simple Moves - MiniToolApr 16, 2025 am 12:52 AM

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

AutoFill Is Not Working in Excel? Here Are Fixes! - MiniToolAutoFill Is Not Working in Excel? Here Are Fixes! - MiniToolApr 16, 2025 am 12:51 AM

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.

Windows 7 Starter Edition: What Is It? How to Download It? - MiniToolWindows 7 Starter Edition: What Is It? How to Download It? - MiniToolApr 16, 2025 am 12:50 AM

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.

Run Apps as Different User in Windows with This Top GuideRun Apps as Different User in Windows with This Top GuideApr 16, 2025 am 12:49 AM

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.

Fixed: Dropbox There Was an Error Downloading Your FileFixed: Dropbox There Was an Error Downloading Your FileApr 16, 2025 am 12:48 AM

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.

5 Ways to Fix Selected Files Are Not Highlighted in File Explorer - MiniTool5 Ways to Fix Selected Files Are Not Highlighted in File Explorer - MiniToolApr 16, 2025 am 12:47 AM

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.

Fix Language Bar Missing from the Taskbar - Proven GuideFix Language Bar Missing from the Taskbar - Proven GuideApr 16, 2025 am 12:46 AM

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

How to Connect an External Drive to an Android Phone or Tablet? - MiniToolHow to Connect an External Drive to an Android Phone or Tablet? - MiniToolApr 16, 2025 am 12:45 AM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools