sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Access specifies entity

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 415 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y Offline
      ymagrini
      last edited by

      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:0x00000008fbfd08

      in 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:0x00000008fbfc90

      Sketchup.active_model.entities[10]
      #Sketchup::Edge:0x00000008fbf948

      .....

      Thanks, very much

      Yamil.

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @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:0x00000008fbfd08

        in 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:0x00000008fbfc90

        Sketchup.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
        

        Color Groups.gif

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          # 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
          

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement