<?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: How to Rotate a body From Python Script in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069454#M20239</link>
    <description>&lt;P&gt;I think your program probably was working it's just that you were rotating the cylinder around it's axis, so you didn't see any change.&amp;nbsp; In your setToRotation call, change "newComp.yConstructionAxis.geometry.getData()[2]" to "newComp.&lt;FONT color="#ff0000"&gt;z&lt;/FONT&gt;ConstructionAxis.geometry.getData()[2]" and you should see a difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2016 22:53:46 GMT</pubDate>
    <dc:creator>ekinsb</dc:creator>
    <dc:date>2016-03-03T22:53:46Z</dc:date>
    <item>
      <title>How to Rotate a body From Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069337#M20236</link>
      <description>&lt;P&gt;I'm trying to rotate a body, (ideally to align to vector). I have some test code that just rotates by 78 degrees along the yAxis at the origin. However it does nothing. Its based on teh Move example code. How do I rotate a body?&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, traceback
def createNewComponent(rootComp):
    allOccs = rootComp.occurrences
    newOcc = allOccs.addNewComponent(adsk.core.Matrix3D.create())
    return newOcc.component
    
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # Create a document.
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # Get the root component of the active design.
        rootComp = createNewComponent(design.rootComponent)
        ui.messageBox("FirstOrigin: "+ str(rootComp.originConstructionPoint.geometry.asArray()))
        features = rootComp.features

        # Create sketch circle on the xz plane.
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)
        sketchCircles = sketch.sketchCurves.sketchCircles
        centerPoint = adsk.core.Point3D.create(0, 0, 0)
        sketchCircles.addByCenterRadius(centerPoint, 10)

        # Create a collection of entities for extrude
        entities0 = adsk.core.ObjectCollection.create()
        entities0.add(sketch.profiles.item(0))

        # Create a cylinder with ExtrudeFeature using the profile above.
        extrudeFeats = features.extrudeFeatures
        extrudeFeatureInput = extrudeFeats.createInput(entities0, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        extrudeFeatureInput.isSolid = True
        extrudeFeatureInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(2.0))
        extrudeFeature = extrudeFeats.add(extrudeFeatureInput)

        # Create a collection of entities for move
        entities1 = adsk.core.ObjectCollection.create()
        entities1.add(rootComp.bRepBodies.item(0))

        # Create a transform to do move
        transform = adsk.core.Matrix3D.create()
        transform.setToRotation(78,rootComp.yConstructionAxis.geometry.getData()[2],rootComp.originConstructionPoint.geometry)

        # Create a move feature
        moveFeats = features.moveFeatures
        moveFeatureInput = moveFeats.createInput(entities1, transform)
        moveFeats.add(moveFeatureInput)
        ui.messageBox("FirstOrigin: "+ str(rootComp.originConstructionPoint.geometry.asArray()))
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2016 21:50:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069337#M20236</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-03T21:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rotate a body From Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069431#M20237</link>
      <description>&lt;P&gt;I don't see any big problems with your code except that anytime angles are specified or returned by the API that are in radians rather than degrees.&amp;nbsp; The other thing is that the position that you're displaying at the end won't change even if the body is moved.&amp;nbsp; That's because you're getting the position of the occurrence and it hasn't changed.&amp;nbsp; Instead you've moved the body in the component that the occurrence is referencing.&amp;nbsp; I don't know what you're trying to accomplish but I'm guessing that it would be better to move the occurrence instead of the body.&amp;nbsp; The Occurrence object has a transform property that you can set with a Matrix3D to change the occurrence position and orientation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:41:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069431#M20237</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2016-03-03T22:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rotate a body From Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069443#M20238</link>
      <description>&lt;P&gt;Ignore the last statment. Its a debug statement left over froim an old test. I'm not trying to do anything to the occurance. I'm trying to rotate that specific body by any angle (so the radians, degrees problem doesn't matter). If you run this script the cylinder generated does not move at all. It stays still.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a sample script that shows moving a body by any angle. I know this is possible in the system because I rotate objects all the time using the interface displayed below, how do you recreate this?&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/222360i2D34D149417F1E49/image-size/original?v=mpbl-1&amp;amp;px=-1" alt="Capture.PNG" title="Capture.PNG" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:47:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069443#M20238</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-03T22:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rotate a body From Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069454#M20239</link>
      <description>&lt;P&gt;I think your program probably was working it's just that you were rotating the cylinder around it's axis, so you didn't see any change.&amp;nbsp; In your setToRotation call, change "newComp.yConstructionAxis.geometry.getData()[2]" to "newComp.&lt;FONT color="#ff0000"&gt;z&lt;/FONT&gt;ConstructionAxis.geometry.getData()[2]" and you should see a difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:53:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/6069454#M20239</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2016-03-03T22:53:46Z</dc:date>
    </item>
    <item>
      <title>Betreff: How to Rotate a body From Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/13258153#M20240</link>
      <description>&lt;P&gt;#Watch up, Fusion works with radians. So if you want to rodate 45 degree write:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;import math&lt;BR /&gt;&lt;SPAN&gt;alpha&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;math&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;radians&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;45&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;# Then write in line 49:&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;transform&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;setToRotation&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;alpha&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;rootComp&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;zConstructionAxis&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;geometry&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;getData&lt;/SPAN&gt;&lt;SPAN&gt;()[&lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;],&lt;/SPAN&gt;&lt;SPAN&gt;rootComp&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;originConstructionPoint&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;geometry&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2025 17:25:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-rotate-a-body-from-python-script/m-p/13258153#M20240</guid>
      <dc:creator>adminTCYL2</dc:creator>
      <dc:date>2025-01-13T17:25:08Z</dc:date>
    </item>
  </channel>
</rss>

