Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone on the forum.
I have this lisp that reads all blocks with the name X-TEST.
Then it places each block found under the other, according to the value of the TAG parameter.
(defun c:TEST ( / ss blkRef insPt atts att tagValue newBlkRef )
(vl-load-com)
(setq ss (ssget "X" '((0 . "INSERT") (66 . 1) (2 . "X-TEST")))) ; Select all "X-TEST" blocks with attributes
(if (not ss)
(princ "\nNo 'X-TEST' blocks found in the current layout.")
(progn
(setq insPt (getpoint "\nChoose the initial point to insert the blocks: ")) ; Insertion point
(foreach blk (mapcar 'cadr (ssnamex ss))
(setq blkRef (vlax-ename->vla-object blk)) ; Converts entity to VLA-Object
; Gets all the attributes of the block
(setq atts (vlax-invoke blkRef 'GetAttributes))
(foreach att atts
(if (= (strcase (vla-get-tagstring att)) "TAG")
(setq tagValue (vla-get-textstring att))
)
)
; Inserts a new "X-TEST" block at the specified point
(setq newBlkRef (vla-insertblock (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point insPt) "X-TEST" 1 1 1 0))
; Assigns the value of the "TAG" attribute to the new block
(setq atts (vlax-invoke newBlkRef 'GetAttributes))
(foreach att atts
(if (= (strcase (vla-get-tagstring att)) "TAG")
(vla-put-textstring att tagValue)
)
)
; Moves the insertion point downward
(setq insPt (list (car insPt) (- (cadr insPt) 0.375) (caddr insPt)))
)
)
)
(princ)
)
I've tried several ways and I can't do it, I would like it to eliminate duplicate values and put the TAG parameter in alphabetical order.
Could anyone please help with this? I've been with no way out for days
Solved! Go to Solution.