Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I have a DWG file with a lot of pages stacked on top of each other, and I would like to separate them by a distance X to work with them more easily. Each page is on a different layer, so it's possible to move them by selecting the layer corresponding to each page. The title block is on layer 0 and is the same for all pages and should be copied to each of the existing pages. I have attached a DWG file with more details. I managed to make some progress with the following code, but I can't seem to sort them by name as they appear in the layer properties. I would like the pages to be moved in the correct order. Thank you very much.
(defun c:MoveLayersByXDist ()
(prompt "\nEnter the 'X distance' value: ")
(setq xDist (getreal)) ; Prompts the user to enter the X distance
(if (not xDist)
(progn
(prompt "\nError: A numeric value is required for 'X distance'.")
(exit)
)
)
(setq layers (getLayers) ; Get a list of all layers
counter 1 ; Counter to multiply the distance
selectionLayer0 (ssget "X" (list (cons 8 "0"))) ; Select all objects on layer "0"
distances '()) ; List to store copy distances
; Move all layers except "0" and "1"
(foreach layer layers
(if (not (member layer '("0" "1"))) ; Ignore layers "0" and "1"
(progn
(setq selection (ssget "X" (list (cons 8 layer)))) ; Select all on the current layer
(if selection
(progn
(setq distance (* counter xDist)) ; Calculate the move distance
(command "_.move" selection "" "0,0,0" (strcat (rtos distance 2 6) ",0,0")) ; Move the selection
(setq distances (cons distance distances)) ; Store the copy distance
(setq counter (1+ counter)) ; Increment the counter
)
)
)
)
)
; Copy the contents of layer "0" according to the accumulated distances
(if selectionLayer0
(foreach distance (reverse distances) ; Iterate over the distances in order
(command "_.copy" selectionLayer0 "" "0,0,0" (strcat (rtos distance 2 6) ",0,0"))
)
)
(princ "\nLayer movement and layer '0' copy process completed.")
(princ)
)
(defun getLayers ()
(setq layerList '())
(vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(setq layerList (cons (vla-get-name layer) layerList))
)
(reverse layerList)
)
Solved! Go to Solution.