<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Converting points from alternate coordinate systems to match Fusion 360 in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/11442816#M6500</link>
    <description>Incredibly useful to me!!!</description>
    <pubDate>Sat, 24 Sep 2022 10:11:22 GMT</pubDate>
    <dc:creator>en9y37</dc:creator>
    <dc:date>2022-09-24T10:11:22Z</dc:date>
    <item>
      <title>Converting points from alternate coordinate systems to match Fusion 360</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/10973814#M6496</link>
      <description>&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wernersLNPQD_0-1645929733874.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1030202i6DF28AB364278893/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wernersLNPQD_0-1645929733874.png" alt="wernersLNPQD_0-1645929733874.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Some mechanical drawings also require to be rotated and moved. &amp;nbsp;If for a minute, imagine the above diagram is rotated 90 or 270 degrees.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to figure out how to transform the points for holes from their coordinate system, to one that Fusion use.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 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 
#
pts = adsk.core.ObjectCollection.create()
sketchPoints = sketch.sketchPoints
for p in points:
    x = p[0]
    y = p[1]
    app.log(f'Adding hole at ({x}, {y})')
    pt = None
    if face == "bottom":
        pt = sketchPoints.add(adsk.core.Point3D.create(-1*x/10, y/10, 0))
    elif face == "top":
        pt = sketchPoints.add(adsk.core.Point3D.create(x/10, y/10, 0))
    else:
        raise "Not Implemented"
    # Rotate
    pts.add(pt)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Is there a better approach to converting between coordinate systems in Fusion 360, than writing a ton of code? &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Feb 2022 03:07:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/10973814#M6496</guid>
      <dc:creator>bloudraak</dc:creator>
      <dc:date>2022-02-27T03:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Converting points from alternate coordinate systems to match Fusion 360</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/10975130#M6497</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would do like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# 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"
    
pts = adsk.core.ObjectCollection.create()
sketchPoints = sketch.sketchPoints

for p in points:
    x = p[0]
    y = p[1]
    app.log(f'Adding hole at ({x}, {y})')
    pt = None
    pt = sketchPoints.add(adsk.core.Point3D.create(f*x/10, y/10, 0))
    # Rotate
    pts.add(pt)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 12:28:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/10975130#M6497</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2022-02-28T12:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Converting points from alternate coordinate systems to match Fusion 360</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/10985423#M6498</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 04:54:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/10985423#M6498</guid>
      <dc:creator>bloudraak</dc:creator>
      <dc:date>2022-03-05T04:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting points from alternate coordinate systems to match Fusion 360</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/10985457#M6499</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example.&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; I want to create those same points in Fusion but I know that coordinate system is different than the sketch coordinate system.&amp;nbsp; 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.&amp;nbsp; Here's a picture, where the coordinate system the points are defined in is purple and the sketch coordinate system is shown in green.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="MatrixSample.png" style="width: 519px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1032758i8BBEA1C8250377B5/image-size/large?v=v2&amp;amp;px=999" role="button" title="MatrixSample.png" alt="MatrixSample.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def MatrixSample():
    try:
        des: adsk.fusion.Design = app.activeProduct

        # Define the coordinate system the points are currently defined in where it
        # is defined with respect to the sketch coordinate system.
        origin = adsk.core.Point3D.create(10, 0, 0)
        xDir = adsk.core.Vector3D.create(-1, 0, 0)
        yDir = adsk.core.Vector3D.create(0, 1, 0)

        points = []
        points.append(adsk.core.Point3D.create(1, 1, 0))        
        points.append(adsk.core.Point3D.create(1, 2, 0))        
        points.append(adsk.core.Point3D.create(1, 3, 0))        
        points.append(adsk.core.Point3D.create(1, 4, 0))        

        # Define the matrix that describe the transform into sketch space.
        otherCoordSys = adsk.core.Matrix3D.create()
        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()

        if app.activeEditObject.objectType != adsk.fusion.Sketch.classType():
            ui.messageBox('A sketch must be active.')
            return

        sketch: adsk.fusion.Sketch = app.activeEditObject
        for point in points:
            # Transform the point.
            point.transformBy(otherCoordSys)

            # Create the point in the sketch.
            sketch.sketchPoints.add(point)

        # Draw the axes of the sketch coordinate system to be able to visualize it.
        lines = sketch.sketchCurves.sketchLines
        lines.addByTwoPoints(adsk.core.Point3D.create(0,0,0), adsk.core.Point3D.create(10,0,0))
        lines.addByTwoPoints(adsk.core.Point3D.create(0,0,0), adsk.core.Point3D.create(0,5,0))
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 06:02:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/10985457#M6499</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2022-03-05T06:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Converting points from alternate coordinate systems to match Fusion 360</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/11442816#M6500</link>
      <description>Incredibly useful to me!!!</description>
      <pubDate>Sat, 24 Sep 2022 10:11:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/converting-points-from-alternate-coordinate-systems-to-match/m-p/11442816#M6500</guid>
      <dc:creator>en9y37</dc:creator>
      <dc:date>2022-09-24T10:11:22Z</dc:date>
    </item>
  </channel>
</rss>

