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: 

Can we select a Setup programmatically?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
vijay.shindeSLE5F
365 Views, 3 Replies

Can we select a Setup programmatically?

Is there any API to select a Setup so that it's reflected in view and also in browser?

We need this to trigger command 'IronEditOperation' for the Setup which is active. 

We have confirmed in C++ add-in that if a setup which is active but not selected then TextCommand "Commands.Start IronEditOperation" fails with error "No operation is selected".

Error.PNG

We tried adding the active Setup in activeSelections but it doesn't resolve the error.

 

@BrianEkins @MattWynn can you please help us with this?

3 REPLIES 3
Message 2 of 4

Hi @vijay.shindeSLE5F .

 

I have tried to select CAM elements in the past, but I could not find a way to select them.

Message 3 of 4

I have no experience in what you want to do

Matt Wynn
Senior Manager, Software Development, Fusion Fabrication
Message 4 of 4
kandennti
in reply to: kandennti

@vijay.shindeSLE5F .

 

It will be python, but I'll describe what I know.

 

I know that there are two ways to select other than activeSelections, in the case of text commands.

 

The first is to use "Selections.Add".
https://github.com/kantoku-code/Fusion360_Small_Tools_for_Developers/blob/master/TextCommands/TextCo... 

 

The argument "Paths" can be found in "Selections.List". The method is described here.
https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands2/m-p/9937161 

 

Unfortunately, CAM Setup cannot get the correct "Paths" in "Selections.List".

1.png

 

 

The other way is to use "Commands.Select".
https://github.com/kantoku-code/Fusion360_Small_Tools_for_Developers/blob/master/TextCommands/TextCo... 
The "ONK" argument can be found in "ObjectPaths.Onk".
2.png

 

I don't know much about "ONK", but I have created a sample.

# 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"))

        # target setup
        setup = cam.setups[0]

        # ObjectPaths.Onk
        onk = u'ONK::CmpInst={}/Cmp={}/{}/{}={}'.format(
            quote(doc.name),
            quote(doc.name),
            'Setups=1', #This depends on the language in which the document was created.
            setup.name,
            setup.operationId)

        app.log(onk)

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

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

It is possible to select some of them, but it may result in an error.

 

The error occurs if the document name contains spaces or other characters.
Therefore, it may need to be URL-encoded.

 

The 'Setups=1' part seems to depend on the language used when the document was created or when CAM was first used, and I haven't found a way to check this.

 

 

The only way to use the TextCommands is to try it patiently anyway.

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

Post to forums