API for Auto Explode View feature

API for Auto Explode View feature

Anonymous
Not applicable
1,145 Views
7 Replies
Message 1 of 8

API for Auto Explode View feature

Anonymous
Not applicable

Hi Fusion 360 users, 

I have a bunch of 3D models, and I want to save the auto exploded view videos of these models. Currently I am doing this task manually. Is there a way to automate this process using fusion 360 API ?

Is there an API to access the Animation > Auto Explode view feature in fusion 360?

 

Thanks in advance.

0 Likes
1,146 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

I didn't find any direct API in fusion360 that can auto explode a 3D model.

As I am new to Fusion 360, I don't know whether we can trigger task panels' action using the APIs; in my case, it is Animation Workspace -> Transform -> AutoExplode: All levels.

 

As there are already samples and defined procedures available for design steps using API, I didn't find any sample programs to automate other features of fusion 360 using APIs, like the one I pointed above.

 

Any help is much appreciated.

0 Likes
Message 3 of 8

BrianEkins
Mentor
Mentor

Unfortunately, the API does not have full coverage of all of Fusion's functionality.  Currently, there is not any of the functionality in the Animation workspace available through the API.

 

It is possible through the API to execute ANY command in Fusion.  But that's all you can do is execute it, which is the equivalent of clicking the command button in the UI.  For the Explode command, when it is executed, you still need to interact with the command to control the explosion.  That's not possible.  I don't know of any workaround other than to write code that will do the same thing as the Explode command.  It is possible to move occurrences around in an assembly, but re-working all of the logic that the command has would not be trivial and is a bit frustrating since it's already there.

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

Anonymous
Not applicable

Thanks for the reply, @BrianEkins.

Let me elaborate you, what I want to accomplish,

1. load a step file containing a 3D model. (done)

 

2. Select a component from the active model.

2018csb1080_1-1617691200933.png

 

3. Select the auto explode feature from the animation workspace.

2018csb1080_0-1617691099273.png

 

4. Select sequential explosion with default exploding space.

2018csb1080_4-1617691403184.png

 

5. After performing the above steps using APIs, can I access the animation timeline at this stage?

Also, can I access the response of the timeline after changes, like moving the cursor of the timeline, either through APIs or the user interface?

2018csb1080_0-1617694272527.png

 

The 3D model used above is available here.

 

Could you please tell me whether the above steps can be executed with the APIs? If so, could you please provide some example scripts to execute the actions for such a task?

0 Likes
Message 5 of 8

Anonymous
Not applicable

Hi,

Can anyone please let me know that whether the above-stated steps could be executed using APIs infusion 360? I went through the documentation of APIs and I didn't find how to execute the actions of fusion 360's predefined operations through some events, like in my case how can I execute the Auto explode operation through some events.

I've stuck here for quite some time.

 

Thanks in advance.

0 Likes
Message 6 of 8

kandennti
Mentor
Mentor

Hi @Anonymous .

 

I tried a few things.

In order to run Auto Explode, I had to select a component, but I couldn't find a way to select it.

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

ANIMATION_WS = 'Publisher3DEnvironment'

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

        # Switch to Animation WS
        if ui.activeWorkspace.id != ANIMATION_WS:
            ui.workspaces.itemById(ANIMATION_WS).activate()

        # Now we need to make the root component selected, but we cannot find a way to select it.
        app.executeTextCommand(u'Commands.Start PublisherExplodeAllPartsCommand')
        app.executeTextCommand(u'NuCommands.CommitCmd')

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

I think it is difficult to make this happen.

0 Likes
Message 7 of 8

BrianEkins
Mentor
Mentor

It's not currently possible because Fusion doesn't expose any of the Animation capabilities through the API.

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

kandennti
Mentor
Mentor

@Anonymous .

 

When I tried it with some data I have, I was able to Auto Explode it.

 

 

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

ANIMATION_WS = 'Publisher3DEnvironment'

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

        # Switch to Animation WS
        if ui.activeWorkspace.id != ANIMATION_WS:
            ui.workspaces.itemById(ANIMATION_WS).activate()

        # select root component
        selectRootComp()

        # exec Auto Explode
        app.executeTextCommand(u'Commands.Start PublisherExplodeAllPartsCommand')
        app.executeTextCommand(u'NuCommands.CommitCmd')

        ui.activeSelections.clear()

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


def selectRootComp():
    app = adsk.core.Application.get()

    compDataTxt = app.executeTextCommand('ComponentData.ListInstances')
    id = int(compDataTxt.split('EntityId:')[-1])

    ids = [id]
    while True:
        infoJson = json.loads(app.executeTextCommand(
            f'Managed.Parent {id}'))
        id = infoJson['entityId']

        if id < 1:
            break
        ids.append(id)
    
    path = ":".join([str(id) for id in ids[::-1]])
    app.executeTextCommand(f'Selections.Add {path}')

I am not sure if it always works.
Also, I have no clue how to modify the animation timeline, so I can't think of anything better to do.