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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement