Reset the naming
-
If I have
@unknownuser said:
comp#2
comp#3
test#4
test#12How to reset the naming to start back from 0
@unknownuser said:
comp
comp#1
test
test#1 -
If you have known names it's easier...
You can get all of your components' names thus
names=[] defs=model.definitions defs.each{|d|names << d.name}
You then need to find the 'family names' for the sets of components.
families=[] names.each{|name| if name.include?("#") families << name.split("#")[0..-2].join("#") else families << name end } families.uniq!
Now look for the 'family' members...
dsets=[] families.each{|family| dset=[family] defs.each{|d| dset << d if d.name.includes?(family) } dsets << dset }
Now we have the list of 'dsets' of all definitions by 'family'.
The array is in the form [name, defn1, defn2,...]
To ensure that the renaming doesn't affect existing defs with the same name you need to rename ALL in a set and then rename them in order after the 'family' again.
dsets.each{|dset| family=dset[0] randst=rand.to_s dset[1..-1].each{|d|d.name=d.name+randst} dset.[1..-1].each{|d|d.name=family}### they will auto increment*** }
So now all of the definitions should be renamed in order.
***To start the renaming from ''#1 use...d.name=family+"#1"}
then there'll be no 'comp' as the first one will be 'comp#1'... -
Thanks!
Advertisement