Utilizing the Axes Class with the API

I haven’t had much need to use this class or its methods yet but I was testing it out earlier today and noticed that when I set the axis to a new location (move it in the Z dir) it does not seem to make any difference to my API code when I generate geometry, is this by design?

Changing the axes from the UI doesn’t change the actual global axes of the model, just the drawing axes. The axes class can be used if you want your tool to honor the visible drawing axes.

1 Like

Yes. As a rule, the API team tries not to implement changes that affect or change code out “in the wild”.

So they chose to implement this as a pseudo geometry context with a transformation that can be applied to the geometry (vertices, edges, faces, etc.,) that your tool creates.

So, it is you and your code that need to decide when to honor the user’s drawing axes setting.
Ie, from my post of 11 days ago …


Note also that I filed an issue for a missing reset() method.
(See the issue thread for a couple of workaround ideas.)

… and an enhancement to the Sketchup::Axes#set() method …

1 Like

So what would be the best way of honoring the drawing axis if I wanted my API code to generate its geometry relative to the user defined coordinate system? Is there a specific way to do this or do I just add in my own offsets while creating the geometry?

From the Ruby API documentation for Axes:

#transformation ⇒ Object

The transformation method returns the transformation of the axes. This is useful when creating tools that respect the model's drawing axes.

Examples:

# Point for a rectangle.
points = [
  Geom::Point3d.new( 0,  0, 0),
  Geom::Point3d.new(10,  0, 0),
  Geom::Point3d.new(10, 20, 0),
  Geom::Point3d.new( 0, 20, 0)
]
# Transform the points so they are local to the model axes. Otherwise
# they would be local to the model origin.
tr = Sketchup.active_model.axes.transformation
points.each { |point| point.transform!(tr) }
Sketchup.active_model.active_entities.add_face(points)
Returns:
 Transformation - the transformation for the axes.
Version:
SketchUp 2016
1 Like

Nate, we really should not be having to paste from the API docs here. You should have read the entire class before even starting this thread. (FYI, I gave a link to the exact method that Steve posted, in my above but it hasn’t yet been clicked on.)

no kidding:roll_eyes:

1 Like