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!

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