Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for
Show  only  | Search instead for
Did you mean:

## Converting points from alternate coordinate systems to match Fusion 360

4 REPLIES 4
SOLVED
Message 1 of 5
335 Views, 4 Replies

## Converting points from alternate coordinate systems to match Fusion 360

I have several mechanical drawings where the mounting holes for the device use a different coordinate system. Here's one, taken from below, with the origin be on the right bottom. It's essentially the same as the Fusion 360 coordinate system, except flipped over.

Some mechanical drawings also require to be rotated and moved.  If for a minute, imagine the above diagram is rotated 90 or 270 degrees.

I'm trying to figure out how to transform the points for holes from their coordinate system, to one that Fusion use.

``````# Hardcoded for now
width = 77.0 # X
depth = 44.0 # Y
points = [[61.69, 5.69], [61.69, 39.99], [4.24, 21.49]]
face = "bottom"
#
# Code Omitted
#
sketchPoints = sketch.sketchPoints
for p in points:
x = p[0]
y = p[1]
pt = None
if face == "bottom":
elif face == "top":
else:
raise "Not Implemented"
# Rotate

Is there a better approach to converting between coordinate systems in Fusion 360, than writing a ton of code?

Software Engineer
https://wernerstrydom.com
4 REPLIES 4
Message 2 of 5

Hello,

I would do like this:

``````# Hardcoded for now
width = 77.0 # X
depth = 44.0 # Y
points = [[61.69, 5.69], [61.69, 39.99], [4.24, 21.49]]
face = "bottom"
#
# Code Omitted
#

if face == "bottom":
f = -1
elif face == "top":
f = 1
else:
raise "Not Implemented"

sketchPoints = sketch.sketchPoints

for p in points:
x = p[0]
y = p[1]
pt = None
# Rotate

Message 3 of 5

That's essentially what I ended up doing. That being said, I was hoping there's a built-in mechanism to convert between different coordinate systems.

Software Engineer
https://wernerstrydom.com
Message 4 of 5

A transformation matrix will do that for you. You can define a matrix that defines the transformation from one coordinate system to another and then use that to transform each of your points.

Here's an example.

Let's assume I have a coordinate system like the one in your original description where positive X is to the left and positive Y is up. I have some points whose coordinates are defined relative to that coordinate system.  I want to create those same points in Fusion but I know that coordinate system is different than the sketch coordinate system.  In this sample, the coordinate system is not only oriented like I described, but the origin is 10 cm in the X direction of the sketch coordinate system.  Here's a picture, where the coordinate system the points are defined in is purple and the sketch coordinate system is shown in green.

Here's the code. The original points are (1,1,0), (1,2,0), (1,3,0), and (1,4,0) and are defined relative to the purple coordinate system. In the code, the position and orientation of the purple coordinate system is defined. It then uses that to create a transformation matrix to go from that coordinate system to the sketch coordinate system. The points are then transformed and created in the sketch. They are positioned as shown in the picture. The (1,1,0) point now has the coordinate (9,1,0) after the transform has been applied.

I also draw some lines in the sketch so you can see where the X and Y axes are because Fusion doesn't show that.

``````def MatrixSample():
try:

# Define the coordinate system the points are currently defined in where it
# is defined with respect to the sketch coordinate system.

points = []

# Define the matrix that describe the transform into sketch space.
zDir = xDir.crossProduct(yDir)
yDir = zDir.crossProduct(xDir)
otherCoordSys.setWithCoordinateSystem(origin, xDir, yDir, zDir)

# Invert it to shift it to the sketch coordinate system.
otherCoordSys.invert()

ui.messageBox('A sketch must be active.')
return

for point in points:
# Transform the point.
point.transformBy(otherCoordSys)

# Create the point in the sketch.

# Draw the axes of the sketch coordinate system to be able to visualize it.
lines = sketch.sketchCurves.sketchLines
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))``````

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 5