[Request] Name, Definition Name of Components
-
@unknownuser said:
In V6
I have 2 components
with definition name: Component#1, Component#2 all without name
Wishing
definition name: Dice1, name: Dice
definition name: Dice2, name: DiceI select the 2 component
launched in ruby Console your last ruby script : result
True
but nothing is changed for my 2 components selected
It doesn't work like that... AND you never asked for that, initially you said that you had a component named 'Dice1' and you wanted to name its instances as 'Dice'

Where in my description did I say it works on renaming a selected component ???
You now say you want to rename 'Component#1' as 'Dice1' and rename its instances as 'Dice'.
That's completely different!!
First you need a renameDefinitions tool to change the name of 'Component#1' to be 'Dice1' and then use the current tool to rename 'Dice...' definitions' instances as 'Dice'.
Save this code into a file in Plugins called 'renameDefinitions.rb'.
Usage: in the Ruby Console type in
renameDefinitions 'Component#', 'Dice'
to rename all components containing that text, which are renamed with the new text 'Dice' - so
'Component#1' >>> 'Dice1'
'Component#2' >>> 'Dice2'
but 'Component' stays as 'Component'
If there is no second argument the matching text is simply removed from the name.
To match only the first two 'Component#' definitions use a pattern like
renameDefinitions 'Component#[12]$', 'Dice#1'
So only
'Component#1' >>> 'Dice#1'
'Component#2' >>> 'Dice#2'
but 'Component#3' stays as 'Component#3'
To fix the '#' in the replacement 'Dice#', run again as
renameDefinitions 'Dice#', 'Dice'
so all of the 'Dice#' names >>> 'Dice' names...
OR if bizzare is needed
renameDefinitions 'Dice#', 'AfghanistanBananistan'
Sodef renameDefinitions(str = '', txt = '') str = str.to_s ### makes sure! txt = txt.to_s model = Sketchup.active_model model.start_operation('renameDefinitions') model.definitions.each{|defn| next if defn.image? or defn.group? dname = defn.name if str != '' next if dname.gsub(/#{str}/,'') == dname ### NO match to 'str' so skip it... end#if nname = dname.gsub(/#{str}/, txt) ### i.e. it replaces str with txt nname = 'Doh!' if nname == '' ### i.e. it was an exact match and txt=''!! defn.name = nname puts "Defn Name; "+dname+" = "+nname } model.commit_operation end#defNOW use the renameInstances tool to change any instances of renamed definitions as a second step.

-
That what that: missunderstanding my first post

If you re read sequentially my first post I never said that i had component named Dice
I said "I wish"
-
@unknownuser said:
I wish rename all this collection of component selected like this
First component
Definition name = Dice1
Name = DiceIF you had said:
I wish to rename all selected components like this...
Definition name = 'Component#1'
New Definition name = 'Dice1'
New Instances name = 'Dice'
That's what you would have got!
Anyway, you now have something that will do it what you want - renaming the definitions by pattern matching and then a second tool renaming the matching definitions' instances by stripping off the numerical part of the defn name and using that... -
Thx for your efforts

No possibility to enter a joker ?
because my selection of components can have any Definition names!
So make a general renaming in one pass -
Of course all your components will have a name - even if it's 'Component#1' it's still a name ???
Therefore you'd use
renameDefinitions 'Component#', 'Dice'
which acts like a 'wildcard' and every component containing the text 'Component#' will have that replaced with 'Dice' ??????
So 'Component#1 >>> 'Dice1', 'Component#2 >>> 'Dice2' etc
As I then explained further you can constrain the renaming to a smaller set by using other pattern matching like [1238] to just process the first three and the eighth one
renameDefinitions 'Component#[1238]', 'Dice#1'
to rename them all first as as 'Dice#1', 'Dice#2' etc and then in a second step using
renameDefinitions 'Dice#', 'Dice'
to rename them all as as 'Dice1', 'Dice2' etc...This does NOT work on a highlighted 'selection' !!
You make your selection using a pattern matching string in the name!!!!
-
So there is no possibility to change 2 objects components Definition named
Ball
Poll
to these Definition named Dice1, Dice2 in one pass? -
No...
-
Finally i have found a trick with another Console Script of your!

I explode all components selected and call your tricky thing who tranform any selections in Components!
m=Sketchup.active_model; ### tranform any selections in Components By TIG m.start_operation("Faces>Compos"); n=m.active_entities;m.selection.to_a.each{|e|(g=n.add_group(e.all_connected); g.to_component.definition.name="FaceSet#1")if e.valid? and e.parent==n.parent and e.class==Sketchup;;Face}; m.commit_operationSo obtain a generic Components' name: FaceSet#1, FaceSet#2 etc...
Call your renameInstances many posts above
So obtain an only one name for all the Components: FaceSet#
So I can use it inside the Plug Random Replace Component
and even now no kneed to change it in Dice!
...but I must change my tutorial!

Thanks again for your lessons!

I have seen many things about renaming but see also that I am definitly not made for ruby scripting!
-
and...In fact that is some redundant with the use of the Dialog box Info for rename a group of components!

I had an headache for a so simple solution
-
My trick works only with components with no level of component inside

and for rename a same component with definition name "Ball" existing in different positions
as new components with of course new definitions name Ball1, Ball2, Ball3 etc... ?
I suppose they must be "Make Unic" then renamed
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