- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm working on a LISP routine that should move all blocks named BB1, BB2, etc. to a layer called SDC-BUBBLES. However, the code below doesn’t seem to be functioning as expected. I'd really appreciate any suggestions ti make it work.
(defun c:MoveBlocksToLayer ( / ss i ent entData)
;; Select all block references named bb1 or bb2 from the drawing
(setq ss (ssget "_X" '((0 . "INSERT") (2 . "bb1,bb2"))))
;; If selection set is not empty, proceed
(if ss
(progn
(setq i 0) ;; Initialize counter
;; Iterate through all selected blocks
(repeat (sslength ss)
(setq ent (ssname ss i)) ;; Get the entity at index i
(setq entData (entget ent)) ;; Retrieve entity data list
;; Replace the layer (group 8) with "sdc-bubbles"
(setq entData (subst (cons 8 "sdc-bubbles") (assoc 8 entData) entData))
(entmod entData) ;; Apply the modified data to entity
(setq i (1+ i)) ;; Increment counter
)
(princ "\nBlocks moved to layer sdc-bubbles.") ;; Confirmation message
)
)
(princ) ;; Exit quietly
)
Also, I’d like to incorporate this into another routine I have (Print_SDC) so that everything runs in a single LISP command. Here's that additional code for reference that works fine.
(defun c:Print_SDC ()
(command "-LAYER" "OFF" "0-SDC-DYNAMIC-HIDE" "")
(command "HATCHTOBACK")
;; Define a list of layers to process
(setq layerList '("SDC-GRIDLINES" "SDC-PL" "SDC-BACKGROUND" "SDC-BACKGROUND-LIGHT" )) ; Add more layer names as needed
;; Loop through each layer and apply draw order
(foreach layerName layerList
(setq ss (ssget "X" (list (cons 8 layerName))))
(if ss
(command "._DRAWORDER" ss "" "_Back")
)
)
(princ)
;(initdia)
; (command "PLOT" "")
)
Thank You.
Solved! Go to Solution.