How to find a group?
-
Hi all,
This is such a simple question that I feel silly asking it, but I simply can't figure it out. I'm writing a plugin, and I want to calculate the volume of an object, and I know sketchup can do that if the object is a group.
Basically, the user right-clicks a selection to run my plugin, and I want to make that selection a group, calculate the volume, and then output it. I know how to get their selection, and I know how to get the volume of a group, but I don't know how to tell if their selection is a group or how to turn it into one if it isn't.
Any help would be appreciated!
-
Because it's working on a user's selection then all of the selected entities are in the active_entities context and you won't run the risk of a BugSplat by making a group from them directly [this is advised against usually but try it].
model=Sketchup.active_model ents=model.active_entities ss=model.selection group=ents.add_group(ss.to_a) volume=group.volume group.explode
'volume' is the volume of the selected objects in cu" if the objects don't form a solid then it'll be a negative value...
Assuming that the user should have selected one group to get the volume...if ss[0] and ss[0].class==Sketchup;;Group volume=ss[0].volume if volume==0 UI.messagebox("Warning! The selected group has no volume") elsif volume<0 UI.messagebox("Warning! The select is not a 'solid' group.") end#if else UI.messagebox("Select ONE group!") return nil end#if
there are many ways to achieve what you want
Advertisement