sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    New question: more challenging - find group by attribute

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 649 Views 4 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.
    • A Offline
      a4chitect
      last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        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
        end

        Hope this helps,

        DB

        1 Reply Last reply Reply Quote 0
        • AdamBA Offline
          AdamB
          last edited by

          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!

          Developer of LightUp Click for website

          1 Reply Last reply Reply Quote 0
          • C Offline
            CPhillips
            last edited by

            @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)
               }
            }
            
            
            1 Reply Last reply Reply Quote 0
            • A Offline
              a4chitect
              last edited by

              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!

              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