Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
There is an operation that I keep repeating and that would love to optimize. However, I am not very good at programing with lisp so I would like to ask you for some help. I would like Autocad to turn every layer on, so I can choose a layer, then return to the previous layer settings and then turn on selected layer. How would I approach this? Probably doing something like this:
- Turn All Layers On: It makes all layers visible using the LAYON command.
- Select an Object: The user selects an object, and the layer name of that object is retrieved.
- Save object's layer: The layer name of that object is saved as "target".
- Restore Layer Settings: Restores the layer states to what they were before turning them all on using the LAYERP command.
- Turn "target" Layer On: The selected object's layer is turned on.
- EXTRA: If the layer is already on, then say: "Caution! Layer was already on".
Should I try to write LSP code? Ok, I did have a conversation with chatgpt and tried to guide him, but I don't get him to do it right!
(defun c:LayerOn (/ selObj layerName)
;; Turn all layers ON (but do not unfreeze them)
(command "_.LAYON")
;; Prompt the user to select an object
(princ "\nSelect an object to keep its layer on: ")
(setq selObj (entsel))
(if selObj
(progn
;; Get the layer name of the selected object
(setq layerName (cdr (assoc 8 (entget (car selObj)))))
;; Restore the previous layer settings
(command "_.LAYERP")
;; Turn on the selected layer if it was off
I DON'T KNOW HOW TO DO THIS
;; Confirm the action
(princ (strcat "\nLayer " layerName " is now visible."))
)
;; If no object is selected
(princ "\nNo object selected.")
)
(princ)
)
Thanks a lot
Solved! Go to Solution.