Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello every one
I've made a lisp code to create layers with some conditions
now I need to add something to it is to put these created layers in group filter ( ALT + G ) it's existed and say it's name is "new"
how to make this ??
thanks in advance
(defun createLayerFromDialogValues (prefix text color)
;; Ensure prefix and text are valid (not nil) before proceeding
(if (and prefix text)
(progn
(setq layerName (strcat prefix text)) ;; Concatenate prefix and text to form layer name
;; Display the layer name being created for debugging
(prompt (strcat "\nAttempting to create layer: \"" layerName "\""))
;; Check if the layer already exists
(if (tblsearch "layer" layerName)
(prompt (strcat "\nLayer \"" layerName "\" already exists."))
(progn
;; Get layer collection
(setq layerCollection (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
;; Attempt to create new layer with error handling
(setq result (vl-catch-all-apply 'vla-add (list layerCollection layerName)))
;; Check for success or error
(if (not (vl-catch-all-error-p result))
(progn
;; Layer created successfully, set color
(setq layerObj (vla-item layerCollection layerName))
(vla-put-color layerObj color)
(prompt (strcat "\nLayer \"" layerName "\" created with color " (itoa color) "."))
;; Now, handle group filter
(setq acadDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq groups (vla-get-Groups acadDoc))
;; Check if a group named "new" exists
(setq newGroup (vl-catch-all-apply 'vla-item (list groups "new")))
;; If "new" group doesn't exist, create it
(if (vl-catch-all-error-p newGroup)
(progn
(setq newGroup (vla-add groups "new"))
(prompt "\n'new' group created.")
)
(prompt "\n'new' group found.")
)
;; Add the new layer to the "new" group
(vla-AppendItem newGroup layerObj)
(prompt (strcat "\nLayer \"" layerName "\" added to the 'new' group filter."))
)
;; Handle error in layer creation
(prompt (strcat "\nError creating layer: " (vl-catch-all-error-message result)))
)
)
)
)
;; Error handling if prefix or text is nil
(prompt "\nError: prefix or text is nil; cannot create layer name.")
)
)
say the syntax required is
(createLayerFromDialogValues "g" "f" 1)
Solved! Go to Solution.