• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Adding child group while parent group is active

Scheduled Pinned Locked Moved Plugins
10 Posts 4 Posters 1.1k 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
    DavidBoulder
    last edited by 11 Aug 2010, 15:51

    We are having some problems getting the transformation correct when adding a child group to a parent group when that parent group is active. If the parent group isn't active then it works fine.

    Has anyone else had this problem. Details and technique to duplicate are below.

    Our workflow is that the user adds child groups to a parent group while the parent is open. The script below shows my problem, you have to enter it line by line in the ruby console because there are steps (Steps A and B) where you have to click around to change the current active group. I have tried calling make unique on both groups to no avail and can’t even do a work around of setting the child’s transformation to the parent’s inverse transformation because when I try to get the parent’s transformation it comes back as identity. I would really appreciate any help in finding a work around for this, I don’t want to have to go to components instead of groups unless I really have to.

    Script is below:

    # clear everything out
    Sketchup.active_model.entities.clear!
    
    # add the parent group
    group1 = Sketchup.active_model.entities.add_group
    
    # didn’t work
    # group1.make_unique
    
    # set parent’s transformation
    group1.transformation = Geom;;Transformation.translation(Geom;;Point3d.new(10.m, 0, 0))
    
    # add some points to the parent group
    group1.entities.add_cpoint(Geom;;Point3d.new(0.m, 0.m, 0.m)) 
    group1.entities.add_cpoint(Geom;;Point3d.new(5.m, 5.m, 3.m))
    
    # the parent group’s transformation shows the correct translation
    puts group1.transformation.to_a.join(', ')
    
    # step A) double click group1 to open it
    
    # parent’s transformation now shows as identity?
    puts group1.transformation.to_a.join(', ')
    
    # add the child group
    group2 = group1.entities.add_group
    
    # didn’t work
    # group2.make_unique
    
    # we want the child group’s axes to be the same as the parent group’s axes, unfortunately this seems to put it at the absolute origin
    group2.transformation = Geom;;Transformation.new 
    
    # add some points to the child group
    group2.entities.add_cpoint(Geom;;Point3d.new(0.m, 0.m, 1.m)) 
    group2.entities.add_cpoint(Geom;;Point3d.new(5.m, 5.m, 4.m))
    
    # step B) exit out of all groups to top level model
    
    # the parent group’s transformation is correct
    puts group1.transformation.to_a.join(', ')
    
    # the child group has a negative translation to bring it back to the origin?  Why?
    puts group2.transformation.to_a.join(', ')
    
    # this will put group2 where it is supposed to be
    group2.transformation = Geom;;Transformation.new 
    
    # group transformations are now correct
    puts group1.transformation.to_a.join(', ')
    puts group2.transformation.to_a.join(', ')
    
    

    --

    David Goldwasser
    OpenStudio Developer
    National Renewable Energy Laboratory

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 11 Aug 2010, 16:17

      @unknownuser said:

      Returns the transformation of the current component edit session. If a user has double-clicked to edit a component's geometry, this will return the transformation of that component, relative to its parent's origin. This allows one to correctly calculate "local" transformations of a given entity regardless of whether the user is in edit mode.

      http://code.google.com/apis/sketchup/docs/ourdoc/model.html#edit_transform

      Have you looked into that method? SU7+ though.

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

      1 Reply Last reply Reply Quote 0
      • M Offline
        macumber
        last edited by 11 Aug 2010, 16:38

        Thanks ThomThom, do you have any information explaining edit_transform in more detail? In my case I have group1 with group2 inside of it. I sort of understand what this does when the active_path is '[group1]'. However, what happens when the active path is '[group1, group2]'? What I'm really after is some documentation like:

        when active_path is '[]', group1.transformation returns xxx, group2.transformation returns yyy, active_model.edit_transform returns zzz
        when active_path is '[group1]', group1.transformation returns xxx, group2.transformation returns yyy, active_model.edit_transform returns zzz
        when active_path is '[group1, group2]', group1.transformation returns xxx, group2.transformation returns yyy, active_model.edit_transform returns zzz

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 11 Aug 2010, 17:09

          If I remember correctly, when a group/component is open for editing SU will transform the coordinates inside the active context into global coordinates. With model.edit_transform you can convert the coordinates you get while editing back into local coordinates.

          You also have model.active_path http://code.google.com/apis/sketchup/docs/ourdoc/model.html#active_path with give you access to the current edit path.

          I can't remember exactly how it worked - I'm sure someone else will chime in.

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

          1 Reply Last reply Reply Quote 0
          • M Offline
            macumber
            last edited by 11 Aug 2010, 17:26

            I guess a simple question is which component are you editing when you are editing group2 inside of group1? Are you editing group2, group1, or both?

            1 Reply Last reply Reply Quote 0
            • D Offline
              danbig
              last edited by 11 Aug 2010, 19:01

              @davidboulder said:

              ...I don’t want to have to go to components instead of groups unless I really have to.

              Just out of curiosity, why do you want to use groups instead of components? I've been trying to set some standards for my own workflow of when to use a group vs. a component (beyond the obvious of having multiple instances of the same entity, or needing the internal reference axis of components).

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 11 Aug 2010, 19:44

                @danbig said:

                Just out of curiosity, why do you want to use groups instead of components? I've been trying to set some standards for my own workflow of when to use a group vs. a component (beyond the obvious of having multiple instances of the same entity, or needing the internal reference axis of components).

                Groups don't add entries in the Component Browser. The comp list quickly grows in a project, so unless I know I will need multiple instances of an object I create groups.

                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
                  danbig
                  last edited by 12 Aug 2010, 00:00

                  What about being able to change the internal axis of a component? It seems like this changes the orientation of the bounding box as well. Does this have any consequence on your workflow?

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 12 Aug 2010, 06:06

                    @danbig said:

                    What about being able to change the internal axis of a component? It seems like this changes the orientation of the bounding box as well. Does this have any consequence on your workflow?

                    Never trust the API docs. 😕
                    Also check out the comments at the bottom of the page.

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

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      macumber
                      last edited by 12 Aug 2010, 13:55

                      Well I guess I will have to get off my butt and post the answer to my own question:

                      
                      # clear everything out
                      Sketchup.active_model.entities.clear!
                      
                      # add the parent group
                      group1 = Sketchup.active_model.entities.add_group
                      
                      # set parent’s transformation
                      group1.transformation = Geom;;Transformation.translation(Geom;;Point3d.new(10.m, 0, 0))
                      
                      # add some points to the parent group
                      group1.entities.add_cpoint(Geom;;Point3d.new(0.m, 0.m, 0.m))
                      group1.entities.add_cpoint(Geom;;Point3d.new(5.m, 5.m, 3.m))
                      
                      # add the child group
                      group2 = group1.entities.add_group
                      
                      # set child’s transformation
                      group2.transformation = Geom;;Transformation.translation(Geom;;Point3d.new(0, 10.m, 0))
                      
                      # add some points to the child group
                      group2.entities.add_cpoint(Geom;;Point3d.new(0.m, 0.m, 0.m))
                      group2.entities.add_cpoint(Geom;;Point3d.new(5.m, 5.m, 3.m))
                      
                      # group transformations are now correct
                      puts Sketchup.active_model.active_path
                      puts group1.transformation.to_a.join(', ')
                      puts group2.transformation.to_a.join(', ')
                      puts Sketchup.active_model.edit_transform.to_a.join(', ')
                      
                      # from top level
                      active_path = nil
                      group1.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 393.700787401575, 0.0, 0.0, 1.0]
                      group2.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 393.700787401575, 0.0, 1.0]
                      edit_transform = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
                      
                      # open group1
                      active_path = [group1]
                      group1.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
                      group2.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 393.700787401575, 393.700787401575, 0.0, 1.0]
                      edit_transform = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 393.700787401575, 0.0, 0.0, 1.0]
                      
                      # open group2
                      active_path = [group1, group2]
                      group1.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
                      group2.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
                      edit_transform = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 393.700787401575, 393.700787401575, 0.0, 1.0]
                      
                      
                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      1 / 1
                      • First post
                        1/10
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement