Delete layer with specified text/word in layer name
hi All,
I am trying to delete layers including one specific word in layer name.
I tryed a code, like below but does not work:
Code:
(defun c:dd () (command "._-layer" "delete" pause "") (princ))
When prompted for layer name(s), I simply entered *myword* (specific word in whole layer name) I got "The selected layers could not be deleted."....
Can someone help?
Thanks.
1 Attachment(s)
Re: Delete layer with specified text/word in layer name
Quote:
Originally Posted by
Arterius
hi All,
When prompted for layer name(s), I simply entered *myword* (specific word in whole layer name) I got "The selected layers could not be deleted."....
Can someone help?
Thanks.
Make sure there are no entities under the target layer name
.Attachment 95772
Re: Delete layer with specified text/word in layer name
The thing is there are entities :)
I would like to delete all objects on layer also.
Like you do by typing LAYDEL, and [Name], and select one and confirm.
Re: Delete layer with specified text/word in layer name
Code:
(defun c:demo ( / layname)
(if (and (setq layname (getstring "\nEnter Layer to delete: "))
(/= "" layname)
(ssget "X" '((8 . "*myword*")))
)
(command "_erase" "p" "" "._-layer" "delete" layname "")
)(princ)
)
But of course , if there are objects under the specified layer inside a block/another layout/xref. it will still bomb.
Re: Delete layer with specified text/word in layer name
Code:
(defun c:delayer (/ layname)
(if (and (setq layname (getstring "\nEnter Layer to delete: "))
(/= layname ""))
(vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(if (= :vlax-false (vla-get-isxref b))
(vlax-for o b
(if (and (vlax-write-enabled-p o)
(wcmatch (strcase (vla-get-layer o)) (strcase layname)))
(vla-delete o)
)
)
)
)
)
(repeat 4
(vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))
)
(princ)
)
(vl-load-com) (princ)
Re: Delete layer with specified text/word in layer name
yes, I know I need to be careful with this.
Thanks, but how to bypass "\nEnter Layer to delete: "? Just put into code my specific word, type running command and that's all?
Re: Delete layer with specified text/word in layer name
Quote:
Originally Posted by
Arterius
yes, I know I need to be careful with this.
Thanks, but how to bypass "\nEnter Layer to delete: "? Just put into code my specific word, type running command and that's all?
What do you mean Arterius? The command is exclusively for that <*myword*> specific keyword?
Code:
(defun c:DSL nil ;<-- Delete This Layer
(vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(if (= :vlax-false (vla-get-isxref b))
(vlax-for o b
(if (and (vlax-write-enabled-p o)
(wcmatch (strcase (vla-get-layer o)) "*MYWORD*"))
(vla-delete o)
)
)
)
)
)
(repeat 4
(vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))
)
(princ)
)
(vl-load-com) (princ)
Re: Delete layer with specified text/word in layer name
Hi pbejse,
thanks for codes! I meant that your code from post #5 prompts for *myword*, that's really fine, but I was thinking about putting *myword* as permament into routine. I have edited your code and I found what I was looking for :)
Thanks for your help. Regards