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: 

Is there access to the Display Settings / Environment options?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Joshua.mursic
228 Views, 5 Replies

Is there access to the Display Settings / Environment options?

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

5 REPLIES 5
Message 2 of 6
BrianEkins
in reply to: Joshua.mursic

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
in reply to: BrianEkins

Thanks so much Brian! Really appreciate the help!

Message 4 of 6
Joshua.mursic
in reply to: BrianEkins

Hey Brian,

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

Message 5 of 6
BrianEkins
in reply to: Joshua.mursic

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
in reply to: BrianEkins

Thanks!

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report