Creating custom threads using Sweeps or other tools

Creating custom threads using Sweeps or other tools

jphalip
Enthusiast Enthusiast
331 Views
2 Replies
Message 1 of 3

Creating custom threads using Sweeps or other tools

jphalip
Enthusiast
Enthusiast

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

0 Likes
332 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

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.

0 Likes
Message 3 of 3

jphalip
Enthusiast
Enthusiast

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.