How to create a Coil feature?

How to create a Coil feature?

jphalip
Enthusiast Enthusiast
710 Views
3 Replies
Message 1 of 4

How to create a Coil feature?

jphalip
Enthusiast
Enthusiast

Hi,

 

I can't seem to figure out how to create a coil feature using the Python API. Looking at the documentation (https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-1a25f536-6aa0-437f-b8ba-79beff4e1877), the "CoilFeatures object [...] supports the ability to create new coil features". However, I'm not seeing any method to actually create a new coil.

 

Do you have any tips on how to do this?

 

Thank you,

 

Julien

0 Likes
Accepted solutions (1)
711 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor
Accepted solution

Hi @jphalip .

 

Primitives, including coils, are provided with objects, but the API does not seem to provide a way to create them.

Instead, I tried to create them using text commands.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core
import math

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        coilFeat: adsk.fusion.CoilFeature = create_coil(
            root,
            adsk.core.Point3D.create(2, 1, 0),
            1.0,
            4.0,
            3.0,
            15.0,
            0.5
        )

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def create_coil(
    comp: adsk.fusion.Component,
    center: adsk.core.Point3D,
    coilDiameter: float,
    coilRevolutions: float,
    coilHeight: float,
    coilTaperAngle_deg: float,
    sectionSize: float):

    skt: adsk.fusion.Sketch = comp.sketches.add(
        comp.xYConstructionPlane
    )
    sktCircles: adsk.fusion.SketchCircles = skt.sketchCurves.sketchCircles

    circle: adsk.fusion.SketchCircle = sktCircles.addByCenterRadius(
        center,
        coilDiameter * 0.5
    )

    comp: adsk.fusion.Component = circle.parentSketch.parentComponent

    app: adsk.core.Application = adsk.core.Application.get()
    ui: adsk.core.UserInterface = app.userInterface

    sels: adsk.core.Selections = ui.activeSelections
    sels.clear()
    sels.add(circle)

    app.executeTextCommand(u'Commands.Start Coil')
    app.executeTextCommand(u'Commands.SetString infoSizeType infoRevolutionAndHeight')
    app.executeTextCommand(u'Commands.SetDouble CoilRevolutions {}'.format(coilRevolutions))
    app.executeTextCommand(u'Commands.SetDouble CoilHeight {}'.format(coilHeight))
    app.executeTextCommand(u'Commands.SetDouble CoilTaperAngle {}'.format(math.radians(coilTaperAngle_deg)))
    app.executeTextCommand(u'Commands.SetString infoSectionType infoCircular')
    app.executeTextCommand(u'Commands.SetString infoSectionPosition infoOutside')
    app.executeTextCommand(u'Commands.SetDouble SectionSize {}'.format(sectionSize))
    app.executeTextCommand(u'Commands.SetString infoBooleanType infoNewBodyType')
    app.executeTextCommand(u'NuCommands.CommitCmd')

    skt.deleteMe()

    return comp.features.coilFeatures[-1]

 

After executing the script, it looks like this.

1.png

 

For more information about text commands, please read here.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands/m-p/9645688 

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands2/m-p/9937161 

Message 3 of 4

jphalip
Enthusiast
Enthusiast

Thank you so much @kandennti, this is perfect!

 

One question, how can I figure out what values to use I want to change the drop-down options like infoBooleanType, infoSectionPosition, and infoSectionType?

Message 4 of 4

jphalip
Enthusiast
Enthusiast

@kandennti Actually, nevermind, I found that this command gives all the available options: "Toolkit.cmdDialog"