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: 

Color Effect for Head-Up Display

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
nnikbin
252 Views, 8 Replies

Color Effect for Head-Up Display

Selecting a body in browser shows its name at the bottom-right corner of the viewport. As shown in the following picture, the color of the text changes to make contrast between the text and the set viewport background based on [Settings > Environment]

 

35.png

 

Similar to it, I want to make a Head-Up Display (HUD) using CustomGraphicText and control its color to make contrast with the viewport background. Unfortunately there is no CustomGraphicsInverColorEffect to automatically change the text color and I was not able to find any API to get the current viewport environment name or color.

 

It is possible to use a color like green for HUD or to put a solid background layer underneath the text to make some contrast but none of these solutions is ideal.

 

I appreciate any suggestions to make a HUD which is readable for any selected viewport environment.

 

 

8 REPLIES 8
Message 2 of 9
BrianEkins
in reply to: nnikbin

I'm sure there's nothing in the existing API to help with this.  It's a good question though and something that's not been considered before.  It would be interesting to find out how Fusion does this internally.  If it's getting the background color and then setting the color of the text to be contrasting or if there's a more automatic way internally where the text color is set automatically.  I suspect the former, but I don't know.

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

Thank you @BrianEkins  for your informative reply.

Message 4 of 9
JeromeBriot
in reply to: nnikbin

Hi,

 


@nnikbin wrote:

I was not able to find any API to get the current viewport environment name or color.


Try this :

 

 

 

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

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

        EnvironmentID = app.executeTextCommand('Options.Get EnvironmentIDId').split()[-1]

        ui.messageBox(EnvironmentID)

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

 

 

Returned ID and corresponding RGB values are:

  • DarkSky - [51, 51, 51]
  • GreyRoom - [84, 84, 83]
  • PhotoBooth - [255, 255, 255]
  • TranquilityBlue - [63, 137, 200]
  • InfinityPool - [130, 145, 152]

You can also parse the file NGlobalOptions.xml (C:/Users/<UserName>/AppData/Roaming/Autodesk/Neutron Platform/Options/<UserID>/ on Windows) :

 

<GraphicsOptionGroup>
  <EnvironmentIDId ToolTip="Eclairage, arrière-plan et divers paramètres de couleur" UserName="Environnement" Value="DarkSky"/>
</GraphicsOptionGroup>

 

Message 5 of 9
nnikbin
in reply to: JeromeBriot

Wonderful! Thank you @JeromeBriot 

I do not know how reliable are these unofficial commands for using in add-ins that will be distributed. I guess for my problem the benefit may be more that the possible risk of breaking in future versions of Fusion 360. What do you think? Do you use them for a similar problem?

Message 6 of 9
JeromeBriot
in reply to: nnikbin

I try to avoid these unofficial commands. But AFAIK, this is the only solution here. And I think that the environment setting is stable now in Fusion 360.

 

You could try different methods successively:

  1. Use app.executeTextCommand
  2. Parse the XML file
  3. Ask the user
import adsk.core, adsk.fusion, adsk.cam, traceback

import xml.etree.ElementTree as etree
import platform
import os

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

        try:
            EnvironmentID = app.executeTextCommand('Options.Get EnvironmentIDI').split()[-1]
            EnvironmentIDFound = True
        except:
            EnvironmentIDFound = False

        if not EnvironmentIDFound:
            if platform.system() == 'Windows':
                xmlFile = os.path.join(os.getenv('APPDATA'), 'Autodesk', 'Neutron Platform', 'Options', app.currentUser.userId, 'NGlobalOptions.xml')
            else:
                xmlFile = os.path.join(os.path.expanduser('~'), 'Library', 'Application Support', 'Autodesk', 'Neutron Platform', 'Options', app.currentUser.userId, 'NGlobalOptions.xml')
            if os.path.exists(xmlFile):
                node = etree.parse(xmlFile).getroot().find('GraphicsOptionGroup').find('EnvironmentIDId')
                if node is not None and 'Value' in node.attrib:
                    EnvironmentID = node.attrib['Value']
                else:
                    EnvironmentID = 'PhotoBooth'
                EnvironmentIDFound = True
            else:
                EnvironmentIDFound = False

        if not EnvironmentIDFound:
            (EnvironmentID, isCancelled)  = ui.inputBox('Enter the name of the current environment', 'Select environment', 'PhotoBooth')

        ui.messageBox(EnvironmentID)

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

 

Message 7 of 9
nnikbin
in reply to: JeromeBriot

Thank you @JeromeBriot  for your good suggestion, and thank you for sharing your opinion on using unofficial text commands.

Message 8 of 9
kandennti
in reply to: JeromeBriot

@JeromeBriot  Great job!

 

It looks like you can get the various folder paths used in Fusion360 with this.

Paths.Get

It's probably OS independent.

 

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

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

        dirName ='optionsDirectory'
        ui.messageBox(F'-- {dirName} --\n{getEnvironmentFolderPath(dirName)}')

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

# --Get environment folder path--
# NameList Fusion360 ver2.0.9937
#     "rootDirectory",
#     "executableDirectory",
#     "localizationDirectory",
#     "coreAddInDirectory",
#     "stringTableDirectory",
#     "appDirectory",
#     "sharedExtensionDirectory",
#     "temporaryDirectory",
#     "unbrandedUserDataDirectory",
#     "userDataDirectory",
#     "allUsersDataDirectory",
#     "unbrandedUserAppPluginsDirectory",
#     "unbrandedAllUserAppPluginsDirectory",
#     "bootstrapOptionDirectory",
#     "optionsDirectory",
#     "cloudCacheDirectory",
#     "isInstalledBuild",
#     "scriptsDirectory",
#     "autorunScriptsDirectory",
#     "samplesScriptsDirectory",
#     "programDataScriptsDirectory",
#     "appDataScriptsDirectory",
#     "manuallyInstalledScriptsDirectory",
#     "materialsDirectory",
#     "testTempDirectory",
#     "scratchDirectory",
#     "resultDirectory",
#     "sampleDirectory",
#     "AppLogFilePath",
#     "CacheDirectory",
#     "autoSaveDirectory",
def getEnvironmentFolderPath(name :str):
    app = adsk.core.Application.get()
    paths = json.loads(app.executeTextCommand(u'Paths.Get'))

    return paths.get(name)
Message 9 of 9
nnikbin
in reply to: kandennti

Thank you @kandennti  for your reply and sharing this information

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