Is there access to the Display Settings / Environment options?

Is there access to the Display Settings / Environment options?

Joshua.mursic
Advocate Advocate
688 Views
5 Replies
Message 1 of 6

Is there access to the Display Settings / Environment options?

Joshua.mursic
Advocate
Advocate

Hello,

 

I am trying to have my addon change the background color of the environment, depending on what mode that addon is in. Is there a way to activate the different environment options (Dark Sky, Grey Room etc...)? And is it possible to create new environment color options?  

 

Kind regards,

Josh

0 Likes
Accepted solutions (2)
689 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor
Accepted solution

The environments aren't directly exposed through the API. However, you can access the environment command through the API and interact with it to get and set the current environment.  Below is some example code that contains a test function and two helper functions that let you get and set the environment. When getting and setting which item in the list is active, I chose to use the index instead of the name so it will work when Fusion is set to any language.

 

def run(context):
    app: adsk.core.Application = adsk.core.Application.get()
    ui = app.userInterface
    try:
        SetEnvironment(ui, 'Dark Sky')
        envName = GetEnvironment(ui)
        app.log(envName)

        SetEnvironment(ui, 'Tranquility Blue')
        envName = GetEnvironment(ui)
        app.log(envName)
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def GetEnvironment(ui: adsk.core.UserInterface) -> str:
    viewCmd = ui.commandDefinitions.itemById('ViewEnvCommand')
    listCntrl: adsk.core.ListControlDefinition = viewCmd.controlDefinition

    if listCntrl.listItems[0].isSelected:
        return 'Dark Sky'
    elif listCntrl.listItems[1].isSelected:
        return 'Grey Room'
    elif listCntrl.listItems[2].isSelected:
        return 'Photo Booth'
    elif listCntrl.listItems[3].isSelected:
        return 'Tranquility Blue'
    elif listCntrl.listItems[4].isSelected:
        return 'Infinity Pool'
    elif listCntrl.listItems[5].isSelected:
        return 'River Rubicon'
    else:
        return 'Unknown'

  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 6

Joshua.mursic
Advocate
Advocate

Thanks so much Brian! Really appreciate the help!

0 Likes
Message 4 of 6

Joshua.mursic
Advocate
Advocate

Hey Brian,

I do not see the SetEnviroment() function in your example code that you provided

0 Likes
Message 5 of 6

BrianEkins
Mentor
Mentor
Accepted solution

Oops. Sorry about that. Here it is.

def SetEnvironment(ui: adsk.core.UserInterface, envName: str) -> bool:
    viewCmd = ui.commandDefinitions.itemById('ViewEnvCommand')
    listCntrl: adsk.core.ListControlDefinition = viewCmd.controlDefinition

    if envName == 'Dark Sky':
        listCntrl.listItems[0].isSelected = True
    elif envName == 'Grey Room':
        listCntrl.listItems[1].isSelected = True
    elif envName == 'Photo Booth':
        listCntrl.listItems[2].isSelected = True
    elif envName == 'Tranquility Blue':
        listCntrl.listItems[3].isSelected = True
    elif envName == 'Infinity Pool':
        listCntrl.listItems[4].isSelected = True
    elif envName == 'River Rubicon':
        listCntrl.listItems[5].isSelected = True
    else:
        return False

    return True
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 6

Joshua.mursic
Advocate
Advocate
Thanks!
0 Likes