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

    How to add entities inside a group?

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 229 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.
    • N Offline
      NewOne
      last edited by

      Well, title says all... I can't figure out how to add entities (component instances) inside a group that I already have created. It contains some entities, but I want to be able to add more things inside it, using a ruby script.
      And one more thing that bothers me: when I initially made the group I did it like this:

      
      ...
      group = model.active_entities.add_group entities_array
      group.name = name
      
      

      But, the problem is that I gave a name just to the group entity and since group.definition.name is not a valid method, I'm stuck. Why I need to give same name to the definition as the entity? Because when/if I use right-click -> Make Component, the new created component instance will take definition's name.

      Thank you.

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        You get a groups definition by group.entities.parent
        But, there's a bug in SU where that reference some times get mixed up with the wrong definition.

        I use this snippet to get groups definitions:

        
        def self.get_real_group_parent(group)
          if group.entities.parent.instances.include?(group)
            return group.entities.parent
          else
            Sketchup.active_model.definitions.each { |definition|
              return definition if definition.instances.include?(group)
            }
          end
          return nil # error
        end
        
        

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          To add entities to a group:

          group.entities.add_face(...)

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            @newone said:

            Well, title says all... I can't figure out how to add entities (component instances) inside a group that I already have created. It contains some entities, but I want to be able to add more things inside it, using a ruby script.
            And one more thing that bothers me: when I initially made the group I did it like this:

            
            > ...
            > group = model.active_entities.add_group entities_array
            > group.name = name
            > 
            

            But, the problem is that I gave a name just to the group entity and since group.definition.name is not a valid method, I'm stuck. Why I need to give same name to the definition as the entity? Because when/if I use right-click -> Make Component, the new created component instance will take definition's name.

            Thank you.

            Last things first...

            
            name=group.name
            inst=group.to_component
            defn=inst.definition
            defn.name=name
            ### done !
            
            

            To add to ANY entities - including those of a group or definition...

            
            ents=group.entities
            tr=Geom;;Transformation.new(point)
            ents.add_instance(defn,tr)
            
            

            TIG

            1 Reply Last reply Reply Quote 0
            • N Offline
              NewOne
              last edited by

              thanks thomthom, can I borrow your snippet for what I need? πŸ˜„ It shows very useful!

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                Go ahead!

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                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