<?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 Manipulating a component's origin in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/manipulating-a-component-s-origin/m-p/6056937#M20300</link>
    <description>&lt;P&gt;is there a way to translate and rotate an orgin of a component using the python API.&lt;/P&gt;&lt;P&gt;I have code to reorient the coordinate system of an occurance but it doesn't seem to do anything to the actual component:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;def translateToNewOrigin(root, newOrigin, newZaxis):
        zAxis = newZaxis
        (x,y,z)= axes(zAxis)
        xAxis = adsk.core.Vector3D.create(x[0],x[1],x[2])
        yAxis = adsk.core.Vector3D.create(y[0],y[1],y[2])
        zAxis = adsk.core.Vector3D.create(z[0],z[1],z[2])
#        reportMessageBox("Axes: \nx:{}\ny:{}\nz:{}",(x,y,z))
        for occurrence in design.rootComponent.allOccurrencesByComponent(root):
    #        reportMessageBox("occurance: {}", (occurrence.component.name))
            # Get the current transform of the occurrence
            transform = occurrence.transform
    #        reportMessageBox("transform: {}", (transform.asArray()))
            coordinateSystem = transform.getAsCoordinateSystem()
    #        reportMessageBox("system: {}, {}, {},{};", coordinateSystem)
            transform.setToAlignCoordinateSystems(coordinateSystem[0],coordinateSystem[1],coordinateSystem[2],coordinateSystem[3],newOrigin,xAxis,yAxis,zAxis)
    #        reportMessageBox("new Transform: {}", (transform.asArray()))
            # Set the tranform data back to the occurrence 
            occurrence.transform = transform
    #        reportMessageBox("result: {}", (self.design.rootComponent.allOccurrencesByComponent(self.RWOH).item(0).transform.asArray()))&lt;/PRE&gt;</description>
    <pubDate>Thu, 25 Feb 2016 20:03:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-02-25T20:03:01Z</dc:date>
    <item>
      <title>Manipulating a component's origin</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/manipulating-a-component-s-origin/m-p/6056937#M20300</link>
      <description>&lt;P&gt;is there a way to translate and rotate an orgin of a component using the python API.&lt;/P&gt;&lt;P&gt;I have code to reorient the coordinate system of an occurance but it doesn't seem to do anything to the actual component:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;def translateToNewOrigin(root, newOrigin, newZaxis):
        zAxis = newZaxis
        (x,y,z)= axes(zAxis)
        xAxis = adsk.core.Vector3D.create(x[0],x[1],x[2])
        yAxis = adsk.core.Vector3D.create(y[0],y[1],y[2])
        zAxis = adsk.core.Vector3D.create(z[0],z[1],z[2])
#        reportMessageBox("Axes: \nx:{}\ny:{}\nz:{}",(x,y,z))
        for occurrence in design.rootComponent.allOccurrencesByComponent(root):
    #        reportMessageBox("occurance: {}", (occurrence.component.name))
            # Get the current transform of the occurrence
            transform = occurrence.transform
    #        reportMessageBox("transform: {}", (transform.asArray()))
            coordinateSystem = transform.getAsCoordinateSystem()
    #        reportMessageBox("system: {}, {}, {},{};", coordinateSystem)
            transform.setToAlignCoordinateSystems(coordinateSystem[0],coordinateSystem[1],coordinateSystem[2],coordinateSystem[3],newOrigin,xAxis,yAxis,zAxis)
    #        reportMessageBox("new Transform: {}", (transform.asArray()))
            # Set the tranform data back to the occurrence 
            occurrence.transform = transform
    #        reportMessageBox("result: {}", (self.design.rootComponent.allOccurrencesByComponent(self.RWOH).item(0).transform.asArray()))&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Feb 2016 20:03:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/manipulating-a-component-s-origin/m-p/6056937#M20300</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-25T20:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating a component's origin</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/manipulating-a-component-s-origin/m-p/6057401#M20301</link>
      <description>&lt;P&gt;I didn't follow how you intend to define your new coordinate system.&amp;nbsp; Just the origin and Z axis isn't enough because the part can still spin around the Z axis.&amp;nbsp; Moving an occurrence is certainly possible.&amp;nbsp; Below is a variation of your program that just uses a point to define the new origin.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;def testTranslate():
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        design = app.activeProduct
        rootComp = adsk.fusion.Component.cast(design.rootComponent)
        
        newOrigin = adsk.core.Point3D.create(1,1,1)
        translateToNewOrigin(design, newOrigin)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def translateToNewOrigin(design, newOrigin):
    root = adsk.fusion.Component.cast(design.rootComponent)
    
    # Iterate through the occurrences in the root component.
    for occurrence in root.occurrences:
        # Get the current transform of the occurrence.
        trans = adsk.core.Matrix3D.cast(occurrence.transform)
        
        # Change the translation portion of the matrix to account for the new origin.
        trans.translation = newOrigin.asVector()

        # Set the transform of the occurrence.
        occurrence.transform = trans

    # Snapshot the changes.
    root.parentDesign.snapshots.add()
&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Feb 2016 00:52:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/manipulating-a-component-s-origin/m-p/6057401#M20301</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2016-02-26T00:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating a component's origin</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/manipulating-a-component-s-origin/m-p/8488737#M20302</link>
      <description>&lt;P&gt;I have read many times that the Fusion GUI does not allow any manipulation of a component's origin. Does your post mean that you can override this limitation by directly manipulating a component's origin programmatically through the Python interface? Does the Python interface, therefore, expose functionalities that are hidden from the GUI?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 07:04:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/manipulating-a-component-s-origin/m-p/8488737#M20302</guid>
      <dc:creator>AagAag</dc:creator>
      <dc:date>2018-12-27T07:04:38Z</dc:date>
    </item>
  </channel>
</rss>

