Jump to content

Re-name layers from C-somethign to V-something


baker

Recommended Posts

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    7

  • Tharwat

    6

  • BlackBox

    5

  • baker

    3

Top Posters In This Topic

Posted Images

Try this baker and it is case sensitive which means ( c- (small letter) is not equal to C- (capital letter)) .

 

Codes better than Command calls . :D

(defun c:TesT (/ nxt layrs Nme)
 ;; == TharwaT 01. 09. 2011 == ;;
 (while
   (setq nxt (tblnext "LAYER" (null nxt)))
    (setq
      layrs
       (entget (tblobjname "LAYER" (setq Nme (cdr (assoc 2 nxt)))))
    )
    (if (and (not (eq Nme "0"))
             (eq (vl-string-search "C-" Nme 0) 0)
        )
      (entmod
        (subst (cons 2 (vl-string-subst "V-" "C-" (cdr (assoc 2 layrs))))
               (assoc 2 layrs)
               layrs
        )
      )
    )
 )
 (princ)
)

 

Tharwat

Link to comment
Share on other sites

*cough* wcmatch *cough*

But I try not to re-invent the wheel where possible ;)

 

I have thought of that as another access to Layer name matches and I do agree that the function wcmatch is much better than vl-string-search in this case .

 

Anyway here it goes .

 

Comments are also welcomed . :)

 

(defun c:TesT (/ nxt layrs Nme)
 ;; == TharwaT 01. 09. 2011 == ;;
 (while
   (setq nxt (tblnext "LAYER" (null nxt)))
    (setq
      layrs
       (entget (tblobjname "LAYER" (setq Nme (cdr (assoc 2 nxt)))))
    )
    (if (and (not (eq Nme "0"))
             (wcmatch Nme "C-*")
        )
      (entmod
        (subst (cons 2 (vl-string-subst "V-" "C-" (cdr (assoc 2 layrs))))
               (assoc 2 layrs)
               layrs
        )
      )
    )
 )
 (princ)
)

Link to comment
Share on other sites

Tharwat,

 

Not that you have to of course, but out of curiosity... if you're not going to use the RENAME command, and you're going to use vl-* functions, then why not just iterate the Layers Collection instead? :unsure:

 

Pseudo code:

 

((lambda (acDoc / )
 (vlax-for lay (vla-get-layers acDoc)
   [color=seagreen];;<-- Check / rename layers here[/color]
   )
 )
 (vla-get-activedocument (vlax-get-acad-object)))

Link to comment
Share on other sites

.. if you're not going to use the RENAME command,

 

If you have many layers (maybe Hundreds) in a dwg , the command call would be lazy .:)

 

and you're going to use vl-* functions, then why not just iterate the Layers Collection instead? :unsure:

 

Both are the same , aren't they ?

 

One more routine in Vl .:)

 

(defun c:TesT (/ lays Nme)
 ;; == TharwaT 01. 09. 2011 == ;;
 (setq lays (vla-get-layers
              (vla-get-activedocument (vlax-get-acad-object))
            )
 )
 (vlax-for x lays
   (if (wcmatch (setq Nme (vla-get-name x)) "C-*")
     (vla-put-name x (vl-string-subst "V-" "C-" Nme))
   )
 )
 (princ)
)

 

Regards,

 

Tharwat

Link to comment
Share on other sites

Work smart, not hard.

 

Nice saying .

 

When being overwhelmed by lots of projects to hand over on time , there won't be time to spend on thinking than keep on working (sometimes) :lol:

Link to comment
Share on other sites

Nice saying .

 

When being overwhelmed by lots of projects to hand over on time , there won't be time to spend on thinking than keep on working (sometimes) :lol:

Then maybe you should spend more time working and less time trolling the forums. ;)

Link to comment
Share on other sites

I am an idiot!!! thank you guys for being patient and supportive!!

 

 

*US*

 

We'll whip you numpties into shape, one way or another! :P :rofl: LoL

 

^^ Just being sarcastic, of course. Please take no offense.

Link to comment
Share on other sites

none taken.. i own a VW enthusiasts forum and we toss poo at each other all the time!! all in good fun!

 

^^ Gold, that is. :rofl:

 

I'm glad you share the sense of humor; you *should* fit in nicely.

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