Change color entity group
-
-
You need to find the group.
There are several methods, depending on how your 'tool' is getting its information...
a.group = Sketchup.active_model.selection[0]
assuming one group is selected...
Assumingmy_name = "Grupo#72"
b.group = Sketchup.active_model.active_entities.grep(Sketchup::Group).select{|g| g.name = my_name }[0]
which gives you the first group of that name in the current active entities context...
c.named_groups = [] Sketchup.active_model.definitions.select{|d| d.group? }.each{|g| g.instances.each{|i| named_groups << i if i.name == my_name }}
Now you have an array of all groups named 'my_name
'
Often there will be only one... but you CAN rename several groups with the exact same name !
If you are sure then there'll only be one, thengroup = named_groups[0]
Let's us assume you have a '
group
' reference...Now you need to get a material...
There are several ways to get a reference to the material...Assuming
my_material_name = "My_Lovely_Material"
a.material = Sketchup.active_model.materials[my_material_name]
If it returnsnil
then it doesn't exist.
Otherwise it's a reference to that material.
b. To make the new material use:
` if material = Sketchup.active_model.materials[my_material_name]do stuff with 'material'
else ### make the new 'material'
material = Sketchup.active_model.materials.add(my_material_name)
material.color = [123, 123, 123] ### some RGB value
end`Now you have the references to the
group
and thematerial
, use them thus...
group.material = material
There are many ways to skin a cat...
-
Excelente!
Thanks very much!
Advertisement