• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

How to add entities to a nested group?

Scheduled Pinned Locked Moved Developers' Forum
32 Posts 4 Posters 1.5k 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.
  • T Offline
    TIG Moderator
    last edited by 17 Sept 2010, 20:08

    Aaargh... in your sample code you 'magick' a group out of 'thin air' [groupGroup] and then you add it into a group within a nested group. IF that does exists it certainly isn't inside the 'newRootGroup' [retitled 'rootGroup'] entities as you've just created that - so it will ultimately splat - you ARE cross-threading entities.

    Please try recasting your code [ignoring names and reusing references [variables] as it's getting confusing] in a way I outlined...

    TIG

    1 Reply Last reply Reply Quote 0
    • D Offline
      draftomatic
      last edited by 21 Sept 2010, 22:59

      I think TIG gave up on me... 😳

      1 Reply Last reply Reply Quote 0
      • D Offline
        draftomatic
        last edited by 21 Sept 2010, 23:02

        @tig said:

        Aaargh...
        Please try recasting your code [ignoring names and reusing references [variables] as it's getting confusing] in a way I outlined...

        Argh indeed!

        Here it is - as simple as I can make it. This is 14 lines of code. Now tell me, what is wrong?

        The heirarchy is: model.entities -> group1 -> group2
        After the code finishes, it should be: model.entities -> group1 -> group2 -> faceGroup -> face+edges

        You can see that I'm creating these groups here, so there's no "magick!"

        ` # Testing group nesting

        model = Sketchup.active_model
        modelEntities = model.active_entities

        Create a face

        pts = []
        pts[0] = [0, 0, 0]
        pts[1] = [100, 0, 0]
        pts[2] = [100, 100, 0]
        pts[3] = [0, 100, 0]
        face = modelEntities.add_face(pts)

        Create root group

        group1 = modelEntities.add_group()

        Nest group2 inside group1

        group2 = group1.entities.add_group()

        Create group for faceGroup

        faceGroup = modelEntities.add_group(face)

        Nest in the first level

        newGroup1 = modelEntities.add_group(group1, faceGroup)
        group1.explode()

        Repeat to get it to the second level deep

        newGroup2 = newGroup1.entities.add_group(group2, faceGroup)

        group2.explode() # This crashes SketchUp`

        1 Reply Last reply Reply Quote 0
        • C Offline
          Chris Fullmer
          last edited by 22 Sept 2010, 01:35

          You are exploding group1 though. That does seem right to me. I can't look at it right now, but I probably can try later tonight.

          Seems like you should make a group and add the face data to it. Then make a group and add the facegroup to it. Then make a new group and add the other group to that. I'm sure that is exactly what you've already tried. I'll see if I can write up a fully working sample (unless someone else beats me to it).

          Chris

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • D Offline
            draftomatic
            last edited by 22 Sept 2010, 04:39

            Thank you very much Chris. And thanks to TIG too, even though I'm pretty sure he's moved on to bigger and better threads than this =D

            1 Reply Last reply Reply Quote 0
            • D Offline
              draftomatic
              last edited by 22 Sept 2010, 05:54

              Check it out. I have all these groups (group2 - groupN), under a root group (group1). And then I have faces, which I want to group with edges (faceGroup), and place in a nested group (group2 - groupN). There could potentially be many faceGroups, as shown in the picture...

              HOWEVER... my example script 2 posts up is a simplified version of this, with only one nested group (group2), which is initially empty.

              Clear enough? 😃


              su grouping bug storyboard.JPG

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 22 Sept 2010, 06:24

                I'm confused by all this...
                Why are you not creating the entities directly into the appropriate group instead of trying to move them from group to group?

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

                1 Reply Last reply Reply Quote 0
                • D Offline
                  draftomatic
                  last edited by 22 Sept 2010, 07:57

                  @thomthom said:

                  I'm confused by all this...
                  Why are you not creating the entities directly into the appropriate group instead of trying to move them from group to group?

                  Because, my "real" code gets the faces by way of the user clicking a context menu on an existing face and clicking my plugin's option. So, the face is already there, but my example script is emulating this by creating a face inside of model.entities first...

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 22 Sept 2010, 08:13

                    ok...

                    What about:

                    1. user pick face
                    2. group the face ( group1)
                    3. get the definition of the group ( group1.entities.parent)
                    4. add a new instance of the group into the group you want it
                    5. erase group1

                    When you have the group instance you can use entities.add_instance to add a copy of the group.
                    It might avoid the problems if using .add_group with entities as argument and exploding.

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

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      draftomatic
                      last edited by 22 Sept 2010, 08:40

                      @thomthom said:

                      ok...

                      What about:

                      1. user pick face
                      2. group the face ( group1)
                      3. get the definition of the group ( group1.entities.parent)
                      4. add a new instance of the group into the group you want it
                      5. erase group1

                      When you have the group instance you can use entities.add_instance to add a copy of the group.
                      It might avoid the problems if using .add_group with entities as argument and exploding.

                      Oh... tricky. I'll try that tomorrow.

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 22 Sept 2010, 09:08

                        
                        # picked_face is the face the user selected
                        # group2 is the destination group
                        group1 = picked_face.parent.entities.add_group( picked_face.all_connected )
                        group_def = group1.entities.parent
                        group2.entities.add_instance( group_def, group2.transformation.inverse * group1.transformation )
                        group1.erase!
                        
                        

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

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          draftomatic
                          last edited by 23 Sept 2010, 19:12

                          YAY! Thanks a ton thomthom, your solution works.

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

                          Advertisement