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: 

Create new CAM setups

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
494 Views, 5 Replies

Create new CAM setups

I have written a script that runs after a documentOpened event triggers. The trigger takes an existing f3d file that has an empty default setup, populates its parameters, runs toolpath generation, postprocessing, and finally exports a .nc file.

My one issue is that I prefer importing .stl files which can not encode a setup. Therefore, I have to create an empty .f3d file, export it, then use that when triggering the script.

 

I know the CAM API is currently being worked on. I wanted to ask if it's possible to create a new setup, associate it with the stl file, and do all of the processing without having to go through manually creating a setup.

I feel like this should be easily achievable. If the devs are willing to give open-source access to that part of the inner workings instead of updating that specific part of the API it would be great too; I can add on to the existing Python API.

5 REPLIES 5
Message 2 of 6
kandennti
in reply to: Anonymous

Hi @Anonymous .

 

I tried it.

I was able to import the STL, create a setup, and set up the body, but I didn't think it was practical.

 

# Fusion360API Python script
import adsk.core, adsk.fusion, adsk.cam, traceback
import pathlib

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des :adsk.fusion.Design = app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # stl file name
        stls = [
            'test1.stl',
            'test2.stl'
        ]

        # import stl
        folder = pathlib.Path(__file__).resolve().parent
        for stl in stls:
            path = folder / 'stl' / stl
            app.executeTextCommand(f'NaFusionUI.ImportCmd {path}')

        # change work space
        camWs :adsk.core.Workspace = ui.workspaces.itemById('CAMEnvironment')
        camWs.activate()

        # get cam
        doc = app.activeDocument
        products = doc.products
        cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))

        # create setup & setting meshbody
        for mesh in root.meshBodies:
            initSetup(mesh)

            # Change stock mode
            setup = cam.setups[-1]
            prmStockMode = setup.parameters.itemByName('job_stockMode')
            prmStockMode.expression = "'fixedbox'" 
            # prmStockMode.expression = "(job_type == 'turning') ? 'fixedcylinder' : 'default'" # NG

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

def initSetup(body):
    app = adsk.core.Application.get()
    ui = app.userInterface

    # create setup
    app.executeTextCommand(u'Commands.Start IronSetup')

    # focus select body
    app.executeTextCommand(u'UI.EnableCommandInput job_model')

    # select body
    sels = ui.activeSelections
    sels.clear()
    sels.add(body)

    # ok button
    app.executeTextCommand(u'NuCommands.CommitCmd')


def importSTL(path):
    app = adsk.core.Application.get()
    app.executeTextCommand(f'NaFusionUI.ImportCmd {path}')

 

 

 

I did a test with the attached data.

Message 3 of 6
Anonymous
in reply to: kandennti

Thank you for the reply! I'll try it out and let you know if it works out. Why do you think this is impractical? Also where do I get the commands for 

app.executeTextCommand

I couldn't find the list of commands in the API documentation.

Message 4 of 6
kandennti
in reply to: Anonymous

@Anonymous .

 

For more information about TextCommands, see 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 

 

 

For a list of commands, the older ones can be found here.

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

 

 

For a more up-to-date list, run the following in TextCommand(TXT)

TextCommands.List /hidden

 

Message 5 of 6
BrianEkins
in reply to: kandennti

Some details about text commands.  Developers will add sometimes add those to aid in their initial development or testing of some functionality.  There's no guarantee they'll continue to work or be available in the future.  As a result, they are not supported in any way.  If you're writing something for yourself and find a text command to work around a limitation with the API, that's probably a good use of a text command but I would never want to deliver a product to others that depends on a text command.

 

I also wish that CAM would provide some additional functionality in the API.  It would be great to be able to automate the design and the manufacturing.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 6
Anonymous
in reply to: Anonymous

Thank you for the clarification! The Text Commands are my way to go for now until the API allows creating setups!

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report