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

    Group from Selected Entities

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 342 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.
    • D Offline
      dvonhausen
      last edited by

      This is probably covered in the past but how, using ruby, do I group all of the selected components? In other words, programmatically perform a "Make Group"?

      1 Reply Last reply Reply Quote 0
      • K Offline
        kyyu
        last edited by

        It's done like this:

        model = Sketchup.active_model
        ent = model.entities
        sel = model.selection
        ent.add_group(sel)
        

        You don't want to write it out like this (long way). But this is what the above means(all one line):

        Sketchup.active_model.entities.add_group(Sketchup.active_model.selection)
        
        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          Wasn't there potential issues with adding existing entities to groups via the API?

          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

            @thomthom said:

            Wasn't there potential issues with adding existing entities to groups via the API?

            There was BUT in recent updates it seems much safer, although if the selection contains groups or instances it's safest to add new instances into the group.entities and erase! the originals to avoid splats...

            TIG

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

              @tig said:

              @thomthom said:

              Wasn't there potential issues with adding existing entities to groups via the API?

              There was BUT in recent updates it seems much safer, although if the selection contains groups or instances it's safest to add new instances into the group.entities and erase! the originals to avoid splats...

              But what where the issues in older versions? And workarounds?
              I actually have a project where I need to add some existing faces to groups and then manipulate these faces. Faces are connected to other geometry.

              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

                @thomthom said:

                @tig said:

                @thomthom said:

                Wasn't there potential issues with adding existing entities to groups via the API?

                There was BUT in recent updates it seems much safer, although if the selection contains groups or instances it's safest to add new instances into the group.entities and erase! the originals to avoid splats...

                But what where the issues in older versions? And workarounds?
                I actually have a project where I need to add some existing faces to groups and then manipulate these faces. Faces are connected to other geometry.

                You would sometimes get unexpected BugSplats when grouping an array of entities directly - and you can still do if the array contains instances - it's safest to trap for these and use add_instance() on them in the new entities context, using the original instance's transformation, and then erase the original instance to tidy up! Raw geometry will move from an entities context into a group.entities relatively safely IF the group is in the ents_array[0].parent.entities too...
                Of course 'cross-threading' entities across different contexts always messes up [still]
                However if you only have faces you can usually safely use face_group=entities.add_group(array_of_faces_in_entities) and they'll be cut from entities and go into face_group - the faces disappear from entities, IF there are some face.edges that are no longer needed in entities [because there are no 'dependent' faces left in entities] then these are removed from entities too... BUT if there's an edge in entities that is needed for a face that's moved over into face_group.entities AND is still needed for a face that's left behind in entities, then that edge is 'auto-duplicated' in both entities contexts rather than 'moved' from one entities context to another like the face itself...

                TIG

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

                  cheers

                  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