<?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: Moving assembly components with an API script in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-assembly-components-with-an-api-script/m-p/14137168#M22803</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/18995438"&gt;@greenmica&lt;/a&gt;&amp;nbsp;-san.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;If possible, I would have liked to see a sample.&lt;/P&gt;
&lt;P&gt;I think calling `fusion.Design.computeAll` will solve the problem.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        # Create a new document with parametric (hybrid) design mode
        app.documents.add(core.DocumentTypes.FusionDesignDocumentType)
        des: fusion.Design = app.activeProduct
        des.designType = fusion.DesignTypes.ParametricDesignType
        root: fusion.Component = des.rootComponent

        # Create a sketch on the XY plane
        skt: fusion.Sketch = root.sketches.add(root.xYConstructionPlane)

        # Add 5 control points and create a fitted spline
        pts: core.ObjectCollection = core.ObjectCollection.create()
        pts.add(core.Point3D.create(-5, 0, 0))
        pts.add(core.Point3D.create(2, 3, 0))
        pts.add(core.Point3D.create(4, 1, 0))
        pts.add(core.Point3D.create(6, 4, 0))
        pts.add(core.Point3D.create(8, 0, 0))
        spline: fusion.SketchFittedSpline = skt.sketchCurves.sketchFittedSplines.add(pts)

        # Create cylinder components jointed to control points 2, 3, 4 (index 1, 2, 3)
        add_cylinder_component(root, spline, 1)
        add_cylinder_component(root, spline, 2)
        add_cylinder_component(root, spline, 3)

        # Refresh the viewport and notify that components were created
        adsk.doEvents()
        app.activeViewport.refresh()
        ui.messageBox("3 cylinder components created and jointed to control points 2, 3, 4.")

        # Move spline control points 2, 3, 4
        offsets: list[tuple[float, float, float]] = [
            (0, 3, 0),
            (0, -3, 0),
            (0, 3, 0),
        ]
        for i, (dx, dy, dz) in enumerate(offsets):
            spline.fitPoints.item(i + 1).move(core.Vector3D.create(dx, dy, dz))

        # Refresh the viewport and notify that control points were moved
        adsk.doEvents()
        app.activeViewport.refresh()
        ui.messageBox("Spline control points 2, 3, 4 moved.")

        # Recompute all features to update joint positions after moving spline control points
        des.computeAll()
        ui.messageBox("Computing all features to update component positions...")


    except Exception:
        if ui:
            ui.messageBox("Failed:\n{}".format(traceback.format_exc()))


def add_cylinder_component(
    root: fusion.Component,
    spline: fusion.SketchFittedSpline,
    fit_pt_idx: int,
) -&amp;gt; fusion.Joint:
    """Create a cylinder component and rigidly joint it to a spline fit point."""
    occ: fusion.Occurrence = root.occurrences.addNewComponent(core.Matrix3D.create())
    occ.isGroundToParent = False
    comp: fusion.Component = occ.component

    cyl_skt: fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane)
    cyl_skt.sketchCurves.sketchCircles.addByCenterRadius(
        core.Point3D.create(0, 0, 0), 1.0
    )
    prof: fusion.Profile = cyl_skt.profiles.item(0)
    ext_input: fusion.ExtrudeFeatureInput = comp.features.extrudeFeatures.createInput(
        prof, fusion.FeatureOperations.NewBodyFeatureOperation
    )
    ext_input.setDistanceExtent(False, core.ValueInput.createByReal(2.0))
    comp.features.extrudeFeatures.add(ext_input)

    fit_pt: fusion.SketchPoint = spline.fitPoints.item(fit_pt_idx)
    geo1: fusion.JointGeometry = fusion.JointGeometry.createByPoint(comp.originConstructionPoint)
    geo2: fusion.JointGeometry = fusion.JointGeometry.createByPoint(fit_pt)
    joint_input: fusion.JointInput = root.joints.createInput(geo1, geo2)
    joint_input.setAsRigidJointMotion()
    return root.joints.add(joint_input)
