• Login
sketchucation logo sketchucation
  • Login
๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

How to add entities inside a group?

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 3 Posters 183 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 20 Oct 2009, 17:41

    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
    • T Offline
      thomthom
      last edited by 20 Oct 2009, 17:56

      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
      • T Offline
        thomthom
        last edited by 20 Oct 2009, 17:57

        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
        • T Offline
          TIG Moderator
          last edited by 20 Oct 2009, 18:04

          @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 20 Oct 2009, 18:26

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

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 20 Oct 2009, 18:45

              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
              1 / 1
              • First post
                1/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement