How code select group child with the name is ...?

Hello

I would like to add attributes to child groups of the selected component.
I know the names of the groups: “Flowers”, “Fruits”, “Annual Vegetation”.

Code to retrieve the name of the parent component in a “c_parent” variable
c_parent =?

code to count the number of groups
n_child =?

#Code loop to select each child group of the component
for each 1 to n_child

on select the child group

we get the name of the child group
g_enfant =?

set the Hidden attribute according to the following condition:

  • if g_enfant = “Annual Vegetation” then Hidden = c_parent! vgtx_101
  • if g_enfant = “Flowers” then Hidden = c_parent! vgtx_102
  • if child = “Fruits” then Hidden = c_parent! vgtx_103

redraw the group

End of loop

Thank you

Simon :smiley:

Just a guess but perhaps something like this

mod = Sketchup.active_model
ent = mod.active_entities
sel = mod.selection
SKETCHUP_CONSOLE.clear
cis = sel.grep(Sketchup::ComponentInstance)[0]
cis.each{|ci|
  c_parent = ci.definition.name; p c_parent
  groups = ci.definition.entities.grep(Sketchup::Group)
  groups.each{|g|
    case g.name
    when "Annual Vegitation";p 'veg'
      g.set_attribute("Groups","Hidden","#{c_parent} vgtx_101")
    when "Flowers";p 'flr'
      g.set_attribute("Groups","Hidden","#{c_parent} vgtx_102")
    when "Fruits";p 'fru'
      g.set_attribute("Groups","Hidden","#{c_parent} vgtx_103")
    end
  }
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.