Change workspace

Change workspace

dinocoglitore
Advocate Advocate
1,445 Views
3 Replies
Message 1 of 4

Change workspace

dinocoglitore
Advocate
Advocate

Hi all,

I'm looking for APIs that help me to change the workspace from Model to Render.

I found in the forum an example to view all the Environments and I add two line to change the workspace (in my mind...) but nothing append.

 

import adsk.core, adsk.fusion, adsk.cam, traceback

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

        print("\n\n")
        for workspace in ui.workspaces:
            print(workspace.id)
            
        ui.workspaces.id = "FusionRenderEnvironment"    
        ui.workspaces.itemById = "FusionRenderEnvironment"    

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

Someone can help me ?

Thank you 

Dino

0 Likes
Accepted solutions (1)
1,446 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni
Accepted solution

The Workspaces object provides access to all of the existing workspaces.  The item and itemById methods provide a way to access the contents of the collection but they are functions that return a value and can't be used to set the workspace.  You do that on the Workspace object.  The code below will do it.

 

renderWS = ui.workspaces.itemById("FusionRenderEnvironment")
renderWS.activate()

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 4

dinocoglitore
Advocate
Advocate

Hi Brian.

Thank you very much.

Dino

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hi,

 

I want to create add-in python script which aims at exporting mesh of my geometry in VTK format. For this, my script needs to open the simulation environment workspace (script add-ins are runnable only in FusionSolidEnvironment workspace)

I wrote the following code

 

import adsk.core, adsk.fusion, tempfile, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = app.activeProduct
        # Get the ExportManager from the active design.
        exportMgr = design.exportManager
        
        tmpDir = tempfile.gettempdir()
        
        # Create an STEPExportOptions object and do the export.
        stepOptions = exportMgr.createSTEPExportOptions('C:/Users/rrochefort/Documents/Python_Scripts/test.stp')
        res = exportMgr.execute(stepOptions)

        # Create vtu
        renderWS = ui.workspaces.itemById("SimulationEnvironment")
		renderWS.activate()
        app.executeTextCommand(u'SimMeshDB.Export  0  C:/Users/rrochefort/Documents/Python_Scripts/my_mesh.vtu')

When I run this script, nothing happens, and I get no error message

I think the problem is that scripts are only runnable in FusionSolidEnvironment workspace.

Could you help me please on this problem ? How can I automate the exporting of my mesh ?

 

Thanks

 

0 Likes