See the top rated post in this thread. Click here

Results 1 to 8 of 8

Thread: Delete layer with specified text/word in layer name

  1. #1
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default 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.

  2. #2
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Delete layer with specified text/word in layer name

    Quote Originally Posted by Arterius View Post
    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

    .undelete.JPG

  3. #3
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default 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.

  4. #4
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default 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.
    Last edited by pbejse; 2014-06-03 at 10:46 AM.

  5. #5
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    1

    Default 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)

  6. #6
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default 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?

  7. #7
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Delete layer with specified text/word in layer name

    Quote Originally Posted by Arterius View Post
    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)

  8. #8
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default 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

Similar Threads

  1. Replies: 12
    Last Post: 2016-04-19, 06:09 PM
  2. Unable to Delete Layer $AUDIT-BAD-LAYER
    By kane333 in forum AutoCAD General
    Replies: 8
    Last Post: 2009-12-18, 07:29 PM
  3. Text mysteriously on Layer 0, can't select to delete
    By cadop.89229 in forum AutoCAD General
    Replies: 5
    Last Post: 2006-10-03, 02:21 PM
  4. Layer Manager to delete multiple layer states
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 3
    Last Post: 2006-05-19, 02:11 PM
  5. Replies: 1
    Last Post: 2006-04-03, 10:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •