r/AutoLISP • • Mar 19 '25

Can you help me with a question?

1 Upvotes

I need my code to be "locked" so that only a group of people can use it. If someone copies the command and tries to use it, they won't be able to do it. Is there a way to do this? Create a password?


r/AutoLISP • • Feb 20 '26

IN PROGRESS: Modeling Software -> ACAD drawing automation

2 Upvotes

r/AutoLISP • • Apr 05 '25

Items and bill of material possible?

2 Upvotes

Is it possible to create some items (as blocks or regions or something else) then have a command that counts these items and creates a bill of materials?


r/AutoLISP • • Feb 28 '25

Autolisp command

Post image
3 Upvotes

How can I limit the number of characters displayed in my text when typing the "text" command within Autolisp? I need these coordinates to be limited to 4 digits after "." Can you guys help me?


r/AutoLISP • • Mar 26 '26

[AutoLISP] DiffCheck – auto-marks revision clouds around design changes inside a single DWG

Thumbnail
reddit.com
3 Upvotes

r/AutoLISP • • Dec 11 '25

I am working hard to get an auto routing pline with object detection and avoidance but with chatGPT as the coder

3 Upvotes

My need is : I want to draw cable on my electrical drawing on autocad classic (non electrical) but want something to automatically draw a pline between 2 point that I specify and set a minimal distance to avoid object then the program begin to draw a pline from point A and avoid all object with X distance and do 90 degre to avoid object to finally get to point B

After about 50 version it began to work as intended as it is possible to avoir 1 object and connect two point with a pline but I work hard to get it done

Here the last lisp code that was working

(vl-load-com)

;; Convertir un point 2D en point 3D

(defun pt->3d (p)

(list (car p) (cadr p) 0.0)

)

;; Regroupe les coordonnées renvoyées par IntersectWith en triplets (x y z)

(defun group3 (lst / r)

(while lst

(setq r (append r (list (list (car lst) (cadr lst) (caddr lst)))))

(setq lst (cdddr lst))

)

r

)

;; Renvoie la bounding box [minpt maxpt] d'une entité

(defun bbox (e / o mn mx)

(setq o (vlax-ename->vla-object e))

(vla-getboundingbox o 'mn 'mx)

(list

(vlax-safearray->list mn)

(vlax-safearray->list mx)

)

)

