Rename Multiple layers
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Rename Multiple layers

 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization
Author Message
Tim
Guest





Posted: Fri Apr 08, 2005 7:23 pm    Post subject: Rename Multiple layers Reply with quote

is it possible to re-name multiple layers all at once.

The problem I have is this..we all know that when you bind a x-ref you get
the x-ref name before the layer name.
Has anybody come up with a way to strip the x-ref name from the layer name
so you wind up with your layer standards left.

I have to convert multiple dwgs (as-builts) to a clients standard before we
give it to them. And because of the different layer names it makes it real
hard to run them against a standards checker or layer converter because I
have to account for a lot more names than just our standards. (i.e. x3grid,
x5grid etc...)

Any help or guidance would be greatly appreciated.


Tim W.

Back to top
T.Willey
Guest





Posted: Fri Apr 08, 2005 8:06 pm    Post subject: Re: Rename Multiple layers Reply with quote

On my machine (A2k4) you can bind the xref as an insert and the layer names are that as if you inserted the drawing.
Example:
layer Base|Wall
became
Wall

I think the system variable is "bindtype". For the acad help
BINDTYPE System Variable
Concepts Procedures Reference




Type: Integer
Not Saved
Initial value: 0

Controls how xref names are handled when binding xrefs or editing xrefs in place.


0 Traditional binding behavior ("xref1|one" becomes "xref$0$one")

1 Insert-like behavior ("xref1|one" becomes "one")


Hope that helped, if not a lisp shouldn't be to hard to write.
Tim
Back to top
Joe Burke
Guest





Posted: Fri Apr 08, 2005 8:09 pm    Post subject: Re: Rename Multiple layers Reply with quote

Tim,

Let's get one thing straight first. If you bind an xref using the "bind" option, it
works as you described. But is you use the "insert" option the xref layer names are
removed.

Given the insert option, if a layer name exists in both files, the layers are merged.
Otherwise a new layer is created.

So are you asking how to rename or merge layers which don't exist in both files? So
you end up with a set of layer names which comply with your company standards?

Joe Burke


"Tim" <nospamtwilson@hepc.com> wrote in message news:4256a22a$1_2@newsprd01...
Quote:
is it possible to re-name multiple layers all at once.

The problem I have is this..we all know that when you bind a x-ref you get the
x-ref name before the layer name.
Has anybody come up with a way to strip the x-ref name from the layer name so you
wind up with your layer standards left.

I have to convert multiple dwgs (as-builts) to a clients standard before we give it
to them. And because of the different layer names it makes it real hard to run them
against a standards checker or layer converter because I have to account for a lot
more names than just our standards. (i.e. x3grid, x5grid etc...)

Any help or guidance would be greatly appreciated.


Tim W.


Back to top
Tim
Guest





Posted: Fri Apr 08, 2005 8:43 pm    Post subject: Re: Rename Multiple layers Reply with quote

The dwgs I am working on were already bound a using "bind" so I have to work
with what I have.

Is it possible to remove everyting precedding the $0$ in a bunch of layers
with lisp or a script etc...

I have a routine that will remove the $0$ but then it adds a x# to the
beginning of each layer with the # going from say x2 to x8.
How about removing the first 2 characters from each layer name..is that
possible...

I can code the routine to modify the layers but then I have to account for
all of the different x# values instead of just using our standard layer
names. Thus the question of being able to remove the x-ref part of the layer
name

Thanks guys

Tim...





Tim,

Let's get one thing straight first. If you bind an xref using the "bind"
option, it
works as you described. But is you use the "insert" option the xref layer
names are
removed.

Given the insert option, if a layer name exists in both files, the layers
are merged.
Otherwise a new layer is created.

So are you asking how to rename or merge layers which don't exist in both
files? So
you end up with a set of layer names which comply with your company
standards?

Joe Burke


"Tim" <nospamtwilson@hepc.com> wrote in message
news:4256a22a$1_2@newsprd01...
Quote:
is it possible to re-name multiple layers all at once.

The problem I have is this..we all know that when you bind a x-ref you get
the x-ref name before the layer name.
Has anybody come up with a way to strip the x-ref name from the layer name
so you wind up with your layer standards left.

I have to convert multiple dwgs (as-builts) to a clients standard before
we give it to them. And because of the different layer names it makes it
real hard to run them against a standards checker or layer converter
because I have to account for a lot more names than just our standards.
(i.e. x3grid, x5grid etc...)

Any help or guidance would be greatly appreciated.


Tim W.
Back to top
T.Willey
Guest





Posted: Fri Apr 08, 2005 9:02 pm    Post subject: Re: Rename Multiple layers Reply with quote

You can search the string for the last $ character, then grab all the information after that. Something like
(setq cnt1 -1)
(while (setq cnt1 (vl-string-search "$" LayName (1+ cnt1)))
(setq cnt2 cnt1)
)
(setq LayName (substr LayName (+ 2 cnt2)))

From command line prompt

Command: (setq layname "lksdajfalk$kfj$fkadsl$this is what I want")
"lksdajfalk$kfj$fkadsl$this is what I want"

Command: !LayName
"this is what I want"

Hope that helps.
Tim
Back to top
Tim
Guest





Posted: Fri Apr 08, 2005 10:00 pm    Post subject: Re: Rename Multiple layers Reply with quote

Here is the adaptation of the code you sent me added into the existing code
that I had.
Keep in mind that my lisp skills are somewhat lacking as I am not a
programmer by any means.
With that in mind... this obviously does not work so could you look at it
and let me know where the problem lies

I certainly appreciate it

Tim W.



(DEFUN C:N$ (/ CE record lname LLEN cnt NNAME XNAME YNAME TEST)
(setq CE (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq cnt 0)
(setq record (tblnext "layer" T))
(while record
(setq lname (cdr(assoc 2 record))
LLEN (- (strlen lname) 3)
cnt 1 NNAME nil XNAME ""
)
(repeat LLEN
(setq TEST (substr lname cnt 3))
(if (= TEST "$")
(progn
(if (/= XNAME YNAME) (setq cnt -1))

(while (setq cnt1 (vl-string-search "$" NName (1+ cnt1)))
(setq cnt2 cnt1)
)

(command ".rename" "layer" lname nname)
)
(if (null NNAME)(setq XNAME (strcat XNAME (substr lname cnt 1))))
)
(setq cnt (1+ cnt))
); end repeat
(setq record (tblnext "layer") YNAME XNAME)
);end while
(setvar "cmdecho" CE)
(princ)
)
Back to top
T.Willey
Guest





Posted: Fri Apr 08, 2005 10:21 pm    Post subject: Re: Rename Multiple layers Reply with quote

The only thing I don't understand is how you get your prefix for the layers, the x3layername, so I couldn't code that. If you code that and label the number "LayNum" then just add it in, then here is a code that should work.

Tim

(defun c:RenameLayers (/ ActDoc LayName cnt1 cnt2 tmpName LayNum)

(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vlax-for Lay (vla-get-Layers ActDoc)
(setq LayName (vla-get-Name Lay))
(if (vl-string-search "$" LayName)
(progn
(setq cnt1 -1)
(while (setq cnt1 (vl-string-search "$" LayName (1+ cnt1)))
(setq cnt2 cnt1)
)
(setq tmpName (substr LayName (+ 2 cnt2)))
(vla-put-Name Lay (strcat LayNum tmpName))
)
)
)
(princ)
)
Back to top
Kent Cooper, AIA
Guest





Posted: Fri Apr 08, 2005 10:21 pm    Post subject: Re: Rename Multiple layers Reply with quote

What if there's already a layer "this is what I want" in the drawing?
That's the big potential hangup I see with any automated routine to change
layer names. Maybe you could take layer $0$whatever, find the whatever part
from that, and compare it with (tblsearch) for any layer that might already
be called whatever, then if there is one, LAYMRG $0$whatever into whatever,
and if there isn't, rename it.
--
Kent Cooper

"T.Willey" wrote...
Quote:
You can search the string for the last $ character, then grab all the
information after that. Something like
(setq cnt1 -1)
(while (setq cnt1 (vl-string-search "$" LayName (1+ cnt1)))
(setq cnt2 cnt1)
)
(setq LayName (substr LayName (+ 2 cnt2)))

From command line prompt

Command: (setq layname "lksdajfalk$kfj$fkadsl$this is what I want")
"lksdajfalk$kfj$fkadsl$this is what I want"

Command: !LayName
"this is what I want"

Hope that helps.
Tim
Back to top
T.Willey
Guest





Posted: Fri Apr 08, 2005 10:36 pm    Post subject: Re: Rename Multiple layers Reply with quote

Another good point, man you are all over my codes today Kent, but in a good way.

Tim
Back to top
Tim
Guest





Posted: Fri Apr 08, 2005 10:43 pm    Post subject: Re: Rename Multiple layers Reply with quote

When I first open a dwg the layers are the typical {0189A3$0$BLDG-EQ}
After I run the routine to get rid of $0$ Then I get (X1BLDG-EQ)
The routine used to work great in 2002 and lower just removing the $0$, now
it messes up.
So coding it for the typical xref layer would work.

I tried running the code and got a "bad argument type: stringp nil"

Thanks for helping by the way

Tim




The only thing I don't understand is how you get your prefix for the layers,
the x3layername, so I couldn't code that. If you code that and label the
number "LayNum" then just add it in, then here is a code that should work.

Tim

(defun c:RenameLayers (/ ActDoc LayName cnt1 cnt2 tmpName LayNum)

(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vlax-for Lay (vla-get-Layers ActDoc)
(setq LayName (vla-get-Name Lay))
(if (vl-string-search "$" LayName)
(progn
(setq cnt1 -1)
(while (setq cnt1 (vl-string-search "$" LayName (1+ cnt1)))
(setq cnt2 cnt1)
)
(setq tmpName (substr LayName (+ 2 cnt2)))
(vla-put-Name Lay (strcat LayNum tmpName))
)
)
)
(princ)
)
Back to top
T.Willey
Guest





Posted: Fri Apr 08, 2005 11:07 pm    Post subject: Re: Rename Multiple layers Reply with quote

That is because the variable "LayNum" is never set in my routine. I didn't know how you got the prefix "x1", so I couldn't code that in. If you tell me how you get it then I can add it, or you could add it.

Tim
Back to top
Tim
Guest





Posted: Fri Apr 08, 2005 11:18 pm    Post subject: Re: Rename Multiple layers Reply with quote

Remember the X# comes only after I run the other routine..So your original
premise of stripping out everything behind the last $ would work perfectly..
I would prefer not to run the other routine now if I don't have to.


Thanks

Tim
Back to top
T.Willey
Guest





Posted: Fri Apr 08, 2005 11:27 pm    Post subject: Re: Rename Multiple layers Reply with quote

So you don't want to rename the layers with a x# ?
If so then change this line
(vla-put-Name Lay (strcat LayNum tmpName))
to
(while (tblsearch "layer" tmpName)
(setq tmpName (strcat tmpName "--VersionFromXref"))
)
(vla-put-Name Lay tmpName)

This will check to make sure the layer name doesn't exist within the drawing, and if it does then it will rename it to have as a suffix "--VersionFromXref".

Also you can remove LayNum from the variable list.

Hope I'm understanding you correctly.
Tim
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB