Jump to content

Layer Lisp


jaylo23

Recommended Posts

Just noticed your links to your programs in the sig.... seems like everyone followed me on that one :wink: Buzzard, Freerefill... now you...

 

Yeah, it's just random crap, but someone might find it useful. Thought I'd stick it there so people can have a chance of giving it a look. Never know when it might be useful to someone else. I'm sure it's a waste of time and space. More than anything, I just wanted to remove the need to post a subroutine (if it's in the sub thread) everytime I post something for someone. This way, I can just post the main and direct them to the link. After that, I just added a few more, just because.

Link to comment
Share on other sites

  • Replies 105
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    41

  • alanjt

    30

  • JeepMaster

    15

  • kalarpu

    11

What about something like this?

(defun c:RemSuff (/ suff doc name)
 (vl-load-com)

 (while (not (and (setq suff (getstring "\nSpecify Suff to Remove: "))
                  (snvalid suff)
             ) ;_ and
        ) ;_ not
   (princ "\n** Invalid Suffix **")
 ) ;_ while

 (vla-StartUndoMark
   (setq doc (vla-get-ActiveDocument
               (vlax-get-acad-object)
             ) ;_ vla-get-ActiveDocument
   ) ;_ setq
 ) ;_ vla-StartUndoMark

 (vlax-for lay (vla-get-layers doc)
   (if (wcmatch (strcase (setq name (vla-get-name lay)))
                (strcase (strcat "*" suff))
       ) ;_ wcmatch
     (vl-catch-all-apply
       'vla-put-Name
       (list lay
             (substr name
                     1
                     (vl-string-position (ascii suff) name nil T)
             ) ;_ substr
       ) ;_ list
     ) ;_ vl-catch-all-apply
   ) ;_ if
 ) ;_ vlax-for

 (vla-EndUndoMark doc)
 (princ)
) ;_ defun

Alan,

Your lisp works great, and I think you for it. But my problem now is all the xref layers that's on the dwg also get the suffix added to it.:( Obviously, we don't want that to happen. I only want my current drawing layers to have suffix added on.

Link to comment
Share on other sites

Try this buddy:

 

(defun c:laysuff (/ suff doc)
 (vl-load-com)

 (setq suff (getstring t "\nSpecify Suffix for all layers: "))

 (vla-StartUndoMark (setq doc (vla-get-ActiveDocument
                                (vlax-get-acad-object))))

 (vlax-for lay (vla-get-layers doc)
   (or (wcmatch (strcase (vla-get-name lay)) (strcase (strcat "*|*,*" suff)))
       (vl-catch-all-apply 'vla-put-Name
         (list lay (strcat (vla-get-Name lay) suff)))))

 (vla-EndUndoMark doc)
 (princ))

Link to comment
Share on other sites

Perhaps this for the removal:

 

(defun c:RemSuff  (/ suff doc name)
 (vl-load-com)

 (setq suff (getstring t "\nSpecify Suff to Remove: "))

 (vla-StartUndoMark (setq doc (vla-get-ActiveDocument
                                (vlax-get-acad-object))))

 (vlax-for lay (vla-get-layers doc)
   (and (wcmatch (strcase (setq name (vla-get-name lay))) (strcase (strcat "~*|*,*" suff)))
        (vl-catch-all-apply 'vla-put-Name
          (list lay (substr name 1 (vl-string-position (ascii suff) name nil T))))))

 (vla-EndUndoMark doc)
 (princ))

Link to comment
Share on other sites

Yeah, I think its a good idea - I would post some, but I have thousands stored and haven't got the time for any spring cleaning now... :geek:

 

Well, it's just some random stuff I use. I was bored and thought I'd share.

Link to comment
Share on other sites

Alan,

Your lisp works great, and I think you for it. But my problem now is all the xref layers that's on the dwg also get the suffix added to it.:( Obviously, we don't want that to happen. I only want my current drawing layers to have suffix added on.

 

I didn't even consider Xrefs, but I see Lee took care of it.

Link to comment
Share on other sites

Yeah, you like that scrunched up look. :wink:

 

I just find it easier to read :)

 

"Coding styles are like a**holes, everyone has one and no one likes anyone elses." Eric Warmenhoven

Link to comment
Share on other sites

