<?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: Creating custom threads using Sweeps or other tools in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-custom-threads-using-sweeps-or-other-tools/m-p/11768764#M4350</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10351190"&gt;@jphalip&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The numbers are appropriate, but I made a sample.&lt;/P&gt;
&lt;P&gt;The helix uses the TemporaryBRepManager.createHelixWire method.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-19CBF605-BB13-4FB6-84CC-F92C0CC7F3BE" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-19CBF605-BB13-4FB6-84CC-F92C0CC7F3BE&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        exec_sample()
        app.activeViewport.refresh()

        ui.messageBox('Done')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def exec_sample():
    app: core.Application = core.Application.get()
    des: fusion.Design = app.activeProduct
    root: fusion.Component = des.rootComponent

    helix: fusion.SketchFixedSpline = create_helix(
        root,
        core.Point3D.create(0.0,0),
        core.Vector3D.create(0,0,1),
        core.Point3D.create(2,0,0),
        1,
        5,
        0,
    )

    sktPlane: fusion.ConstructionPlane = create_plane(root, helix)

    guideRail: fusion.SketchFixedSpline = create_helix(
        root,
        core.Point3D.create(0,0,0),
        core.Vector3D.create(0,0,1),
        core.Point3D.create(1,0,0),
        1,
        5,
        0,
    )

    profile: fusion.Profile = create_profile_sketch(
        root,
        sktPlane,
        [
            core.Point3D.create(1,0,0),
            core.Point3D.create(-0.5,0.2,0),
            core.Point3D.create(-0.5,-0.2,0),
        ]
    )

    create_guide_rail_sweep(
        root,
        profile,
        helix,
        guideRail,
    )


def create_guide_rail_sweep(
    comp: fusion.Component,
    profile: fusion.Profile,
    pathCurve: fusion.SketchFixedSpline,
    guideCurve: fusion.SketchFixedSpline,
) -&amp;gt; fusion.SweepFeature:

    path: fusion.Path = fusion.Path.create(
        pathCurve,
        fusion.ChainedCurveOptions.noChainedCurves
    )

    guide: fusion.Path = fusion.Path.create(
        guideCurve,
        fusion.ChainedCurveOptions.noChainedCurves
    )

    sweepFeats: fusion.SweepFeatures = comp.features.sweepFeatures
    sweepIpt: fusion.SweepFeatureInput = sweepFeats.createInput(
        profile,
        path,
        fusion.FeatureOperations.NewBodyFeatureOperation
    )
    sweepIpt.guideRail = guide

    return sweepFeats.add(sweepIpt)


def create_profile_sketch(
    comp: fusion.Component,
    plane: fusion.ConstructionPlane,
    pointList: list,
) -&amp;gt; fusion.Profile:

    skt: fusion.Sketch = comp.sketches.add(plane)
    skt.isLightBulbOn = False

    points: fusion.SketchPoints = skt.sketchPoints
    sktPnts = [points.add(p) for p in pointList]
    sktPnts.append(sktPnts[0])

    sktLines: fusion.SketchLines = skt.sketchCurves.sketchLines
    for p1, p2 in zip(sktPnts, sktPnts[1:]):
        sktLines.addByTwoPoints(p1, p2)

    return skt.profiles[0]


def create_plane(
    comp: fusion.Component,
    curve: fusion.SketchFixedSpline,
) -&amp;gt; fusion.ConstructionPlane:

    path: fusion.Path = fusion.Path.create(
        curve,
        fusion.ChainedCurveOptions.noChainedCurves
    )

    planes: fusion.ConstructionPlanes = comp.constructionPlanes
    planeIpt: fusion.ConstructionPlaneInput = planes.createInput()
    planeIpt.setByDistanceOnPath(
        path,
        core.ValueInput.createByReal(0),
    )

    plane: fusion.ConstructionPlane = planes.add(planeIpt)
    plane.isLightBulbOn = False

    return plane

def create_helix(
    comp: fusion.Component,
    axisPoint: core.Point3D,
    axisVector: core.Vector3D, 
    startPoint: core.Point3D, 
    pitch: float, 
    turns: float, 
    taperAngle: float,
) -&amp;gt; fusion.SketchFixedSpline:

    tmpMgr: fusion.TemporaryBRepManager=fusion.TemporaryBRepManager.get()
    helixWireBody: fusion.BRepBody = tmpMgr.createHelixWire(
        axisPoint,
        axisVector,
        startPoint,
        pitch, 
        turns, 
        taperAngle,
    )

    skt: fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane)
    skt.isLightBulbOn = False
    sktFixeds: fusion.SketchFixedSplines = skt.sketchCurves.sketchFixedSplines

    return sktFixeds.addByNurbsCurve(helixWireBody.wires[0].edges[0].geometry)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is indeed cumbersome.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Feb 2023 02:55:52 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2023-02-21T02:55:52Z</dc:date>
    <item>
      <title>Creating custom threads using Sweeps or other tools</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-custom-threads-using-sweeps-or-other-tools/m-p/11768412#M4349</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to write a script that creates custom, non-standard threads. I believe the common tool for that is the Coil. However, I've learned from &lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/creating-a-custom-command-dialog-then-running-a-text-command/m-p/11664690#M18017" target="_blank" rel="noopener"&gt;past experience&lt;/A&gt; that Coils can only be controlled in scripts via Text Commands, which can lead to some issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I was thinking perhaps the Sweep tool could be used instead? Do you think that would be possible, and if so, do you have any tips on how to do it? Or should I consider a different tool altogether?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Julien&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 22:12:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-custom-threads-using-sweeps-or-other-tools/m-p/11768412#M4349</guid>
      <dc:creator>jphalip</dc:creator>
      <dc:date>2023-02-20T22:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom threads using Sweeps or other tools</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-custom-threads-using-sweeps-or-other-tools/m-p/11768764#M4350</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10351190"&gt;@jphalip&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The numbers are appropriate, but I made a sample.&lt;/P&gt;
