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: 

Commands to change View Environment?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
ponomarevcs
442 Views, 3 Replies

Commands to change View Environment?

I'm looking any way to change a View Environment (Navigation Bar → Display Settings → Environment) via text command or script.

I'm trying to use text command NuCommands.ViewEnvironmentCmd but it's do nothing without properly argument (or something else).

 

3 REPLIES 3
Message 2 of 4
kandennti
in reply to: ponomarevcs

Message 3 of 4
BrianEkins
in reply to: ponomarevcs

The view environment settings are not explicitly exposed through the API.  However, the API does provide access to the user-interface and these are accessible through the navigation toolbar and can be manipulated that way.  For example, I want to change the visual style to "Shaded", turn on ground plane and shadow, and change the environment to "Tranquility Blue". The following code does that by driving the UI.  Besides it being a bit convoluted, there's another downside to this approach is that it's dependent on the names of the items in the lists so it won't work if you're running Fusion under a language besides English.  I suppose you could use index values instead of names.  Those will be consistent as long as they don't add new items or rearrange items in the lists.

 

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

        # Get the Nav Toolbar.
        navToolbar = ui.toolbars.itemById('NavToolbar')

        # Get the Display Settings drop-down
        viewDropDown: adsk.core.DropDownControl = navToolbar.controls.itemById('ViewDisplayCommand')

        # Get the current visual style and get the shaded list item.
        visualStyleCntrlDef: adsk.core.ControlDefinition = viewDropDown.controls.itemById('ViewVisualStyleCommand')
        cmdDef = visualStyleCntrlDef.commandDefinition
        listControl: adsk.core.ListControlDefinition = cmdDef.controlDefinition
        listItem: adsk.core.ListItem       
        for listItem in listControl.listItems:
            if listItem.name == 'Shaded' and not listItem.isSelected:
                listItem.isSelected = True
                break

        # Set the view environment
        viewEnvCntrlDef: adsk.core.CommandDefinition  = viewDropDown.controls.itemById('ViewEnvCommand')
        cmdDef = viewEnvCntrlDef.commandDefinition
        listControl: adsk.core.ListControlDefinition = cmdDef.controlDefinition
        for listItem in listControl.listItems:
            if listItem.name == 'Tranquility Blue' and not listItem.isSelected:
                listItem.isSelected = True
                break

        # Turn on the ground plane and shadow.
        viewEffectCmd = adsk.core.CommandDefinition = viewDropDown.controls.itemById('ViewEffectCommand')
        cmdDef = viewEffectCmd.commandDefinition
        listControl: adsk.core.ListControlDefinition = cmdDef.controlDefinition
        for listItem in listControl.listItems:
            if listItem.name == 'Ground Plane' and not listItem.isSelected:
                listItem.isSelected = True
            elif listItem.name == 'Ground Shadow' and not listItem.isSelected:
                listItem.isSelected = True
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) 

 

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 4
ponomarevcs
in reply to: BrianEkins

Thanks a lot for help!

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

Post to forums  

Autodesk Design & Make Report