"refresh" Group BoundingBox
-
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 -
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. -
I think I saw a method to update the bounding box... though I might be confusing it with another method...
-
You will need to learn and understand the
Geom::Transformation
class, and the various instance methods for getting and setting the tranforms forGroup
andComponentInstance
classes.There is also a "secret"
local_transformation
method that was added toGroup
andComponentInstance
classes, by the Dynamic Components extension.Check the CodeSnippets sticky thread indexes.
TIG has answered this quetsion many times over. ( Search TIG's posts )
-
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]...
-
Ah! That was it.
ComponentDefinition.invalidate_bounds
http://code.google.com/apis/sketchup/docs/ourdoc/componentdefinition.html#invalidate_bounds -
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 useComponentDefinition.group?
for!I'll have a look at the slicer5 code, looks interesting
Jan
-
Note that you also have
ComponentDefinition.image?
as Image elements also have definitions. Important to note when iterating the definitions collection.
Advertisement