Change from Group to Component - Name Inheritance
-
Dear All,
Is it possible to change a Group to Component and 'force' the Component to inherit the name from the Group?
Regards -
It would have to be a script.
When you change a group to a component the group's name is ignored and not even passed to the new-component's instance that now replaces the group.
The new component definition's name matches the original group definition's name which will be something like "Group#1"...
This "one-liner" will make any selected group[s] into components and use each group's name for the new component definition's name [instead of using its group-definition name] always provided that it's not "" [blank]... It also makes the new component-instance's name the same as the original group's name [again, always provided that it's not "" [blank]]...m=Sketchup.active_model;m.start_operation("g2c");m.selection.each{|e|next unless e.is_a?(Sketchup;;Group);n=e.name;i=e.to_component;i.name=n;i.definition.name=n unless n.empty?};m.commit_operation
copy/paste it into the Ruby Console + <enter>... It's one step undo-able...
-
Hi TIG,
Tried and it doesn't work. The Ruby Console accepts the script (adds TRUE) but the change is 'wiping out' the name as usual.
Regards -
@beginner said:
Hi TIG,
Tried and it doesn't work. The Ruby Console accepts the script (adds TRUE) but the change is 'wiping out' the name as usual.
Regards
I beg to differ.
I have tested it and it DOES work.
Preselect some things to convert...
Then run the code...
If you have an 'unnamed' group it will make a new component named say "Group#1" because by default it uses the group's definition name, the instance that replaces the original group is also unnamed [""].
If you have a 'named' group = "xxx"; it WILL make a new component definition named "xxx", the instance that replaces the original group is also named "xxx".
If you have more that one group that shares the name "xxx", then the new component definitions are renamed in turn - "xxx", "xxx#1", "xxx#2" etc - because definitions must have a unique name...
Are you preselecting groups and pasting the whole of the code ???
It SHOULD work... -
Hi TIG,
My apologies...
Now, I figured out the 'steps'...
I didn't expect the the script would convert the Groups for me - hundreds of them in one go !!!
1. Select the Group or Groups
2. 'Paste' the Script and 'ENTER'- Don't change/convert the Group manually as I tried ! - it would change any selected Groups to the Component ... automatically !
Amazing...
TIG, Thank you
- Don't change/convert the Group manually as I tried ! - it would change any selected Groups to the Component ... automatically !
-
No probs...
Glad it works for you...............
Advertisement