Is it possible to create setups and operations?

anthony.a.douglas
Enthusiast

Is it possible to create setups and operations?

anthony.a.douglas
Enthusiast
Enthusiast

I am trying to determine how to create new setups and operations, but I cannot see how from the reference manual.  Is it not possible or something? That would be disappointing and bizarre, I thought the theory was you could do anything through the api that the user can do.

0 Likes
Reply
801 Views
10 Replies
Replies (10)

kandennti
Mentor
Mentor

Hi @anthony.a.douglas .

 

After slightly modifying this sample, I was able to create a setup.

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-AEF0708D-B657-4E9F-9032-4535E0D1C417 

#Fusion360API Python script
import adsk.core, adsk.cam, os, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        doc = app.activeDocument
        products = doc.products
        # Get the CAM product
        cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))

        # List of all setups
        setups = cam.setups

        # Specify the full filename of the template.
        templateFilename = 'c:\\tmp\\face.f3dhsm-template'
        
        # Check if the template exists (from the path specified above). Show an error if it doesn't exist.
        if not os.path.exists(templateFilename):
            ui.messageBox("The template '" + templateFilename + "' does not exist")
            return

        # Create CAM Setup
        txtCmds = [
            u'Commands.Start IronSetup',
            u'NuCommands.CommitCmd'
        ]
        [app.executeTextCommand(cmd) for cmd in txtCmds]

        # setup = setups[-1] #ver2.0.9305 NG
        setup = setups[setups.count -1]
        
        # Add the template
        results = setup.createFromTemplate(templateFilename)
        operation = results.item(0)
        operation.name = "API added operation"
        cam.generateAllToolpaths(True)

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

 

Toolpath operation seems to only allow you to insert templates.
I think the cause is that the API does not provide a way to access the tool library.

0 Likes

damien.huvelle
Enthusiast
Enthusiast

@kandennti trying your script on my computer but it does nothing after changing the template path in the script ... without changing anything it does says "template does not exist ...

trying to access the template from the cloud library and found the cloud folder on my computer but when I put this file path in the script nothing happens ...

 

any ideas ?

 

thanks

0 Likes

damien.huvelle
Enthusiast
Enthusiast

still nothing ...

0 Likes

BrianEkins
Mentor
Mentor

I copied the program to create a new script and downloaded the xml template.  I modified the script so the path to the xml file was correct.  Next, in a design that contains a model, I created a new setup.  Finally, I ran the script and ended up with a new toolpath.  Where is it failing for you?

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

damien.huvelle
Enthusiast
Enthusiast

@BrianEkins 

hi, 

after several try, I've been able to run the script succefully but only with the template file in the "C:\" directory ... If I put it somewhere else and modify the path in the script it doesn't work ... But I'm familiar with keeping everything on the cloud of fusion360 because I work on 2 PC's.

 

any Idea why it doesn't work this way ?

0 Likes

kandennti
Mentor
Mentor

@damien.huvelle .

 

The cloud is Google Drive etc, isn't it?
The path settings may be incorrect.

 

I'm using OneDrive and it worked fine this way as well.(Win10)

templateFilename = r'C:\Users\<username>\OneDrive\temp\face.f3dhsm-template'

 

One idea, but why not put the f3dhsm-template file in the script folder?

ใƒปใƒปใƒป
        import pathlib
        templateFile = 'face.f3dhsm-template'
        
        scriptFolder = pathlib.Path(__file__).resolve().parent
        templateFolder = scriptFolder / 'template'
        templateFilename = str(templateFolder / templateFile)
ใƒปใƒปใƒป

I think it's easier to manage if the related files are in the same folder.

0 Likes

BrianEkins
Mentor
Mentor

I'm guessing you've gotten caught with how Python treats the backslash.  It uses it as a special character so a path like "C:\Users\Brian\test.xml" won't work.  You can either use forward slashes instead or use "C:\\Users\\Brian\\test.xml".  In the latter case, the double backslash is treated as a single backslash.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

damien.huvelle
Enthusiast
Enthusiast

@BrianEkins @kandennti 

Yes it works like it should now ! thanks a lot !!

 

Wish i could have this knowledge ... lots of ideas are coming to me when I see the potential of those scripts ... is there a easy way to begin scripting ? what are the basics ? where to start ?

 

would like to "pimp" this script to automatically create a setup for each component of the design (auto name it the way the component is named, like one of those Brian's script does) and assign a template (wich is done!). maybe some other stuff would be added too

0 Likes

anthony.a.douglas
Enthusiast
Enthusiast

Whoa, so I guess it is possible to create a setup and a toolpath template, but not a complete toolpath with a tool, but you can make a template which has a tool included, and use that?  I know some python, but still I cannot understand how exactly that code works.  Maybe a thorough read of the cam api documentation would make it more clear...

0 Likes