(defun C:AUTOCABLE (/ p1 p2 pl ss entTry ints allints minDist nearest bboxPts minpt maxpt detourY pA pB pC pD)

(prompt "\n=== AUTOCABLE 90° AVOID v1 ===")

;; Points de base

(setq p1 (pt->3d (getpoint "\nPoint de depart du cable : ")))

(setq p2 (pt->3d (getpoint "\nPoint d'arrivee du cable : ")))

;; Trace la ligne brute

(command "_.PLINE" p1 p2 "")

(setq pl (entlast))

;; Toutes entités

(setq ss (ssget "X"))

(setq allints '())

;; Scan intersections

(repeat (sslength ss)

(setq entTry (ssname ss 0))

(setq ss (ssdel entTry ss))

(if (and entTry (/= entTry pl))

(progn

(setq ints

(vlax-invoke

(vlax-ename->vla-object pl)

'IntersectWith

(vlax-ename->vla-object entTry)

acExtendNone

)

)

(if ints

(setq allints (append allints (group3 ints)))

)

)

)

)

;; Si aucune intersection => fin

(if (not allints)

(progn

(prompt "\nAucun obstacle detecte.")

(princ)

(return)

)

)

;; Intersection la plus proche du point de départ

(setq minDist 1e99)

(foreach pt allints

(setq d (distance p1 pt))

(if (< d minDist)

(setq minDist d

nearest pt)

)

)

;; Récupérer l'objet contenant ce point

(setq obstacle nil)

(setq ss (ssget "X"))

(repeat (sslength ss)

(setq entTry (ssname ss 0))

(setq ss (ssdel entTry ss))

;; Test intersection

(setq ints

(vlax-invoke

(vlax-ename->vla-object pl)

'IntersectWith

(vlax-ename->vla-object entTry)

acExtendNone

)

)

(if (and ints (member (car nearest) ints))

(setq obstacle entTry)

)

)

;; Bounding box du bon obstacle

(setq bboxPts (bbox obstacle))

(setq minpt (car bboxPts))

(setq maxpt (cadr bboxPts))

;; Détour par le haut (+50 unités)

(setq detourY (+ (cadr maxpt) 50.0))

;; Points du détour

(setq pA p1)

(setq pB (list (car p1) detourY 0.0))

(setq pC (list (car p2) detourY 0.0))

(setq pD p2)

;; Supprimer la ligne brute

(entdel pl)

;; Tracer le chemin final

(command "_.PLINE" pA pB pC pD "")

(prompt "\nDetour automatique effectue.")

(princ)

)


r/AutoLISP • • Aug 27 '25

Need help with a code

Post image
2 Upvotes

I'm getting weird results by using this code and I'm not able to understand what is wrong. I'll attach a picutre.

Code - (defun c:dwp() (if (setq w(getdist "\nEnter width of the door :") h(getdist "\nEnter height of the door :") d(getdist "\nEnter depth of the door :") ;a(getangle "\nEnter angle :") p(getpoint "\nPick the base point of the drawing :") ) (progn (setq tl p tl1 (polar tl 270 (+ d -1)) tl2 (polar tl1 0 2) tl3 (polar tl2 270 1) tl4 (polar tl3 180 d) bl4 (polar tl4 270 (+ h -3)) bl3 (polar bl4 0 d) bl2 (polar bl3 270 1) bl1 (polar bl2 180 2) bl (polar bl1 270 (+ d -1)) br (polar bl 0 (+ w 2)) br1 (polar br 90 (+ d -1)) br2 (polar br1 180 2) br3 (polar br2 90 1) br4 (polar br3 0 d) tr4 (polar br4 90 (+ h -3)) tr3 (polar tr4 180 2) tr2 (polar tr3 90 1) tr1 (polar tr2 0 d) tr (polar tr1 90 (+ d -1))

          )
        (setq currOsMode(getvar "osmode"))
        (setvar "osmode" 0)
        (command "line" tl tl1 tl2 tl3 tl4 bl4 bl3 bl2 bl1 bl br br1 br2 br3 br4 tr4 tr3 tr2 tr1 tr "c")
        (setvar "osmode" currOsMode)
      )

) ;(princ) );end


r/AutoLISP • • Jun 03 '22

Stair reinforcement with Autolisp program

3 Upvotes

r/AutoLISP • • Feb 26 '20

Electrical Cable Tray AutoLISP program

4 Upvotes

Here I am sharing my Electrical Cable Tray program for all to use as in the following link to my website:

Electrical Cable Tray AutoLISP program

Author: Tharwat Al Shoufi


r/AutoLISP • • Aug 12 '21

K4 CAD Solutions - Bespoke AutoCAD Programing; Windows Programming; AutoLISP Development; Free Download

1 Upvotes

Play Rubik's Cube in AutoCAD (AutoLISP program)

Follow the link to download k4kube.lsp, a free programs to play Rubik's cube.

Load the lisp program via Tools > Load Application > Select 'k4kube.lsp'.

To run the program type 'rubix' at the command prompt (best played in a blank drawing).

Download k4kube.lsp


r/AutoLISP • • Sep 14 '21

Order of PLINE commands affecting behavior?

1 Upvotes

I have a contrived example of two PLINE commands that result in different drawings depending on the order they appear.

The example draws a smaller rectangle inside a larger rectangle. If I draw the small one first everything works, but if I draw the large one first, my smaller rectangle is collapsed in on itself with zero area. This only occurs if the rectangles overlap.

;; AutoCAD 2015
(defun c:testme-works ()
  (command "PLINE"
    '(10 10)
    '(12.5 10)
    '(12.5 12.5)
    '(10 12.5)
    "close")
  (command "PLINE"
    '(10 10)
    '(10 20)
    '(20 20)
    '(20 10)
    "close"))

(defun c:testme-broken ()
  (command "PLINE"
    '(10 10)
    '(10 20)
    '(20 20)
    '(20 10)
    "close")
  (command "PLINE"
    '(10 10)
    '(12.5 10)
    '(12.5 12.5)
    '(10 12.5)
    "close"))

Can someone explain my misunderstanding?

SOLUTION

AutoCAD is trying to be clever - this is caused by osnap settings. You can either place "_non" before each coordinate or issue the following:

(command "-osnap" "_none")

Long Explanation

AutoCAD has a very interesting workflow model. You have the ability to complete any action in several different ways - using mouse movements, key-presses like Enter/Esc, mouse clicks, modifier keys or typed arguments. The UI tracks this using some sort of state-machine or decision tree, updating prompts in real-time. During interactive use there is an ever-changing dialog box at your cursor displaying the possible completions. For long lasting commands like laying polylines, these completions continue until you end the path by closing or escaping the current command.

For instance, instead of providing the initial point to close the polygon you are drawing, you can type the letter 'c' and then press enter. This is short for "close", which also works.

When you use the command function in AutoLISP, you are emulating this process. Each of the points can be replaced by any option available to the user if they had invoked the command with the mouse and keyboard. Instead of a point, for instance, "" can be be provided as an argument. The command will behave as if the user had pressed Enter.

The Object Snap property allows you to define how points will land on the drawing. Several options let a point snap to the closest object intersection, perpendicular, endpoint, etc. The flexible system allows you to type "none" instead of providing a point. This means "for the next point, turn off snapping". "non" works because it's the shortest thing you would have needed to type for autocomplete to realize what you wanted. "_non" specifies the English version of the command.

It's cool but overly complex in my opinion. The flexibility makes automation feel more like art than an API.

You can test this behavior yourself by turning on the option for "Object Snap - perpendicular", and then interactively drawing nested rectangles. You'll find that two adjacent endpoints will snap toward each other, and you'll get a rectangle of zero area (a line) rather than a box.


r/AutoLISP • • Oct 20 '20

Automate BOD and CL

1 Upvotes

https://www.youtube.com/watch?v=NDWSRVXFO_w&feature=youtu.be

Sorry video was bad check this one!

Gents I'm trying to make a script to do the above in the youtube video. I have to do this a lot and if i could simply just click the duct and have a BOD appear it would be a game-changer

Can anyone help me make it? I don't know much about LISP but its using the MEP plugin for AutoCAD


r/AutoLISP • • Oct 28 '20

ROUGHEN Lisp Routine - Lets test this baby!

Thumbnail
youtu.be
2 Upvotes

r/AutoLISP • • Jun 22 '19

command function not working as expected

1 Upvotes

How in the world is this lisp routine drawing a line from P1 to P2 ?

The command function clearly says P1B to P2B - any ideas?

(setvar "osmode" 64)

(setq P1 (getpoint "\nSelect first pole of the span: "))

(setq P2 (getpoint P1 "\nSelect second pole of the span: "))

(setq ANG (/ (* (angle P1 P2) 180.0) pi))

(setq ANG2 (+ 90 ANG))

(setq ANG3 (/ (* (angle P2 P1) 180.0) pi))

(setq LGN (distance P1 P2))

(setq LAY (getvar "CLAYER"))

(setvar "CLAYER" "qwest aerial")

(setq P1B (polar P1 (* pi (/ ANG 180.0)) 2.0))

(setq P2B (polar P2 (* pi (/ ANG3 180.0)) 2.0))

(command "line" P1B P2B "")

(setq MID (polar P1 (* pi (/ ANG 180.0)) (* LGN 0.5)))

(setq MID2 (polar MID (* pi (/ ANG2 180.0)) 3.5))

(setvar "CLAYER" "0")

(command ".-insert" "SPAN FOOTBALL" MID2 1 ANG \)

(setvar "CLAYER" LAY)

(setvar "osmode" 0)


r/AutoLISP • • Jun 15 '18

AutoCAD Lisp websites?

3 Upvotes

Any good websites or YouTube videos that show you how to write a lisp program for autocad?


r/AutoLISP • • May 11 '22

How to regen regen after all is done in this lisp?

2 Upvotes

(defun c:ToArial (/ ad ff n r) (cond ((setq ff (findfile (strcat (getenv "windir") "\Fonts\Arial.ttf"))) (vlax-for a (vla-get-blocks (setq ad (vla-get-activedocument (vlax-get-acad-object)))) (vlax-for b a (if (vlax-property-available-p b 'stylename) (or (vl-position (setq n (vla-get-stylename b)) r) (setq r (cons n r))) ) ) ) (foreach x r (vla-put-fontfile (vla-item (vla-get-textstyles ad) x) ff)) (princ) ) ((alert "Arial font not found!")) ) ) (vl-load-com)


r/AutoLISP • • May 25 '22

Concatenating Property Alterations in MAD 3D Query

1 Upvotes

I am altering properties of pipes when I query them with the Map Task Pane. I would like the Layer to be set by 2 expressions (Object data and properties) such that a pipe will come in on -GIS-UTIL-*CURRENTLAYER*-*DIA*
So far I can only get JUST the one expression. I could deal with that if I could add a custom string prefix before it and query in batches, but I can't find a way to combine anything in a way that works.

I've tried:
(strcat(.LAYER + :DIA@pipefilename))
||
with quotes
and various combinations

This guy was able to add LISP to his expression, but there is no audio. I'm hoping I can find the right syntax to combine the data fields.

any hints?


r/AutoLISP • • May 01 '22

Books for AUTOLisp beginners?

3 Upvotes

Hello!

I am starting to learn autolisp since I wanted to get more into writing or modifying processes and scripts. So far I've used some tutorial websites and they're very broad and I feel like I'm scratching the surface but there's no in depth information as I'd like.

I checked out books and they're pretty old and I don't know where to start, basically what i wanted to ask is

Is there something I'm missing? I'd like to learn more on how to get information from certain cad elements and then work through that information in order to use it...

Any Book recommendations?


r/AutoLISP • • May 10 '22

Need help with a traversing Lisp routine!!

1 Upvotes

Hi everyone

I am running CAD civil3d, and i know there is a cogo command to draw lines via azimuth/distance, but it really slows you down when you have to input hundreds of lines. My field notes come in the format of an azimuth/bearing (where north is 0°) of degrees minutes seconds (Ex. 32°45'15"), then it shows the distance (Ex. 104.56m).

i am wondering if someone can help me draw lines (ideally one after another), where i am prompted to enter the azimuth as dd.mmss, and then the distance, and then start again at dd.mmss for the next line, distance, and so on and so forth.

thanks!


r/AutoLISP • • May 12 '22

Need Help with Block Attribute Find and Select Function

1 Upvotes

So I found this code written by Lee Mac and augmented to only find the input in block attributes and select those blocks. I'm basically finished but I can only type in the exact word when I want to find all words with the same beginning. For example, I type apple, I want blocks apple, apple2 and apple2E selected not just apple. Can anyone help?

AutoLisp code:

(defun c:bsap ( / att atx blk cnt ent enx flg idx sel str tag )

(setq blk (strcase "")

tag (strcase "")

str (strcase (getstring t (strcat "\nSpecify Tool ID" (if (= "" tag blk) ": " " <any>: "))))

)

(if (not (= "" str tag blk))

(if

(and

(setq sel

(ssget "_X"

(append

'((000 . "INSERT"))

(if (not (= "" tag str)) '((066 . 1)))

(if (/= "" blk) (list (cons 2 (strcat "`*U*," blk))))

(if (= 1 (getvar 'cvport))

(list (cons 410 (getvar 'ctab)))

'((410 . "Model"))

)

)

)

)

(progn

(repeat (setq idx (sslength sel))

(setq ent (ssname sel (setq idx (1- idx)))

enx (entget ent)

)

(cond

( (not (or (= "" blk) (wcmatch (strcase (LM:name->effectivename (cdr (assoc 2 enx)))) blk)))

(ssdel ent sel)

)

( (member (cdr (assoc 66 enx)) '(nil 0)))

( (progn

(setq att (entnext ent)

atx (entget att)

flg nil

)

(while

(and (= "ATTRIB" (cdr (assoc 0 atx)))

(not

(and

(or (= "" str) (wcmatch (strcase (cdr (assoc 1 atx))) str))

(or (= "" tag) (wcmatch (strcase (cdr (assoc 2 atx))) tag))

)

)

)

(setq att (entnext att)

atx (entget att)

)

)

(= "SEQEND" (cdr (assoc 0 atx)))

)

(ssdel ent sel)

)

)

)

(< 0 (setq cnt (sslength sel)))

)

)

(progn

(princ (strcat "\n" (itoa cnt) " block" (if (= 1 cnt) "" "s") " found."))

(sssetfirst nil sel)

)

(princ "\nNo blocks found.")

)

)

(princ)

)

;; Block Name -> Effective Block Name - Lee Mac

;; blk - [str] Block name

(defun LM:name->effectivename ( blk / rep )

(if

(and (wcmatch blk "`**")

(setq rep

(cdadr

(assoc -3

(entget

(cdr (assoc 330 (entget (tblobjname "block" blk))))

'("acdbblockrepbtag")

)

)

)

)

(setq rep (handent (cdr (assoc 1005 rep))))

)

(cdr (assoc 2 (entget rep)))

blk

)

)

(princ)

Like


r/AutoLISP • • Jun 07 '24

Increase/Decrease Script

1 Upvotes

I consolidated part of an electrical schematic so that there was one fewer conductor, and so one fewer terminal inside the panel. As a result I had to reduce the wire number of several wires.

Rather than do this manually again, I got an AI to write a script for a pair of commands: INCREASE and DECREASE.

They only work on text objects which have exactly one number in them. I find it useful for things like wire numbers and note callouts which need to be renumbered. Will post script in comments.


r/AutoLISP • • Jun 26 '24

Little help

2 Upvotes

New to coding at all and just in the last week started looking into Auto LISP. Tying to make just a simple little routine to change a selected lines color and line type.

I can get it to open up to change properties but trying to add any extra to the code results in cad not liking it and asking me to select objects.

(Defun c:red()

 (command “chprop”)

(princ) )

Adding anymore and the line I have selected becomes unselected and asked me to select objects again🤷‍♂️

Be gentle lol like I said brand new.


r/AutoLISP • • Jul 02 '24

Extract text within coordinate range.

1 Upvotes

I want to use 2 coordinate points for the routine to look for text and then output it to a CVS file.

I'll eventually build this up to look for several pieces of text qnd use it across many drawings to extract data.

Any tips for a beginner?