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: 

Activate a folder in the CAM environment

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Joshua.mursic
206 Views, 2 Replies

Activate a folder in the CAM environment

Hello,

 

I am really struggling with the lack of functionality of the CAM API.

 

I have created a library inside of Fusion with several projects that have different geometries and CAM Setups saved inside of them. I have been able to open these documents and import in the CAD models easily, but have been unable to grab objects from the CAM environment. 

 

I have tried to save the CAM setups as Templates and then import them into the new project with some success, but I need to import the templates into a specific folder in the new projects new setup, and I do not see any functionality to activate a folder to do this. 

 

cam.setups.item(0).folders.item(0).isSelected = True

 

This does not work as the 'isSelected' property appears to be read only.

 

I have also tried to open the template document and using text commands, have been able to copy the entire Setup, including folders and toolpaths. However when I navigate over to the new project, I have no way of selecting the RootSetup so that I could use a text command to paste the copied Template.

 

 

# Targets and copies the first setup in the template document
template = app.documents.open(TEMPLATE_DATAFILE,False).products.itemByProductType('CAMProductType')
templateCam = adsk.cam.CAM.cast(template)
templateCam.setups.item(0)
app.executeTextCommand('Commands.Start IronCopy')

# Reactivate the CAM enviroment in new document
app.documents.open(NEW_DOC_DATAFILE,True).activate()
ui.workspaces.itemById("CAMEnvironment").activate()
camProduct = app.activeDocument.products.itemByProductType('CAMProductType')
cam = adsk.cam.CAM.cast(camProduct)
setups = cam.setups

# Trying to paste to copied Setup but 'cam.setups'
# does not target the setups  object in the ui and thus
# the paste does nothing.
app.executeTextCommand('Commands.Start IronPasteCommand')

 

 

 

are there any text commands to select items in the UI? like the image below

Joshuamursic_2-1673971647708.png

 

Lastly I tried to use the API and text commands to create a new setup from scratch, but I still ran into the problem where I could not target a newly created folder. I used the text command:

 

app.executeTextCommand('Commands.Start IronFolder')

 

to create a new folder but the new folder is not the active object, and so when I create or insert toolpaths using templates, the instead fall under the Setup on the same level as the Folder, and I instead need them inside the folder.

Joshuamursic_3-1673972890500.png

 

Thanks in advance for any insight.

Kind regards,

Josh

 

 

 

 

 

2 REPLIES 2
Message 2 of 3
kandennti
in reply to: Joshua.mursic

Hi @Joshua.mursic .

 

You can choose to use "ONK" as described here.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/can-we-select-a-setup-programmatically/m-p... 


Can't you select it this way?

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core
import adsk.cam
from urllib.parse import quote

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

        # ObjectPaths.Onk
        onk = u'ONK::CmpInst={}/Cmp={}/{}/'.format(
            quote(doc.name),
            quote(doc.name),
            'Setups=1')

        app.log(onk)

        # select setups
        app.executeTextCommand(u'Commands.Select {}'.format(onk))

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

 

To check the "ONK", select the element to be checked in advance and use this command from the add-in I have created and published, which will be output to a text command window.

https://github.com/kantoku-code/Fusion360_Developers_Small_ToolKit 

1.png

Message 3 of 3
Joshua.mursic
in reply to: kandennti

Amazing! Thank you so much @kandennti, I have learned so much from your posts. That is working perfectly.

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