Access specifies entity
-
Hi, again.
I need your help.I perform an automatic ruby code for change colors of group, but I can't select the specified entity.
My code start from this:
Sketchup.active_model.active_entities.grep(Sketchup::Group).each do |group|
[:........]the poblem is that when open the sketchup project, active_entities is:
Sketchup.active_model.active_entities
#Sketchup::Entities:0x00000008fbfd08in this mode, groups thus are not found.
but, when perform double-click into specified group, then acitve_entities is:
Sketchup.active_model.active_entities
#Sketchup::Entities:0x0000000b5deef8(note that is another id)
how can't find another entity or set active_entity ??
if do a loop or i access by index, then get another components......
Sketchup.active_model.entities[0]
#Sketchup::ComponentInstance:0x00000008fbfc90Sketchup.active_model.entities[10]
#Sketchup::Edge:0x00000008fbf948.....
Thanks, very much
Yamil.
-
@ymagrini said:
Hi, again.
I need your help.I perform an automatic ruby code for change colors of group, but I can't select the specified entity.
My code start from this:
Sketchup.active_model.active_entities.grep(Sketchup::Group).each do |group|
[:........]the poblem is that when open the sketchup project, active_entities is:
Sketchup.active_model.active_entities
#Sketchup::Entities:0x00000008fbfd08in this mode, groups thus are not found.
but, when perform double-click into specified group, then acitve_entities is:
Sketchup.active_model.active_entities
#Sketchup::Entities:0x0000000b5deef8(note that is another id)
how can't find another entity or set active_entity ??
if do a loop or i access by index, then get another components......
Sketchup.active_model.entities[0]
#Sketchup::ComponentInstance:0x00000008fbfc90Sketchup.active_model.entities[10]
#Sketchup::Edge:0x00000008fbf948.....
Thanks, very much
Yamil.
It only matters what context you need to be in. The .active_entities will include the entire model if no group or component is open for edit otherwise just the contents of the open group or component will be in the .active_entities.
Sketchup.active_model.active_entities.grep(Sketchup;;Group).each do |group| group.material=[rand(256),rand(256),rand(256)] end
-
# Search top and 1st nested level for a named group; grps = Sketchup.active_model.active_entities.grep(Sketchup;;Group) if !grps.empty? found = grps.find {|grp| grp.name = "Target Name" } else found = nil end if !found # found will be nil, if group was not found nested = Sketchup.active_model.entities.find_all {|ent| ent.is_a?(Sketchup;;Group) || ent.is_a?(Sketchup;;ComponentInstance) } nested.each {|ent| ents = ent.is_a?(Sketchup;;Group) ? ent.entities ; ent.definition.entities grps = ents.grep(Sketchup;;Group) found = grps.find {|grp| grp.name = "Target Name" } if !grps.empty? } end # found will be the group reference, if it was found # found will be nil, if group was not found
Advertisement