Message 1 of 16
Lisp routine - change layer phase
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
For starters i know nothing about LISP. So I turned to ChatGPT to try and help me with a task. I want to be able to select elements in a drawing and change their layer to specific phase (ie. New, Existing, Removal). ChatGPT gave me a great looking script, but I keep getting errors when I try to debug it. Debugging is also something I know nothing about.
Currently the routine is hanging up on line 10 with error:
Exception has occurred.
bad argument type: lentityp (3 <Entity name: 200561f28f0> 0 -1)
(defun c:cx (/ ss newPhaseStatus)
(setq ss (ssget)) ; Prompt the user to select objects
(if (not ss)
(prompt "\nNo objects selected.")
(progn
(setq newPhaseStatus (strcase (getstring "\nEnter 'E' for Existing Conditions, 'R' for Removal Work, or 'N' for New Work: ")))
(if (or (= newPhaseStatus "E") (= newPhaseStatus "R") (= newPhaseStatus "N"))
(progn
(foreach obj (vl-remove-if-not 'vlax-ename->vla-object (mapcar 'vlax-ename->vla-object (ssnamex ss)))
(vl-catch-all-apply
'(lambda ()
(setq currentLayer (vla-get-Layer obj))
(setq layerParts (split-string currentLayer "-"))
(if (< (length layerParts) 4)
(setq layerParts (append layerParts (list ""))))
(setq newLayerName (strcat (nth 0 layerParts) "-" (nth 1 layerParts) "-" (nth 2 layerParts) "-"))
(setq newLayerName (strcat newLayerName newPhaseStatus))
(if (not (tblsearch "layer" newLayerName))
(progn
(setq layerColor (getcolor "\nEnter layer color (0-255): "))
(setq lineType (if (= newPhaseStatus "E") "Continuous" "Hidden"))
(entmakex
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 2 newLayerName)
(cons 70 0)
(cons 62 layerColor)
(cons 6 lineType)
)
)
)
)
(vla-put-Layer obj newLayerName)
))
)
(prompt "\nLayers updated successfully.")
)
(prompt "\nInvalid input. Please enter 'E', 'R', or 'N'."))))
(princ)
)