Trying to set global axis from API
-
xaxis = Geom;;Vector3d.new(3, 5, 0) yaxis = xaxis * Z_AXIS Sketchup.active_model.axes.set([10,0,0], xaxis, yaxis, Z_AXIS)
when I use this API example I get the error message:
undefined method ‘axes’ for #Sketchup::Model:0x9815c70What I am trying to accomplish is to draw a rectangle that is the outside extents of a face.
Similar to a bounding box for the face except the bounding box aligns with the global axes and thus for some faces is 3 dimensional not single planeSo I am trying to align the Global Axes with a face to create a bounding box that matches the face plane. Then reset Global Axes to Default
-
@ktkoh said:
xaxis = Geom;;Vector3d.new(3, 5, 0) > yaxis = xaxis * Z_AXIS > Sketchup.active_model.axes.set([10,0,0], xaxis, yaxis, Z_AXIS)
when I use this API example I get the error message:
undefined method ‘axes’ for #Sketchup::Model:0x9815c70The
Sketchup::Model#axes()
method and theSketchup::Axes
object class are only available with SketchUp version 2016 and higher.@ktkoh said:
So I am trying to align the Global Axes with a face to create a bounding box that matches the face plane. Then reset Global Axes to Default
You can never actually change the global axes. The global origin and axes are always where they are. (They are referenced via global constants
ORIGIN
,X_AXIS
,Y_AXIS
, andZ_AXIS
. **Do NOT attempt to reassign these constants!**You will only result in confusing other extensions and plugins.)The axes method and class changes the drawing axes, which is a temporary user axes that native tools honor, and plugins can honor IF they are written to specifically use the drawing axes. (Extension code will not use the custom drawing axes by default.)
-
You need to approach the issue from the other direction...
You want to end up with a group that includes a face, that has a bounding box which has its base on the face, thus setting the group's bounds z-axis equivalent to the face's normal.
To achieve this you first make a group containing the face - potentially inclined and off axes.
Make a combined transformation that moves the face, and anything else in the group, to the origin and rotated so that its normal is parallel to the z-axis.
Immediately apply that transformation.inverse to the group.
Now the face will look just the same, but its group's bounds are skewed to suit.
You might also need to invalidate the group's definition's bounds to ensure the current bounding box displays properly. -
@ktkoh said:
So I am trying to align the Global Axes with a face to create a bounding box that matches the face plane. Then reset Global Axes to Default
It occurs to me that you really want the maximum 2d extents of the face, and really it might best be done virtually rather than modifying the geometry of the model.
Get the array of vertices in the face's outer loop.
Iterate that array mapping the vertex positions to a new 2D array.
(The first vertex should be put at coords 0,0. BTW, you can transform points if you have [or can get] the transformation of the original face. Ie, get the vector from the first vertex to the 2nd and use it to create a transformation for the face if you must.)
Lastly, get the max X and Y value for the 2D box's height and width. -
Thanks for the comments. This looks like a much more involved solution than my problem is worth. I think I will just stay with the requirement that component joint face needs to hahe 2 edges, common vertex and intersect at 90 degrees to work with my joint tool plugin. I was thinking of a plugin that would add a rectangular face on the existing face to be used for joint detail then deleted when finished. This worked for parts aligmed to the globel axis but not with rotated parts.
Keith
Advertisement