Find Group name
-
How can I find the name of the active group by program?
-
I assume you mean that you are editing a group and need to find its name...
Try:def context() model=Sketchup.active_model context=model.active_entities.parent if context==model return "MODEL; "+model.title elsif context.group? return "GROUP; "+context.instances[0].name elsif ! context.image? return "COMPO; "+context.name end end
This method 'context' returns the model name OR the group name OR if it's a component name of the definition... [you can't easily get an instance's name while you are inside it as you are editing the definition itself]...
-
Thanks for the quick reply.
With a method I want to open the doors and needed to know whether it is the left or right door. -
How do I find the name of the selected door?
-
You give barely enough background information
name=Sketchup.active_model.selection[0].name if Sketchup.active_model.selection[0].respond_to?(:name)
returns the name of a selected entity if it has a name method...or
` Sketchup.active_model.selection.each{|e|
if e.respond_to?(:name)
name=e.namedo something with name ?
end
}`There are many scenarios...
-
I find a way.
# {Ecken von ausgewaehlten Elementen ermitteln() # def ecken_ermitteln model = Sketchup.active_model entities = model.active_entities auswahl = model.selection context = auswahl.first MoMo;;g_name = context.name MoMo;;teile = entities.add_group auswahl model.selection.add(MoMo;;teile) auswahl = model.selection e = auswahl.at(0) bounds_a = e.bounds MoMo;;x_mass = bounds_a.width MoMo;;y_mass = bounds_a.height MoMo;;z_mass = bounds_a.depth MoMo;;i_li = bounds_a.corner(2)[0] if MoMo;;tuer_c_o_li == 0 MoMo;;i_re = bounds_a.corner(3)[0] if MoMo;;tuer_c_o_re == 0 # corner(n) = # 0 = [0, 0, 0] (left front bottom) # 1 = [1, 0, 0] (right front bottom) # 2 = [0, 1, 0] (left back bottom) # 3 = [1, 1, 0] (right back bottom) # 4 = [0, 0, 1] (left front top) # 5 = [1, 0, 1] (right front top) # 6 = [0, 1, 1] (left back top) # 7 = [1, 1, 1] (right back top) end # {S-Tuer oeffnen/schliessen() # def schiebetuer_open_close_li_gen model = Sketchup.active_model entities = model.active_entities status = ecken_ermitteln # siehe oben if MoMo;;g_name == 'Schiebetuer_li' x2 = MoMo;;x_mass / 3 * 2 x1 = x2 if MoMo;;tuer_c_o_li == 0 x1 = -x2 if MoMo;;tuer_c_o_li == 1 a1 = 0 if MoMo;;tuer_c_o_li == 0 a2 = 1 if MoMo;;tuer_c_o_li == 1 t1 = Geom;;Transformation.translation [x1,0,0] entities.transform_entities t1, MoMo;;teile MoMo;;tuer_c_o_li = 1 if a1 == 0 MoMo;;tuer_c_o_li = 0 if a2 == 1 else UI.messagebox 'Es wurde eine falsche Tuer ausgewaehlt.' end status = MoMo;;teile.explode end def schiebetuer_open_close_re_gen model = Sketchup.active_model entities = model.active_entities status = ecken_ermitteln # siehe oben if MoMo;;g_name == 'Schiebetuer_re' x2 = MoMo;;x_mass / 3 * 2 x1 = -x2 if MoMo;;tuer_c_o_re == 0 x1 = x2 if MoMo;;tuer_c_o_re == 1 a1 = 0 if MoMo;;tuer_c_o_re == 0 a2 = 1 if MoMo;;tuer_c_o_re == 1 t1 = Geom;;Transformation.translation [x1,0,0] entities.transform_entities t1, MoMo;;teile MoMo;;tuer_c_o_re = 1 if a1 == 0 MoMo;;tuer_c_o_re = 0 if a2 == 1 else UI.messagebox 'Es wurde eine falsche Tuer ausgewaehlt.' end status = MoMo;;teile.explode end
Advertisement