&lt;P&gt;The helix uses the TemporaryBRepManager.createHelixWire method.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-19CBF605-BB13-4FB6-84CC-F92C0CC7F3BE" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-19CBF605-BB13-4FB6-84CC-F92C0CC7F3BE&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        exec_sample()
        app.activeViewport.refresh()

        ui.messageBox('Done')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def exec_sample():
    app: core.Application = core.Application.get()
    des: fusion.Design = app.activeProduct
    root: fusion.Component = des.rootComponent

    helix: fusion.SketchFixedSpline = create_helix(
        root,
        core.Point3D.create(0.0,0),
        core.Vector3D.create(0,0,1),
        core.Point3D.create(2,0,0),
        1,
        5,
        0,
    )

    sktPlane: fusion.ConstructionPlane = create_plane(root, helix)

    guideRail: fusion.SketchFixedSpline = create_helix(
        root,
        core.Point3D.create(0,0,0),
        core.Vector3D.create(0,0,1),
        core.Point3D.create(1,0,0),
        1,
        5,
        0,
    )

    profile: fusion.Profile = create_profile_sketch(
        root,
        sktPlane,
        [
            core.Point3D.create(1,0,0),
            core.Point3D.create(-0.5,0.2,0),
            core.Point3D.create(-0.5,-0.2,0),
        ]
    )

    create_guide_rail_sweep(
        root,
        profile,
        helix,
        guideRail,
    )


def create_guide_rail_sweep(
    comp: fusion.Component,
    profile: fusion.Profile,
    pathCurve: fusion.SketchFixedSpline,
    guideCurve: fusion.SketchFixedSpline,
) -&amp;gt; fusion.SweepFeature:

    path: fusion.Path = fusion.Path.create(
        pathCurve,
        fusion.ChainedCurveOptions.noChainedCurves
    )

    guide: fusion.Path = fusion.Path.create(
        guideCurve,
        fusion.ChainedCurveOptions.noChainedCurves
    )

    sweepFeats: fusion.SweepFeatures = comp.features.sweepFeatures
    sweepIpt: fusion.SweepFeatureInput = sweepFeats.createInput(
        profile,
        path,
        fusion.FeatureOperations.NewBodyFeatureOperation
    )
    sweepIpt.guideRail = guide

    return sweepFeats.add(sweepIpt)


def create_profile_sketch(
    comp: fusion.Component,
    plane: fusion.ConstructionPlane,
    pointList: list,
) -&amp;gt; fusion.Profile:

    skt: fusion.Sketch = comp.sketches.add(plane)
    skt.isLightBulbOn = False

    points: fusion.SketchPoints = skt.sketchPoints
    sktPnts = [points.add(p) for p in pointList]
    sktPnts.append(sktPnts[0])

    sktLines: fusion.SketchLines = skt.sketchCurves.sketchLines
    for p1, p2 in zip(sktPnts, sktPnts[1:]):
        sktLines.addByTwoPoints(p1, p2)

    return skt.profiles[0]


def create_plane(
    comp: fusion.Component,
    curve: fusion.SketchFixedSpline,
) -&amp;gt; fusion.ConstructionPlane:

    path: fusion.Path = fusion.Path.create(
        curve,
        fusion.ChainedCurveOptions.noChainedCurves
    )

    planes: fusion.ConstructionPlanes = comp.constructionPlanes
    planeIpt: fusion.ConstructionPlaneInput = planes.createInput()
    planeIpt.setByDistanceOnPath(
        path,
        core.ValueInput.createByReal(0),
    )

    plane: fusion.ConstructionPlane = planes.add(planeIpt)
    plane.isLightBulbOn = False

    return plane

def create_helix(
    comp: fusion.Component,
    axisPoint: core.Point3D,
    axisVector: core.Vector3D, 
    startPoint: core.Point3D, 
    pitch: float, 
    turns: float, 
    taperAngle: float,
) -&amp;gt; fusion.SketchFixedSpline:

    tmpMgr: fusion.TemporaryBRepManager=fusion.TemporaryBRepManager.get()
    helixWireBody: fusion.BRepBody = tmpMgr.createHelixWire(
        axisPoint,
        axisVector,
        startPoint,
        pitch, 
        turns, 
        taperAngle,
    )

    skt: fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane)
    skt.isLightBulbOn = False
    sktFixeds: fusion.SketchFixedSplines = skt.sketchCurves.sketchFixedSplines

    return sktFixeds.addByNurbsCurve(helixWireBody.wires[0].edges[0].geometry)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is indeed cumbersome.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 02:55:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-custom-threads-using-sweeps-or-other-tools/m-p/11768764#M4350</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-02-21T02:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating custom threads using Sweeps or other tools</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-custom-threads-using-sweeps-or-other-tools/m-p/11808503#M4351</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt;&amp;nbsp;-- thank you so much for taking the time. I haven't had a chance to try this yet, but will hopefully do so soon and report back.&lt;/P&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 23:05:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-custom-threads-using-sweeps-or-other-tools/m-p/11808503#M4351</guid>
      <dc:creator>jphalip</dc:creator>
      <dc:date>2023-03-08T23:05:44Z</dc:date>
    </item>
  </channel>
</rss>

