- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I’m currently working on an lisp routine to automate the creation of a dynamic block from polylines obj and assign visibility states using corresponding text objects. The goal is to:
1.Select multiple closed polylines in the drawing.
2.get the geometric center of each polyline for proper alignment.
3.select a set of single-line text objects, which will be used as names for the visibility states.
4.create a dynamic block containing all selected polylines, with each polyline assigned to a visibility state named after its corresponding text object.
challenges:
figuring out how to add selections to block as visibility states
current approach:
heres my code i have so far:
(defun c:CreateDynBlock (/ ssPlines ssTexts plineList
textList blkName blkObj blkRef
index plObj visState
)
;; Select closed polylines and text objects
(setq ssPlines (ssget "_X" '((0 . "LWPOLYLINE") (70 . 1))))
(setq ssTexts (ssget "_X" '((0 . "TEXT"))))
;; Debugging outputs
(princ (strcat "\nNumber of Polylines selected: "
(itoa (if ssPlines
(sslength ssPlines)
0
)
)
)
)
(princ (strcat "\nNumber of Text objects selected: "
(itoa (if ssTexts
(sslength ssTexts)
0
)
)
)
)
;; Ensure valid selections
(if (or (not ssPlines) (not ssTexts))
(progn
(princ
"\nError: You must select closed polylines and text objects."
)
(exit)
)
)
;; Convert selections to lists
(setq plineList (mapcar 'car (mapcar 'cdr (ssnamex ssPlines))))
(setq textList
(vl-remove-if
'null
(mapcar
(lambda (e)
(cdr (assoc 1 (entget e)))
)
(mapcar 'cdr (ssnamex ssTexts))
)
)
)
;; Debugging: Print first few text values
(princ "\nFirst few text values: ")
(mapcar (lambda (txt) (princ (strcat "\n- " txt))) textList)
;; Ensure equal number of polylines and texts
(if (/= (length plineList) (length textList))
(progn
(princ
"\nError: The number of polylines and text objects must be the same."
)
(exit)
)
)
Any advice on handling visibility states in dynamic blocks more effectively using lisp?
- Any advice on improving program
*Attached is also the file containing the polylines and text objects
Solved! Go to Solution.