I have a collection of groups and for one of the groups I have assigned the attributes cat, dog and rabbit.
value = ["cat", "dog", "rabbit"]
sel = Sketchup.active_model.selection
obj = sel.first
obj.set_attribute( "PMC", "Pets", value )
If I select this group, I can hide it:
pets = obj.get_attribute("PMC", "Pets")
if pets.include?("cat")
obj.hidden = true
end
If none of the groups are selected I am attempting to interrogate all the groups, using the following, to hide the group with the attribute cat:
group_definitions = Sketchup.active_model.definitions.find_all{|e| e.group? }
groups = group_definitions.collect {|e| e.instances }.flatten
groups.each{ |e|
pets = e.get_attribute("PMC", "Pets")
if pets.include?("cat")
e.hidden = true
end
}
But I am getting the error: #<NoMethodError: undefined method `include?' for nil:NilClass>
EDIT: edited that last section of code to replace
if value.include?("cat")
with
if pets.include?("cat")