I just find it easier to read :)

 

"Coding styles are like a**holes, everyone has one and no one likes anyone elses." Eric Warmenhoven

 

LoL

See, I find it easier to read with my formatting. It's just a matter of preference.

Link to comment
Share on other sites

Perhaps this for the removal:

 

(defun c:RemSuff  (/ suff doc name)
 (vl-load-com)

 (setq suff (getstring t "\nSpecify Suff to Remove: "))

 (vla-StartUndoMark (setq doc (vla-get-ActiveDocument
                                (vlax-get-acad-object))))

 (vlax-for lay (vla-get-layers doc)
   (and (wcmatch (strcase (setq name (vla-get-name lay))) (strcase (strcat "~*|*,*" suff)))
        (vl-catch-all-apply 'vla-put-Name
          (list lay (substr name 1 (vl-string-position (ascii suff) name nil T))))))

 (vla-EndUndoMark doc)
 (princ))

Lee,

This one seems like it's still renaming xref layers. :(

Link to comment
Share on other sites

Lee,

This one seems like it's still renaming xref layers. :(

Try this:

(defun c:RemSuff  (/ suff doc name)
 (vl-load-com)

 (setq suff (getstring t "\nSpecify Suff to Remove: "))

 (vla-StartUndoMark (setq doc (vla-get-ActiveDocument
                                (vlax-get-acad-object))))

 (vlax-for lay (vla-get-layers doc)
   (and (not (wcmatch (setq name (vla-get-name lay)) "*|*"))
        (wcmatch (strcase name) (strcase (strcat "*" suff)))
        (vl-catch-all-apply 'vla-put-Name
          (list lay (substr name 1 (vl-string-position (ascii suff) name nil T))))))

 (vla-EndUndoMark doc)
 (princ))

Link to comment
Share on other sites

I don't know what happen here, but the latest one doesn't seem to pick the correct suffix to remove. It just remove all of them. ie: when I ask it to remove "-DEMO" It removes all the layers with "-DEMO" as well as "-TEXT"

defun c:RemSuff  (/ suff doc name)
 (vl-load-com)

 (setq suff (getstring t "\nSpecify Suff to Remove: "))

 (vla-StartUndoMark (setq doc (vla-get-ActiveDocument
                                (vlax-get-acad-object))))

 (vlax-for lay (vla-get-layers doc)
   (and (not (wcmatch (setq name (vla-get-name lay)) "*|*"))
        (wcmatch (strcase name) (strcase (strcat "*" suff)))
        (vl-catch-all-apply 'vla-put-Name
          (list lay (substr name 1 (vl-string-position (ascii suff) name nil T))))))

 (vla-EndUndoMark doc)
 (princ))

 

If we back track a little, this code from Alan works just fine. The problem we had was it also renames the xrefs, but the xref layers goes back to the correct names after the drawing is reopened. So infact it actually works like it should.

What about something like this?

(defun c:RemSuff (/ suff doc name)
 (vl-load-com)

 (while (not (and (setq suff (getstring "\nSpecify Suff to Remove: "))
                  (snvalid suff)
             ) ;_ and
        ) ;_ not
   (princ "\n** Invalid Suffix **")
 ) ;_ while

 (vla-StartUndoMark
   (setq doc (vla-get-ActiveDocument
               (vlax-get-acad-object)
             ) ;_ vla-get-ActiveDocument
   ) ;_ setq
 ) ;_ vla-StartUndoMark

 (vlax-for lay (vla-get-layers doc)
   (if (wcmatch (strcase (setq name (vla-get-name lay)))
                (strcase (strcat "*" suff))
       ) ;_ wcmatch
     (vl-catch-all-apply
       'vla-put-Name
       (list lay
             (substr name
                     1
                     (vl-string-position (ascii suff) name nil T)
             ) ;_ substr
       ) ;_ list
     ) ;_ vl-catch-all-apply
   ) ;_ if
 ) ;_ vlax-for

 (vla-EndUndoMark doc)
 (princ)
) ;_ defun

I actually have a xref reload lisp that will fix this problem without having to reopen the drawing. We came to this similar problem on a different lisp routine of renaming xrefs and I had the same solution of reloading all the loaded xrefs.:)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...