Selection to component
-
I'm trying to group selected entitys and then convert it into a component to avoid SketchUp's component creation window.
I have somehow made a wrong turn in my head and since this code doesn't give me an error in the console I'm not sure what I've messed up...
It's probably something embarassingly simple.` mod = Sketchup.active_model
ent = mod.entitiesgrp=[] Sketchup.active_model.selection.each {|e| grp.push(e) } grp=ent.add_group cmp=grp.to_component`
-
There are a couple of flaws in your code. First, you push Entities into the Array referenced by the variable grp and then immediately reassign grp to refer to your new Group. Second, you never added any content to the Group. The garbage collector in SketchUp Ruby is very aggressive about reaping empty Groups!
-
TT already has (tt_groups2comps.rb) it for 100 years and it's perfect. I NEVER use the laggy standard one. Best works with shortcuts G for group, Shift-G for groups2comps
http://sketchucation.com/forums/viewtopic.php?p=257578#p257578 -
Try this:
mod = Sketchup.active_model sel = mod.selection ent = mod.active_entities grp = ent.add_group(sel.to_a) dfn = grp.to_component dfn.name = "Compo#1"
If you don't force a definition name, then the component is confusingly named "Group#NN"
You must use.active_entities
, because if the current selection is not in a matching entities context you'll BugSplat ! -
Thanks TIG.
That worked very well.A short question though.
In the Entitys info window the Instance is now called Compo and the Definition is called Group#1.
I thought the definition would be called Compo? -
My mistake !
Try this...mod = Sketchup.active_model sel = mod.selection ent = mod.active_entities grp = ent.add_group(sel.to_a) ins = grp.to_component ins.definition.name = "Compo#1"
The instance should remain 'un-named'...
-
Thanks again. This time it worked as it should.
-
Thanks to both of you for a very useful code snippet. Especially helpful when you're making a component from loose geometry and forgot to check "Replace selection with component", and have to go through the process twice. Always good to save clicks and annoyances.
Advertisement