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).
Solved! Go to Solution.
Solved by BrianEkins. Go to Solution.
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()))
Can't find what you're looking for? Ask the community or share your knowledge.