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: 

coilFeatures

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
brad.bylls
243 Views, 6 Replies

coilFeatures

I see in the forum that the coil feature does not work in the API.

These were all dated back in 2016-2017

Has this been update?

And if so, could someone please show some code as to how to make a coil with the API?

I have a need to create springs and this would work perfectly.

Thank you.

Brad Bylls
6 REPLIES 6
Message 2 of 7
kandennti
in reply to: brad.bylls

Hi @brad.bylls .

 

I recently made a sample of a coil.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/implementing-a-feature-similar-to-coil/m-p... 

 

Make the circle of the sketch selected beforehand and run next. 

app.executeTextCommand(u'Commands.Start Coil')

Then, after setting each item, run next.

app.executeTextCommand(u'NuCommands.CommitCmd')

 

However, I have not found a way to change anything other than these items.

1.png

'Rotation', which is not mentioned in the sample over there, can be manipulated in the following way.

app.executeTextCommand(u'Commands.SetBool CoilFlipRotation <0 or 1>')

 

 

Methods for performing functions that are not provided by the API are described in this section.

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

Message 3 of 7
brad.bylls
in reply to: kandennti

Hi,

In another post you replied about using a pre-existing circle sketch which is exactly what I am trying to do.

I copied your script from my post and added your pre existing circle code and I get an error that the pre-existing circle is an "invalid argument entity"

The sketch is created with the circle.

 

#Fusion360API Python script
import adsk.core, adsk.fusion, traceback
import math

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context😞
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        product = _app.activeProduct
        design = adsk.fusion.Design.cast(product)
        occs = design.rootComponent.occurrences
        mat = adsk.core.Matrix3D.create()
        newOcc = occs.addNewComponent(mat)
        newComp = adsk.fusion.Component.cast(newOcc.component)
        sketches = newComp.sketches
        xyPlane = newComp.xYConstructionPlane
        center = adsk.core.Point3D.create(000)

        # Create the body
        bodySketch = sketches.add(xyPlane)
        bodyCircle = bodySketch.sketchCurves.sketchCircles.addByCenterRadius(center, 1 * 2.54)

        # Coil parameters
        CoilDiameter = 10
        CoilPitch = 4
        CoilHeight = 30
        SectionSize = 1
        CoilFeatureType = 2
        CoilFeatureSectionType = 1

        # wait CommandIDs
        #waitLst = ('PrimitiveCoil','CircleCenterRadius')

        # call Coil command
        #_app.executeTextCommand(u'Commands.Start PrimitiveCoil')
        _ui.activeSelections.add(bodyCircle)  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        _app.executeTextCommand(u'Commands.Start Coil')

        # wait
        while True:
            actCmd = _ui.activeCommand
            adsk.doEvents()
            if actCmd in waitLst:
                continue
            break

        # Cancel check
        if _ui.activeCommand != 'Coil':
            return

        # setting parameters
        cmds = [
            u'Commands.SetDouble SectionSize {}'.format(SectionSize),
            u'Commands.SetDouble CoilPitch {}'.format(CoilPitch),
            u'Commands.SetDouble CoilHeight {}'.format(CoilHeight),
            u'Commands.SetDouble CoilFeatureType {}'.format(CoilFeatureType)
            u'Commands.SetDouble CoilFeatureSectionType {}'.format(CoilFeatureSectionType)
        ]

        #[_app.executeTextCommand(cmd) for cmd in cmds]

        # command commit
        _app.executeTextCommand(u'NuCommands.CommitCmd')

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Brad Bylls
Message 4 of 7
kandennti
in reply to: brad.bylls

@brad.bylls .

 

I have not tried it, just looked at it a bit.

 

The most common reason for errors in Selections.Add is when the Occurrence entity is a nativeObject.

Although the content is different, I found a similar error here, so I created a sample.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/mesh-merge-feature-in-api/m-p/9940123#M121... 

 

I think you will have to use the createForAssemblyContext method.

Message 5 of 7
brad.bylls
in reply to: kandennti

Thank you for the help but not working out as planned. I will go in another direction

Brad Bylls
Message 6 of 7
kandennti
in reply to: brad.bylls

 

@brad.bylls .

 

In the case of Occurrence entities, this will work.

・・・
        # call Coil command
        #_app.executeTextCommand(u'Commands.Start PrimitiveCoil')
        # _ui.activeSelections.add(bodyCircle)  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        proxy = bodyCircle.createForAssemblyContext(newOcc)
        _ui.activeSelections.add(proxy)
        _app.executeTextCommand(u'Commands.Start Coil')
・・・

 

Message 7 of 7
brad.bylls
in reply to: kandennti

Thanks Kandennti, that worked.

Brad Bylls

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