Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating custom threads using Sweeps or other tools

2 REPLIES 2
Reply
Message 1 of 3
jphalip
130 Views, 2 Replies

Creating custom threads using Sweeps or other tools

Hi,

 

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 past experience that Coils can only be controlled in scripts via Text Commands, which can lead to some issues.

 

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?

 

Thanks,

 

Julien

2 REPLIES 2
Message 2 of 3
kandennti
in reply to: jphalip

Hi @jphalip .

 

The numbers are appropriate, but I made a sample.

The helix uses the TemporaryBRepManager.createHelixWire method.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-19CBF605-BB13-4FB6-84CC-F92C0CC7F3BE 

 

# 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,
) -> 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,
) -> 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,
) -> 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,
) -> 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)

 

It is indeed cumbersome.

Message 3 of 3
jphalip
in reply to: jphalip

Hi @kandennti -- 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.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report