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

    "refresh" Group BoundingBox

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 532 Views
    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.
    • brewskyB Offline
      brewsky
      last edited by

      For my BIM-Tools plugin I'm creating lots of Group-objects for walls and the like, all with different orientations.

      The problem I'm having is that I generate geometry "in place", based on surrounding entities.
      The easy way is to just add the newly created geometry directly into a new group.
      But that way the group-origin is not the base-point of the wall object, and for rotated walls the bounding box does not line up with the wall.
      A method "set_axes" would solve this, but I can't find something like that...

      I've been trying to, first; transform the empty group in position and, second; inverse-transform all created geometry so everything is in the correct place. But then something weird happens; the bounding box does not get refreshed and is still placed in the "old" geometry position? Anyone an idea how to "refresh" the bounding box? When i manually open and close the group it correctly realigns...

      I could also use components because they have more methods, but these also have limitations:
      A component does have a method for setting the insertion point, but no way to set direction?
      An other problem with components is that I would "spam" the component browser with way too many walls...

      I really think it's fastest to create the geometry "in place", but I'm almost to a point to translate everything to the origin, there create a group, and translate the group back in place.

      I hope I'm just missing the logical way to do this πŸ˜„

      Thanks for any advise!
      Jan

      Sketchup BIM-Tools - http://sketchucation.com/forums/viewtopic.php?p=299107

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

        Do you create geometry - then group? Like when you use SU?
        When using the API it's better to add the group, then add the geometry. (Sorry if you knew this - but I often see people do that.)

        You could create the group at the origin, using the local coordinates and then reposition it.

        FYI, you can place groups with .add_instance like you can with component instances - as long as you have a group's definition. But that's only good for making copies as you need the definition.

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

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

          I think I saw a method to update the bounding box... though I might be confusing it with another method...

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

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            You will need to learn and understand the Geom::Transformation class, and the various instance methods for getting and setting the tranforms for Group and ComponentInstance classes.

            There is also a "secret" local_transformation method that was added to Group and ComponentInstance classes, by the Dynamic Components extension.

            Check the CodeSnippets sticky thread indexes.

            TIG has answered this quetsion many times over. ( Search TIG's posts )

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              You can 'refresh' the bounds of a group by invalidating the bounds of its definition thus:
              group.entities.parent.invalidate_bounds
              This IS needed if you've just changed entities in a group [added/subtracted/relocated] and you need to find the current bounds of that group again straight afterwards... I found this when laying the slice-components out flat inside a group, in my updated Slicer5 tool - if you don't update the bounds you might not find the correct group.bounds.max point, from which you needed to calculate where to place the next instance relatively...

              I suggest you take some notes from my latest Slicer5 code - there's a lot of transforming going on... A slice is made in place as a group and then the origin is redone so all slices are consistent and the slice will be flat when laid out for export... You basically make a translation transformation [or a rotation], and transform the container's entities, then apply the inverse of the transformation to the container itself, so the things appear to be unchanged in the same place but their container has different axes... Sometimes you need to apply several transformations on an object to perhaps rotate its contents, lay them flat and rotate them a certain way so the axis is correct, and then inverse transform the whole container by those in turn, so that the changes are not noticeable [unless axes are set to display]...

              TIG

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

                Ah! That was it.
                ComponentDefinition.invalidate_bounds
                http://code.google.com/apis/sketchup/docs/ourdoc/componentdefinition.html#invalidate_bounds

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

                1 Reply Last reply Reply Quote 0
                • brewskyB Offline
                  brewsky
                  last edited by

                  Thanks Guys!

                  @tig said:

                  You can 'refresh' the bounds of a group by invalidating the bounds of its definition thus:
                  group.entities.parent.invalidate_bounds

                  This did the trick!

                  I think I'm handling the groups(first made a group, then added new entities πŸ˜„ ) and transformations in the right way after fiddling around for a couple of months, but there still is much to learn.

                  For example I didn't know that group.entities.parent returns a "definition", instead of just the group-object itself as I suspected. But when I re-read the documentation i noticed it was all documented! Now I also now where to use ComponentDefinition.group? for!

                  I'll have a look at the slicer5 code, looks interesting πŸ˜„

                  Jan


                  Wall-groups correctly aligned!

                  Sketchup BIM-Tools - http://sketchucation.com/forums/viewtopic.php?p=299107

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

                    Note that you also have ComponentDefinition.image? as Image elements also have definitions. Important to note when iterating the definitions collection.

                    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