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

Resetting bounding box to match world axis

Scheduled Pinned Locked Moved Developers' Forum
12 Posts 4 Posters 5.0k 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.
  • H Offline
    honoluludesktop
    last edited by 16 Dec 2010, 03:06

    Typically, a component's bounding box (bb hereafter) is created parallel to the world axis. When the component is rotated, the bb rotates. When you explode the rotated component, explode it, then recreate the component, the bb is realigned with the world axis.

    Is there a way to reset a component's bb to the world axis without exploding, then recreating the component? I tried:

    %(#008000)["ComponentDefinition.invalidate_bounds
    Invalidates the bounding box of your definition. This command forces the update of the bounding box of definition while inside an operation."]

    But, the bb did not reset parallel to the world axis. Any ideas?

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 16 Dec 2010, 04:26

      The bounding box that is returned by SU is different than the one that is shown inside of sketchup when you select the component (if I recall correctly).

      To get the visible bounds to change, you would need to edit the component definition, rotate all geometry inside the definition by the rotation of the instance's transformation (or perhaps the inverse of its transformation??). Then remove all rotation from the instance.

      Something along those lines should do the trick,

      Chris

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

      1 Reply Last reply Reply Quote 0
      • H Offline
        honoluludesktop
        last edited by 16 Dec 2010, 07:07

        I recall now, you helped me with this before:

        comp.definition.entities.transform_entities(comp.transformation.invert!,comp.definition.entities.to_a)

        Didn't know that there might be a difference between bb, and what is shown.

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 16 Dec 2010, 07:32

          @chris fullmer said:

          The bounding box that is returned by SU is different than the one that is shown inside of sketchup when you select the component (if I recall correctly).

          You need to get the bounds of the definition - then transform that by the instance transformation.

          @honoluludesktop said:

          comp.definition.entities.transform_entities(comp.transformation.invert!,comp.definition.entities.to_a)

          That would reset scaling and translation as well.

          @honoluludesktop said:

          Didn't know that there might be a difference between bb, and what is shown.

          If you get the bounds of an instance the bb will be oriented to the model or world axis.

          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 16 Dec 2010, 11:34

            @honoluludesktop said:

            The dashed line is the bbox.
            The blue lines is the previous bbox?
            [attachment=1:lqggpjwr]<!-- ia1 -->Temp00.png<!-- ia1 -->[/attachment:lqggpjwr]
            [attachment=0:lqggpjwr]<!-- ia0 -->Temp01.png<!-- ia0 -->[/attachment:lqggpjwr]

            The dashed lines is the Boundingbox you get when you query the instance for it's boundingbox.
            But the blue lines are the actual boundingbox, it's derived from the boundingbox of the definition transformed by the instance transformation.

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

            1 Reply Last reply Reply Quote 0
            • H Offline
              honoluludesktop
              last edited by 16 Dec 2010, 11:37

              The dashed line is the bbox. It's always aligned to the world axis. The blue lines is the bbox when the component is created.
              Temp00.png
              Temp01.png

              1 Reply Last reply Reply Quote 0
              • H Offline
                honoluludesktop
                last edited by 16 Dec 2010, 11:44

                I changed the code from bbox=e.bounds to bbox=e.definition.bounds, and got this:
                Temp02.png

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

                  Nearly there. Take the points from the boundingbox's corners and transform them by the instance's transformation.

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

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    honoluludesktop
                    last edited by 16 Dec 2010, 11:53

                    OK, before I go there, I aligned the bbox with the world axis and got this:
                    Temp04.png
                    Temp03.png

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

                      That's because the instance boundingbox will be oriented to the world axis. Whenever the instance is rotated of axis from this you will get a deviance.

                      I almost forgotten - I got a plugin that draws the selection boundingbox of instances: http://forums.sketchucation.com/viewtopic.php?f=323&t=29377

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

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        honoluludesktop
                        last edited by 16 Dec 2010, 12:19

                        OK done. Where cl is a array of clines, entities.transform_entities(e.transformation,cl.to_a) transforms them into the bbox outline.
                        Temp01.png
                        Temp00.png
                        Thanks.

                        1 Reply Last reply Reply Quote 0
                        • N Offline
                          nickdk
                          last edited by 23 May 2012, 14:28

                          Interesting topic,

                          This this knowledge end up in a plug-in? I'm looking for a way to reset the bounding boxes of 'rotate multiple' components 😄

                          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