Incremental rename bunch of components
-
-
If it doesnt exist itd be pretty easy to make.
Just to clarify, is the "name" in "name#N" constant?
-
And
DefinitionList.unique_namedoes most of the job:
http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/definitionlist.html#unique_name@unknownuser said:
The unique_name is used to generate a unique name for a definition based on a base_name string. For example, a base_name of "Joe" might return "Joe #2"
Iterate the selected instances, collect the definitions.
Iterate the definitions naming them by whatDefinitionList.unique_name.
Bob's your uncle. -
@remus said:
If it doesnt exist itd be pretty easy to make.
Just to clarify, is the "name" in "name#N" constant?
Yes. Something like this - cab#1, cab#2 ...
-
Copy/paste this code into a file called
componentrenamer.rbin the Plugins folder.
To run it you typecomponentrenamer "NewName#1"in the Ruby Console to change the name of selected component-instances' definitions toNewName#1,NewName#2,NewName#3etc...
Note: starting with 'NewName' increments the second one to 'NewName#1'def componentrenamer(newname) model=Sketchup.active_model ss=model.selection defs=[] ss.each{|e|defs << e.definition if e.class==Sketchup;;ComponentInstance} defs.uniq.each{|d|d.name=model.definitions.unique_name(newname)} end#def
-
-
Nice!
I'm guessing the # sign is part of the internal SketchUp API? #s cause some problems with how I use models externally. I looked at the (dang simple) code and didn't see any immediate way to suppress the #.
This is for keeping all instances the same component, but using a different name, correct? It's not taking all instances and making them unique when renaming? (Similar to what happens when two components of the same name come in but are different -- the second one is named: name#1.)
-
To strip the # try adding an extra argument
def componentrenamer(newname,nnn=nil) model=Sketchup.active_model ss=model.selection defs=[] ss.each{|e|defs << e.definition if e.class==Sketchup;;ComponentInstance} defs.uniq.each{|d| unn=model.definitions.unique_name(newname) unn=unn.tr("#",nnn)if nnn d.name=unn } end#defThe second string in the translation
trnnncan be anything you want - e.g. "-" or "_" ?
The usage now has an optional second argument to replace the # with something else
e.g.componentrenamer("NewName","_")
If you don't add it then the # remains unchanged...

-
Thanks TIG! I'll try it out (and learn a little more about SU Ruby)

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement
