New question: more challenging - find group by attribute
-
here goes another question for all ruby-positive out there
is it possible to find the parent of an attribute (simply said: find a group by its attribute?)
i'm trying with a code like this to find all "john" groups
Sketchup.active_model.active_entities.find_all {|x| (x.get_attribute "data", "name").index('john') > 0}
and thanks!
-
Hi,
The parent of a group is (strangely) a component definition. So getting an attribute from each entity of the model doesn't work in this case.
You should test something like that:if entity.parent.typename == "ComponentDefinition" and entity.group? and entity.parent.get_attribute ("dictname", "key") == "john"
then store the group ID in an array or whatever...or:
Sketchup.active_model.definitions.each do |def|
if def.group? and def.get_attribute("dictname", "key") == "john"
...
end
endHope this helps,
-
Does anyone understand the bizarre parts hierarchy in Sketchup? As Didier says the parent of a group is a quasi anonymous Definition (called "Group#N"). So you get things like group.entities.parent != group which caught me out!
-
@a4chitect said:
here goes another question for all ruby-positive out there
is it possible to find the parent of an attribute (simply said: find a group by its attribute?)
i'm trying with a code like this to find all "john" groups
Sketchup.active_model.active_entities.find_all {|x| (x.get_attribute "data", "name").index('john') > 0}
and thanks!
I think this is what you want:
all=[] Sketchup.active_model.definitions.each{|cd| cd.instances.each{|ci| all.push(ci) if((ci.get_attribute("data", "name")).index('john') > 0) } }
-
Thanks didier and cphilips for everything especially for speed, i will release few rubies in a short time, so i hope it will reward you for your efforts. Have a nice time. I finally understand the real power of sketchup: ruby & community. And i think that your and others rubies have raised the SU version number higher then 10, so the only functionality I wish for in the official 7 is photosketch and better menu interface for plugins. This topic hijack is intentional. Thanks!
Advertisement