&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 21 May 2026 08:31:09 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2026-05-21T08:31:09Z</dc:date>
    <item>
      <title>Moving assembly components with an API script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-assembly-components-with-an-api-script/m-p/14136321#M22801</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am creating a biomimetic tail in Fusion360, and I want to model the motion of a cable passing through the ends of the tail segments.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have printed the tail out using TPU have constrained it to create a helical shape. I want to model this helical shape using Fusion's API, and I have written an AI-assisted code to demonstrate that the math works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Primary Issue:&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;When the script is run, there is a new sketch created that models the mathematical motion I wanted, however none of the segments in the assembly move with the points. I have suppressed all constraints and joints before running the script, but I have not placed all of the segments at one origin.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions on how to get the pieces to move according to the API script?&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2026 17:07:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-assembly-components-with-an-api-script/m-p/14136321#M22801</guid>
      <dc:creator>greenmica</dc:creator>
      <dc:date>2026-05-20T17:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Moving assembly components with an API script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-assembly-components-with-an-api-script/m-p/14137168#M22803</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/18995438"&gt;@greenmica&lt;/a&gt;&amp;nbsp;-san.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;If possible, I would have liked to see a sample.&lt;/P&gt;
&lt;P&gt;I think calling `fusion.Design.computeAll` will solve the problem.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        # Create a new document with parametric (hybrid) design mode
        app.documents.add(core.DocumentTypes.FusionDesignDocumentType)
        des: fusion.Design = app.activeProduct
        des.designType = fusion.DesignTypes.ParametricDesignType
        root: fusion.Component = des.rootComponent

        # Create a sketch on the XY plane
        skt: fusion.Sketch = root.sketches.add(root.xYConstructionPlane)

        # Add 5 control points and create a fitted spline
        pts: core.ObjectCollection = core.ObjectCollection.create()
        pts.add(core.Point3D.create(-5, 0, 0))
        pts.add(core.Point3D.create(2, 3, 0))
        pts.add(core.Point3D.create(4, 1, 0))
        pts.add(core.Point3D.create(6, 4, 0))
        pts.add(core.Point3D.create(8, 0, 0))
        spline: fusion.SketchFittedSpline = skt.sketchCurves.sketchFittedSplines.add(pts)

        # Create cylinder components jointed to control points 2, 3, 4 (index 1, 2, 3)
        add_cylinder_component(root, spline, 1)
        add_cylinder_component(root, spline, 2)
        add_cylinder_component(root, spline, 3)

        # Refresh the viewport and notify that components were created
        adsk.doEvents()
        app.activeViewport.refresh()
        ui.messageBox("3 cylinder components created and jointed to control points 2, 3, 4.")

        # Move spline control points 2, 3, 4
        offsets: list[tuple[float, float, float]] = [
            (0, 3, 0),
            (0, -3, 0),
            (0, 3, 0),
        ]
        for i, (dx, dy, dz) in enumerate(offsets):
            spline.fitPoints.item(i + 1).move(core.Vector3D.create(dx, dy, dz))

        # Refresh the viewport and notify that control points were moved
        adsk.doEvents()
        app.activeViewport.refresh()
        ui.messageBox("Spline control points 2, 3, 4 moved.")

        # Recompute all features to update joint positions after moving spline control points
        des.computeAll()
        ui.messageBox("Computing all features to update component positions...")


    except Exception:
        if ui:
            ui.messageBox("Failed:\n{}".format(traceback.format_exc()))


def add_cylinder_component(
    root: fusion.Component,
    spline: fusion.SketchFittedSpline,
    fit_pt_idx: int,
) -&amp;gt; fusion.Joint:
    """Create a cylinder component and rigidly joint it to a spline fit point."""
    occ: fusion.Occurrence = root.occurrences.addNewComponent(core.Matrix3D.create())
    occ.isGroundToParent = False
    comp: fusion.Component = occ.component

    cyl_skt: fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane)
    cyl_skt.sketchCurves.sketchCircles.addByCenterRadius(
        core.Point3D.create(0, 0, 0), 1.0
    )
    prof: fusion.Profile = cyl_skt.profiles.item(0)
    ext_input: fusion.ExtrudeFeatureInput = comp.features.extrudeFeatures.createInput(
        prof, fusion.FeatureOperations.NewBodyFeatureOperation
    )
    ext_input.setDistanceExtent(False, core.ValueInput.createByReal(2.0))
    comp.features.extrudeFeatures.add(ext_input)

    fit_pt: fusion.SketchPoint = spline.fitPoints.item(fit_pt_idx)
    geo1: fusion.JointGeometry = fusion.JointGeometry.createByPoint(comp.originConstructionPoint)
    geo2: fusion.JointGeometry = fusion.JointGeometry.createByPoint(fit_pt)
    joint_input: fusion.JointInput = root.joints.createInput(geo1, geo2)
    joint_input.setAsRigidJointMotion()
    return root.joints.add(joint_input)
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 21 May 2026 08:31:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-assembly-components-with-an-api-script/m-p/14137168#M22803</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2026-05-21T08:31:09Z</dc:date>
    </item>
  </channel>
</rss>

