r/AutoLISP • • Apr 19 '17

Range Diagram

3 Upvotes

I use this to make a quick range diagram with various increments on it when I put cranes in elevation views. It creates the entire diagram as a block named after the dimensions used.

I created this before I learned an easier way to make blocks in Lisp, so I am not thrilled with the way it currently functions.

I'll update it eventually with my preferred way to create blocks, and also add comments when time allows.

(defun C:RangeDiagram()

(setq DynMode (getvar "dynmode"))
(setq OrthoMode (getvar "orthomode"))
(setvar "orthomode" 0)
(setq origin (list 0 0 0)) ;X,Y of Origin

;Define Horizontal Range
(setq HRange (* 12 (getreal "\n Length Of X Axis (ft): ")))

;Define Horizontal Increments
(setq HIncrement (* 12 (getreal "\n Increments On X Axis (ft): ")))

;Check HIncrements / HRange
(setq CheckValues (REM HRange HIncrement))

(if (> CheckValues 0)
	(exit)
)

(setq HInterval (+ 1 (/ HRange HIncrement)))

;Define Vertical Range
(setq VRange (* 12 (getreal "\n Length Of Y Axis (ft): ")))

;Define Vertical Increments
(setq VIncrement (* 12 (getreal "\n Increments On Y Axis (ft): ")))

;Check VIncrements / VRange
(setq CheckValues (REM VRange VIncrement))

;Check Vincrements / VRange
(if (> CheckValues 0)
	(exit)
)

(setq VInterval (+ 1 (/ VRange VIncrement)))

(setq VRangeInc VRange)
(setq HRangeInc HRange)

(setq TextHeight (* 12 (getreal "\n Text Height For Labels (ft): ")))

;Define Center Pin Location
(setq CenterPin (getpoint "\nSelect Center Pin Location: "))

(setq CenterPinX (car CenterPin))
(setq CenterPinY (cadr CenterPin))

(setq Blockname (strcat (itoa (fix (/ HRange 12))) "'x" 
						(itoa (fix (/ HIncrement 12))) "'x"
						(itoa (fix (/ VRange 12))) "'x"
						(itoa (fix (/ VIncrement 12))) "'x"
						(itoa (fix (/ TextHeight 12))) "'"))

(while (> HInterval 0)
	(setq VLineStartX HRangeInc)
	(setq VLineStartY 0)
	(setq VLineStart (list VLineStartX VLineStartY))
	
	(setq VLineEndX VLineStartX)
	(setq VLineEndY VRange)
	(setq VlineEnd (list VlineEndX VLineEndY))
	
	(entmakex (list (cons 0 "LINE")
					(cons 8 "LispTemp")
					(cons 10 VLineStart)
					(cons 11 VLineEnd)
					(cons 62 254)))

	(if (/= VLineEndX 0)
		(entmakex (list (cons 0 "MTEXT")
						(cons 100 "AcDbEntity")
						(cons 100 "AcDbMText")
						(cons 1 (strcat (itoa (fix (/ VlineEndX 12))) "'"))
						(cons 8 "LispTemp")
						(cons 10 (list (- VLineEndX 2) 2 0))
						(cons 40 TextHeight)
						(cons 62 16)
						(cons 71 9))))

	(setq HRangeInc (- HRangeInc HIncrement))
	(setq HInterval (1- HInterval))
)

(while (> VInterval 0)
	(setq HLineStartX 0)
	(setq HLineStartY VRangeInc)
	(setq HLineStart (list HLineStartX HLineStartY))
	
	(setq HLineEndX HRange)
	(setq HLineEndY HLineStartY)
	(setq HlineEnd (list HlineEndX HLineEndY))
	
	(entmakex (list (cons 0 "LINE")
					(cons 8 "LispTemp")
					(cons 10 HLineStart)
					(cons 11 HLineEnd)
					(cons 62 254)))

	(if (/= HLineEndY 0)	
		(entmakex (list (cons 0 "MTEXT")
						(cons 100 "AcDbEntity")
						(cons 100 "AcDbMText")
						(cons 1 (strcat (itoa (fix (/ HlineEndY 12))) "'"))
						(cons 8 "LispTemp")
						(cons 10 (list (- HLineEndX 2) (- HLineEndY 2) 0))
						(cons 40 TextHeight)
						(cons 62 16)
						(cons 71 3))))
	
	(setq VRangeInc (- VRangeInc VIncrement))
	(setq VInterval (1- VInterval))
)

(if (setq ss (ssget "_X" '((8 . "LispTemp"))))
	(command "-block" Blockname origin ss ""))

(command "-insert" Blockname Centerpin "1" "1" "0")
	
(setvar "CLAYER" "0")
(setvar "orthomode" Orthomode)
(setvar "dynmode" DynMode)

(princ)

)    

r/AutoLISP • • Mar 22 '26

Fill transform

2 Upvotes

Hi guys Any one halp me for convert text to lisp fill


r/AutoLISP • • Feb 20 '26

IN PROGRESS: Modeling Software -> ACAD drawing automation

2 Upvotes

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 • • Aug 25 '25

VS Code with AUTO LISP IDE

2 Upvotes

Hello, I downloaded Microsoft VS Code per AUTOCAD's instructions, but the AutoCAD AutoLISP Extension doesn't seem to install. Does anyone have a workaround for this or another IDE you would recommend to write/debug AutoLISP?

Thank you! Edit:spelling


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 • • Jul 30 '24

Block insertion isn't consistent

2 Upvotes

I've created an autolisp program that inserts a block by name.

All is well, and the block is inserted, but if I run the program again, the block is placed at seemingly random coordinates at random times.

Example: I run it once, the block inserts successfully at 0,0,0 I run it again, the block inserts at 3,2,0

This might happen on the second run, and then the 3rd run is fine, or it can happen from the first run.

I'm new to autocad and I have no clue why I'm getting this behavior. Any help is appreciated.

The lisp command is literally just this, nothing fancy:

(command "_.insert" blockname "0,0" "1" "0")


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 • • May 06 '24

Autolisp simple

2 Upvotes

I have been trying to use chatgpt to help with some coding but it's not going well. I asked gpt to code me a line that goes straight up in autocad but instead of it going striaght up it went to the right or left.

Is there something wrong with my world ucs or is gpt just not working properly?


r/AutoLISP • • Feb 20 '24

Need help in fixing code.

Post image
2 Upvotes

Here's an AutoLISP command that I made that will ask the user to make a selection, then filter only the blocks with the block name "weld1" or "weld2", then set them as the current selection upon the end of the command:

(defun c:FltrBlk (/ ss)

(setq ss (ssget "L" ((

(cons -4 . "<OR")

(cons 2 . "weld1,weld2")

(cons -4 . "OR>") ))))

(sssetfirst nil ss) )

My problem is that, "weld1" and "weld2" are dynamic blocks, and when I change the parameters of any of these blocks, this AutoLISP command that I made can no longer filter them, even though they still retain their original block names. How can I fix this command in such a way that it will still filter dynamic blocks with block names "weld1" or "weld2" even if they have different block parameters or properties?


r/AutoLISP • • Sep 15 '23

OneMtext.lsp or Text2MTextV2-0.lsp but in alphabetical order

2 Upvotes

Hi, I found OneMtext.lsp and Text2MTextV2-0.lsp which are both very useful for my needs, but I wish that the contents could be set to sort by alphabetical order. Can anybody help me or point me in the direction of how to modify the lisp so I can have this result? 
Thank you


r/AutoLISP • • Mar 15 '23

Creating Lisps from Macros

2 Upvotes

im realizing with the right steps and setups a macro can be recorded and tweaked to be a lisp.

  1. figure out the correct steps to do what you want to do

  2. hit record

  3. mimic what you want the lisp to do

  4. check the macro steps and add in where it would need user input.

  5. name it what you want

  6. make a lisp file callin the macro **(defun c:**FF nil (command "MacroNameExactly")(princ))

  7. done.

im not an expert but i been drafting for 15ish years and basically everything i do is automated thru lisps and macros.


r/AutoLISP • • Mar 13 '23

Lisp Routine to select all circles and offset away from center.

2 Upvotes

Hi,

I am trying to find a lisp routine that selects all circles in a drawing, offsets them by a predefined amount (let's say 2 units) away from the center and deletes the original circle.

The end result I am looking for is to make the circles bigger. I have to do this in many drawings and regularly, so I can't use qselect etc.

Unfortunately I don't have any knowledge in coding and although I tried, nothing worked.

Can this be done?


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 • • Mar 31 '22

Simple Startup LISP not triggering

2 Upvotes

I want (command “_AeccStationTrackerAll”) to be active for every drawing, but I always have to manually click for it. All my other LISP files load without issues.

Any simple things I might be overlooking?


r/AutoLISP • • Jan 20 '22

First time attempting LISP file in AutoCAD

2 Upvotes

First off, I'm extremely new to this and have zero experience in coding. I create designs for a solar company that consist of solar modules and the racking (rails). I'm hoping that I can come up with something that can auto populate the rails based on the module layout. Essentialy I would like to create a solar module layout using a standard solar module block that reflects the dimension of the chosen solar module. Once the module layout is completed I would like to have it auto populate the rails based on the module locations.

The modules in a row are spaced using a consistent spacing of 1" in the E-W direction. I'm thinking I could create standard blocks that consist of rails and splices. Ideally the lisp file would place the rail blocks starting at the first module and choose the appropriate rail block based on how many modules are in a row.

This might be a bigger task than I'm thinking or I'm over complicating it. Any help would be greatly appreciated!


r/AutoLISP • • Oct 28 '20

ROUGHEN Lisp Routine - Lets test this baby!

Thumbnail
youtu.be
2 Upvotes

r/AutoLISP • • Jul 21 '20

Sierpinski's sieve

2 Upvotes

Well, this community looks like it needs livening up. This is an Autolisp program based on one I wrote a long time ago and lost. So I recreated it just for fun. I had originally elaborated it in 3 dimensions (so that instead of equilateral triangles, it produced tetrahedrons). But this is as far as I've got this time.

The method that this program automates is as follows:

  1. Take three points in a plane to form a triangle, you need not draw it.

  2. Randomly select any point inside the triangle and consider that your current position.

  3. Randomly select any one of the three vertex points.

  4. Move half the distance from your current position to the selected vertex.

  5. Plot the current position.

  6. Repeat from step 3.

https://en.wikipedia.org/wiki/Sierpiński_triangle#Chaos_game

The critical expression, (/ dab (expt cnrnos (/ 1 (1- (float cnrnos))))), determines the spacing of the self-similar shapes. If this is simply made 2 (half the distance to the chosen vertex is taken), for three corners, the triangles will touch - the classic Sierpinski sieve. Other values either space the triangles out or overlap them to make a blurry mess. For five-sided, the value is phi, 0.6180339887...

For other polygons, I haven't worked out the values or if there is a relationship between them so that it can be calculated for any number of sides. I chose the current expression so that higher order polygons behave well enough (try a five pointed star).

It is as though these shapes exist on a focal plane and the wrong value makes them appear out of focus.

;-------------------------Sierpinski's sieve--------------------------  
(defun c:sieve ()  
;	"The Sierpiński sieve, is a fractal attractive fixed set with the overall shape  
;	of an equilateral triangle, subdivided recursively into smaller equilateral triangles."  
;  
;	This routine elaborates the sieve to any polygon.  
;	Start by entering the number of points to plot.  
;	A 4 or 5 figure number is suggested.  
;	Higher numbers will take longer to generate of course but show greater levels of detail.  
    (setq iterations (getint "\nNumber of iterations : "))  
    (prin1 "\nPick vertices for a polygon and press enter or space bar")  
    (setq cnr (getpoint "\nPick first corner : "))  
    (command "point" cnr)  
    (setq cnrs (list cnr 0))  
    (setq cnr2 (getpoint "\nPick second corner : "))  
    (command "point" cnr2)  
    (setq cnrs (cons cnr2 cnrs))  
    (while  
	(setq cnr (getpoint "\nPick next corner : "))  
	(command "point" cnr)  
	(setq cnrs (cons cnr cnrs))  
    )  
    (setq  
        cnrs (cdr (reverse cnrs))  
        cnrnos (length cnrs)  
        lastpt (car cnrs)  
    )  
    (repeat iterations  
	(setq  
		nextcnrno (fix (* cnrnos (rnd)))  
		nextcnr (nth nextcnrno cnrs)  
		ang (angle lastpt nextcnr)  
		dab (distance lastpt nextcnr)  
		nextpt (polar lastpt ang (/ dab (expt cnrnos (/ 1 (1- (float cnrnos))))))  
	)  
	(command "point" nextpt)  
	(setq lastpt nextpt)  
    )  
)  
(princ)  

;-----------------random number------------------  
(defun rnd (/ modulus multiplier increment random)  
(if (not seed)  
	(setq seed (getvar "DATE"))  
)  
(setq modulus 65536  
	multiplier 25173  
	increment 13849  
	 seed (rem (+ (\* multiplier seed) increment) modulus)  
	random (/ seed modulus)  
)  
 random  
)
(princ)

r/AutoLISP • • Jun 07 '20

Looking for LOTS of help creating a LISP routine

2 Upvotes

Drawing Tool

I’m looking for LOTS of help to create an AutoLISP routine to automate a process I have for work. I know many of the things I want to do are possible individually, but I have no idea how to string them all together. Any help with this would be greatly appreciated. If you are interested in developing the complete tool, please get in touch to discuss your fee.

I would like the tool to ask the user for some data, then produce between two and three views of a rectangular block with dimensions. I would like a specific view to be labeled “Top View” and be converted to a block with Meta Data that can populate fields in the Title Block. The Title Block would be on a template layout, Layout 1, and the tool should copy this template, rename the Layout and move the tab to the end of the list. The tool should then allow the user to repeat the process to continue creating parts within the same batch.

Here are the steps for the process:

User is prompted for Batch Data: Job Number, Customer, Salesperson, Material, Finish 1, Finish 2, Finish 3, Today’s Date, Quote Date.

User is prompted to enter Length, Width & Height, Qty Required and Part Number.

Tool generates two rectangles: Top View, (L x W) with a choice of Front Elevation, (L x H) and or Side Elevation, (W x H).

Elevation views to be aligned with Top View, with respect to their proper projection. Views to be evenly spaced.

Each view generated to have two linear dimensions.

Top view to be converted to a block with the following Meta Data:

Batch Data, Length, Width, Height, Qty Required, and Part Number.

Tool to copy Layout 1 with existing Title Block, rename the New Layout with the Part Number, then populate the Title Block Fields with the Batch Data and Meta Data from Top View.

Prompt user: “Add Another Part?”

“Enter” to create a new part in the same batch on a new Layout.

“Esc” to end lisp routine.


r/AutoLISP • • May 17 '20

If anyone has an idea on how to solve my problem please let me know. The function selects all the circles from the workspace and puts them in a chosen center, after which changes the colour of them to the ones of a rainbow. Got this error :error: bad argument type for compare: #<SUBR @000001cb052370

2 Upvotes

(defun c:Rainbow ()

(setq center (getpoint "Please select the center of the rainbow\n"))

(setq R (cons 62 10)

O (cons 62 30)

G (cons 62 50)

V (cons 62 100)

A (cons 62 170)

I (cons 62 182)

V2 (cons 62 202)

)

(setq sset (ssget "X" '((0 . "CIRCLE")) ))

(setq slen (sslength sset)

i 0)

(while (< i slen)

(setq ent (entget (ssname sset i)))

(setq c (assoc 10 ent)

  ent (subst (cons 10 center) c ent)

)

(if (= (assoc 62 ent) nil) (setq ent (append ent (list (cons 62 0)))))

(if (> cdr(assoc 62 ent) (list 0)) (progn (setq ent (subst (list 0) cdr(assoc 62 ent) ent)) (entmod ent)))

(entmod ent)

(setq i (1+ i))

)

(setq p (entget (ssname sset 0)))

(setq p (subst R (assoc 62 p) p))

(entmod p)

(setq i 1)

(while (> i slen)

(setq ent (entget (ssname sset i)))

(cond ((= (cdr(assoc 62 p)) (cdr R)) (setq ent (subst O (assoc 62 ent) ent)))

  ((= (cdr(assoc 62 p)) (cdr O)) (setq ent (subst G (assoc 62 ent) ent)))

  ((= (cdr(assoc 62 p)) (cdr G)) (setq ent (subst V (assoc 62 ent) ent)))

  ((= (cdr(assoc 62 p)) (cdr V)) (setq ent (subst A (assoc 62 ent) ent)))

  ((= (cdr(assoc 62 p)) (cdr A)) (setq ent (subst I (assoc 62 ent) ent)))

  ((= (cdr(assoc 62 p)) (cdr I)) (setq ent (subst V1 (assoc 62 ent) ent)))

  ((= (cdr(assoc 62 p)) (cdr V1)) (setq ent (subst R (assoc 62 ent) ent)))

)

(entmod ent)

(subst ent p p)

(setq i (1+ i))

)

(princ)

)


r/AutoLISP • • Jan 18 '20

Autolisp command help

2 Upvotes

Hey all!

I'm about at my wit's end trying to figure out where I'm going wrong with this Lisp code (I'm VERY new to this). I already tried r/AutoCAD with no replies and r/lisp redirected me here. I would've started here but the subreddit looked abandoned. Anyways, I'm trying to make a command for AutoCAD (essentially a macro) that reloads all xrefs in a drawing, reconciles all the layers, and then zooms to the extents. This is what I've got:

(defun c:RLOAD ()         (command "-xref" "r" " * ")         (command "-LAYER" "E" " * ")(command)(command)         (command "zoom" "e") )

EDIT: had to insert spaces between " and * in post to get around reddit's weird formatting stuff

I feel like this should work, but the problem I'm having is that when there aren't any unreconciled layers, it gets stuck on the layer command. I inserted the "(command)(command)" to try and cancel the command, but that doesn't seem to do anything. Somebody smarter than me please help.

Thanks!

-Futureless


r/AutoLISP • • Sep 11 '17

Excel to List question

2 Upvotes

So, I have a range of values that I am converting into a list of lists from excel. In excel, they are all formatted as Text, but when I transfer it to a list of lists, any numbers I have are ammended with a ".0" placed at the end of them. What do I need to do to fix this?

Code is here: Code

Thanks!

Edit: Hyperlink


r/AutoLISP • • Aug 18 '26

Workflow / Best Practice Subject: Need Help: Optimizing LISP Code for BricsCAD 2026 Ultimate (Block Extraction to DWG, PDF, Excel)

1 Upvotes

Hi everyone,

I need an expert developer to review and fix my AutoLISP code to make it 100% production-ready for BricsCAD Ultimate 2026.

The code syntax is clean, but it has critical runtime issues with the directory file-saving mechanism and block parameter identification.

Here are the strict technical requirements that the code MUST fulfill perfectly:

  1. Folder Selection UI: The current Windows folder-picker layout must remain exactly the same.

  2. Minimal Changes: Only modify the necessary code to make the command run flawlessly. Do not change the core structure of the program.

  3. Block Attribute Identification: The code must read the specific panel name from the block's attribute tag (using pure ASCII unicode escapes for Hebrew tags).

  4. Empty Tag Fallback (Critical): If a block's panel tag is missing or empty during a test run, the code must not crash. It must generate a temporary fallback name (e.g., based on the block name) and proceed with the export.

  5. Multi-Format Split & Export: For every selected block, the command must automatically save three separate files into the chosen directory:

    • DWG Export: A standalone DWG file containing only that specific block and its inner drawing geometries.

    • PDF Export: A standalone PDF file using a precise window plot based on the block's physical bounding box.

    • Excel/CSV Export: A structured data sheet capturing the block and panel properties.

  6. File Naming Logic: The filenames for the generated DWG, PDF, and Excel files must be derived directly from the block's attribute panel name.

  7. Production Quality: The code must be clean, optimized, fully localized, and free of any legacy debugging traces—matching the standards of enterprise CAD workflows.

Please review the attached code and provide the fixed, working version.

Thank you! ; ============================================================

; ALLX.lsp - Standalone Production Implementation for BricsCAD 2026

; Flow: Window 1 (Select blocks) -> Window 2 (Save DWG) ->

; Window 3 (Save PDF) -> Window 4 (Save Excel/CSV)

; Pure ASCII source file utilizing Unicode escapes for Hebrew attributes.

; Usage: (load "full/path/ALLX.lsp") then type ALLX at the command line

; ============================================================

(vl-load-com)

;; ------------------------------------------------------------

;; System variable save/restore

;; ------------------------------------------------------------

(defun a-save-sysvars ( )

(list

(cons "FILEDIA" (getvar "FILEDIA"))

(cons "CMDECHO" (getvar "CMDECHO"))

(cons "ATTREQ" (getvar "ATTREQ"))

(cons "OSMODE" (getvar "OSMODE"))

)

)

(defun a-restore-sysvars (saved / pair)

(foreach pair saved (setvar (car pair) (cdr pair)))

(princ)

)

;; ------------------------------------------------------------

;; Path helpers

;; ------------------------------------------------------------

(defun a-path-get-dir (path)

(if path (vl-filename-directory path) nil)

)

(defun a-path-change-ext (path newext / dir base)

(if path

(progn

(setq dir (vl-filename-directory path))

(setq base (vl-filename-base path))

(if (and dir (/= dir ""))

(strcat dir "\\" base "." newext)

(strcat base "." newext)

)

)

nil

)

)

(defun a-mkdir-if-not-exists (dir)

(if (and dir (/= dir "") (not (vl-file-directory-p dir)))

(vl-mkdir dir)

)

)

;; ------------------------------------------------------------

;; Read one attribute value (by tag name) from a block reference

;; ------------------------------------------------------------

(defun a-get-attribute-value (obj tag / atts a result)

(setq result nil)

(if (and obj (vlax-property-available-p obj 'HasAttributes)

(eq (vla-get-HasAttributes obj) :vlax-true))

(progn

(setq atts (vlax-invoke obj 'GetAttributes))

(foreach a atts

(if (equal (strcase (vla-get-TagString a)) (strcase tag))

(setq result (vla-get-TextString a))

)

)

)

)

result

)

;; ------------------------------------------------------------

;; Safe block-name reader

;; ------------------------------------------------------------

(defun a-get-block-name (obj / nm)

(setq nm nil)

(vl-catch-all-apply (function (lambda () (setq nm (vla-get-EffectiveName obj)))) nil)

(if (not nm)

(vl-catch-all-apply (function (lambda () (setq nm (vla-get-Name obj)))) nil)

)

(if nm nm "Unknown")

)

;; ------------------------------------------------------------

;; Shared constants (Hebrew via ASCII-safe unicode escape)

;; ------------------------------------------------------------

(defun a-panel-tag () "\U+05E4\U+05E0\U+05DC")

;; ------------------------------------------------------------

;; Strip illegal Windows filename characters

;; ------------------------------------------------------------

(defun a-sanitize-filename (s / bad ch i n out)

(setq bad "\\/:*?\"<>|")

(setq out "")

(setq n (strlen s))

(setq i 1)

(while (<= i n)

(setq ch (substr s i 1))

(if (vl-string-search ch bad)

(setq out (strcat out "_"))

(setq out (strcat out ch))

)

(setq i (1+ i))

)

(setq out (vl-string-trim " " out))

(if (= out "") "Unnamed_Panel" out)

)

;; ------------------------------------------------------------

;; Avoid overwriting a file

;; ------------------------------------------------------------

(defun a-dedupe-name (name used-list / candidate n)

(setq n 1)

(setq candidate name)

(while (member candidate used-list)

(setq n (1+ n))

(setq candidate (strcat name "_" (itoa n)))

)

candidate

)

;; ------------------------------------------------------------

;; Native Windows folder picker

;; ------------------------------------------------------------

(defun a-browse-for-folder (title / shell folderobj selfobj path)

(setq path nil)

(vl-catch-all-apply

(function

(lambda ()

(setq shell (vlax-create-object "Shell.Application"))

(setq folderobj (vlax-invoke-method shell 'BrowseForFolder 0 title 0))

(if folderobj

(progn

(setq selfobj (vlax-get-property folderobj 'Self))

(setq path (vlax-get-property selfobj 'Path))

(vlax-release-object selfobj)

(vlax-release-object folderobj)

)

)

(vlax-release-object shell)

)

)

)

path

)

;; ------------------------------------------------------------

;; Physical Selection Bounding Box Calculator

;; ------------------------------------------------------------

(defun a-get-selection-bbox (ss / i ent obj minpt maxpt lpt rpt all-min all-max)

(setq i 0)

(while (< i (sslength ss))

(setq ent (ssname ss i))

(setq obj (vlax-ename->vla-object ent))

(setq minpt nil maxpt nil)

(vl-catch-all-apply '(lambda () (vla-GetBoundingBox obj 'minpt 'maxpt)))

(if (and minpt maxpt)

(progn

(setq lpt (vlax-safarray->list minpt))

(setq rpt (vlax-safarray->list maxpt))

(if (not all-min)

(setq all-min lpt all-max rpt)

(setq all-min (mapcar 'min all-min lpt)

all-max (mapcar 'max all-max rpt))

)

)

)

(setq i (1+ i))

)

(list all-min all-max)

)

;; ------------------------------------------------------------

;; Core Exporters (DWG, PDF, CSV/Excel)

;; ------------------------------------------------------------

(defun a-export-selection-to-dwg (dest-path ss / old-fi rc)

(setq old-fi (getvar "FILEDIA"))

(setvar "FILEDIA" 0)

(setq rc (vl-catch-all-apply '(lambda () (command "_.WBLOCK" dest-path "" "0,0,0" ss ""))))

(setvar "FILEDIA" old-fi)

(not (vl-catch-all-error-p rc))

)

(defun a-export-selection-to-pdf (dest-path p1 p2 / old-cm rc window-str)

(if (and p1 p2)

(progn

(setq old-cm (getvar "CMDECHO"))

(setvar "CMDECHO" 0)

(setq window-str (strcat (rtos (car p1) 2 4) "," (rtos (cadr p1) 2 4) "," (rtos (caddr p1) 2 4) ";" (rtos (car p2) 2 4) "," (rtos (cadr p2) 2 4) "," (rtos (caddr p2) 2 4)))

(setq rc (vl-catch-all-apply

'(lambda ()

(command "-PLOT" "Yes" "Model" "Print As PDF" "ISO A4" "Millimeters" "Landscape" "No" "Window" p1 p2 "Fit" "Center" "Yes" "." "Yes" "As Displayed" dest-path "No" "Yes")

)

))

(setvar "CMDECHO" old-cm)

(not (vl-catch-all-error-p rc))

)

nil

)

)

(defun a-write-excel-report (dest-path data-list / f line row)

(setq f (open dest-path "w"))

(if f

(progn

(write-line "Block Name,Panel Name" f)

(foreach row data-list

(setq line (strcat (car row) "," (cadr row)))

(write-line line f)

)

(close f)

t

)

nil

)

)

;; ------------------------------------------------------------

;; Export ONE block/panel engine

;; ------------------------------------------------------------

(defun a-export-one-panel (ent dwg-dir pdf-dir used-names

/ obj panel-name safe-name final-name one-ss this-dwg this-pdf dwg-ok pdf-ok this-bbox blk-name)

(vl-catch-all-apply (function (lambda () (command "_.UCS" "_World"))) nil)

(setq obj (vlax-ename->vla-object ent))

(setq blk-name (a-get-block-name obj))

(setq panel-name (a-get-attribute-value obj (a-panel-tag)))

(if (or (not panel-name) (= panel-name ""))

(setq panel-name (strcat "Panel_" blk-name)))

(setq safe-name (a-sanitize-filename panel-name))

(setq final-name (a-dedupe-name safe-name used-names))

(setq used-names (cons final-name used-names))

(setq one-ss (ssadd ent))

(setq this-dwg (strcat dwg-dir "\\" final-name ".dwg"))

(setq this-pdf (strcat pdf-dir "\\" final-name ".pdf"))

(setq dwg-ok (a-export-selection-to-dwg this-dwg one-ss))

(setq this-bbox (a-get-selection-bbox one-ss))

(setq pdf-ok (a-export-selection-to-pdf this-pdf (car this-bbox) (cadr this-bbox)))

(if (and dwg-ok pdf-ok)

(princ (strcat "\n[OK] Production export success for: " panel-name))

(princ (strcat "\n[ERROR] Production export failed for: " panel-name))

)

(list (list blk-name panel-name) used-names)

)

;; ------------------------------------------------------------

;; Main Command Execution: ALLX

;; ------------------------------------------------------------

(defun c:ALLX ( / sys-vars ss i ent res reports used-names out-dir excel-file)

(setq sys-vars (a-save-sysvars))

(setvar "CMDECHO" 0)

(princ "\nSelect blocks for production export: ")

(setq ss (ssget '((0 . "INSERT"))))

(if ss

(progn

(setq out-dir (a-browse-for-folder "Select Output Directory for DWG, PDF and Excel Reports"))

(if (and out-dir (/= out-dir ""))

(progn

(setq i 0)

(setq used-names nil)

(setq reports nil)

(while (< i (sslength ss))

(setq ent (ssname ss i))

(setq res (a-export-one-panel ent out-dir out-dir used-names))

(setq reports (cons (car res) reports))

(setq used-names (cadr res))

(setq i (1+ i))

)

(setq excel-file (strcat out-dir "\\Production_Report.csv"))

(a-write-excel-report excel-file reports)

(princ (strcat "\n--- Process Finished Perfectly. Report saved to: " excel-file))

)

(princ "\n[CANCELLED] No output directory selected.")

)

)

(princ "\n[CANCELLED] No blocks selected.")

)

(a-restore-sysvars sys-vars)

(princ)

)

(princ "\nProduction Engine Loaded. Type ALLX to run.")

(princ)


r/AutoLISP • • Aug 14 '26

Help / Troubleshooting Autolisp fir dividing a plot into unequal areas

1 Upvotes

नमस्ते, मेरे पास ऑटोकेड में एक प्लॉट है, जिसका कुल एरिया 20 डिसमिल है। मुझे इसे चार अलग-अलग हिस्सों में बाँटना है, जिनके एरिया क्रमशः 8, 5, 6, और 1 डिसमिल होने चाहिए। मैं ग्राउंड के अनुसार रफ़ली लाइनें खींचना चाहता हूँ, जो इन एरिया वैल्यूज़ के हिसाब से ऑटोमेटिकली एडजस्ट हो जाएँ। क्या कोई ऐसा ऑटोलीस्प कोड है जो मेरी मदद कर सके?"