Inventor 2022 - Different Icon for dark theme

Inventor 2022 - Different Icon for dark theme

yan.gauthier
Advocate Advocate
947 Views
6 Replies
Message 1 of 7

Inventor 2022 - Different Icon for dark theme

yan.gauthier
Advocate
Advocate

Is there a way to specify an icon for light theme and a different one for dark theme just like we can do for big and small icon ? Otherwise, does this mean the only way to adapt my icons is to check ThisApplication.ThemeManager.ActiveTheme.Name every time the events ApplicationEvents.OnApplicationOptionChange is fired ?

 

0 Likes
Accepted solutions (1)
948 Views
6 Replies
Replies (6)
Message 2 of 7

JelteDeJong
Mentor
Mentor

As far as I know, there is no special property for dar/light themes. But I guess that your alternative is a good solution and not that difficult to implement.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 7

yan.gauthier
Advocate
Advocate
Accepted solution

To those interested. Here is the code I used to make it work (I work with C#, since VB.NET is a dying species)

 

private string activeTheme;
private void ApplicationEvents_OnApplicationOptionChange(EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode)
        {
            if(BeforeOrAfter == EventTimingEnum.kBefore)
            {
                activeTheme = InvApp.ThemeManager.ActiveTheme.Name;
            }
            else if(BeforeOrAfter == EventTimingEnum.kAfter)
            {
                if (activeTheme.Equals("DarkTheme", StringComparison.OrdinalIgnoreCase) && InvApp.ThemeManager.ActiveTheme.Name.Equals("LightTheme", StringComparison.OrdinalIgnoreCase))
                {
                    SetDarkThemeIcons();
                }
                else if (activeTheme.Equals("LightTheme", StringComparison.OrdinalIgnoreCase) && InvApp.ThemeManager.ActiveTheme.Name.Equals("DarkTheme", StringComparison.OrdinalIgnoreCase))
                {
                    SetLightThemeIcons();
                }
            }

            HandlingCode = HandlingCodeEnum.kEventNotHandled; //let Inventor do its thing
        }
0 Likes
Message 4 of 7

mat_hijs
Collaborator
Collaborator

@yan.gauthier Would you also be willing to share the code inside SetDarkThemeIcons() or SetLightThemeIcons()?

0 Likes
Message 5 of 7

yan.gauthier
Advocate
Advocate

If what you want to know is how to change the icon, then the code is something like this : 

 

schematikDifferenceButton.ButtonDefinition.LargeIcon = AxHostConverter.ImageToPictureDisp(Icons.BigSchematikDifferenceIcon(isDarkMode: true));
schematikDifferenceButton.ButtonDefinition.StandardIcon = AxHostConverter.ImageToPictureDisp(Icons.SmallSchematikDifferenceIcon(isDarkMode: true));

 

where AxHostConverter is based on System.Windows.Forms.AxHost and uses stdole (which you need to set the reference to the dll manually)

 

internal class AxHostConverter : AxHost
{
    private AxHostConverter() : base("") { }

    static public stdole.IPictureDisp ImageToPictureDisp(Image image)
    {         
         return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);          
    }
    static public Image PictureDispToImage(stdole.IPictureDisp pictureDisp)
    {
        return GetPictureFromIPicture(pictureDisp);
    }
}

 

If what you want to know is how to create an Icon for Inventor, there are many options, but you need to have something that is derived from System.Drawing.Image to convert to IPictureDisp. In my case, I work with System.Drawing.Bitmap. Small Icons are 16x16px and Big Icons are 32x32px

0 Likes
Message 6 of 7

mat_hijs
Collaborator
Collaborator

I have the icons already, both for light theme and for dark theme. I was basically looking for a clean way to switch between these Icons. The way I have it built right now, besides having to create the buttondefinition and adding it to the ribbon, I also have to create a line for each buttondefinition for both dark theme and light theme to choose the correct icon. I was hoping there was a way so I could for example have a function that takes a buttondefinition, finds the corresponding dark or light icon and sets it. That way I would only have to call the function for each buttondefinition once.

Icons.BigSchematikDifferenceIcon(isDarkMode: true)

How does this work? That seems like it may be close to what I was looking for.

0 Likes
Message 7 of 7

yan.gauthier
Advocate
Advocate

It's a method that takes the bool isDarkMode parameter to switch the color. Most of my icons are dynamically generated from either a SVG file, a SVG string or from a font character from the MDL2 Assets. I Set the color myself. So I have more than just 2 lines of codes for all of that.

 

public static Bitmap BigSchematikCopyDesignIcon(bool isDarkMode = false)
{
    SKColor color = isDarkMode ? new SKColor(0xd9, 0xd9, 0xd9, 0xff) : new SKColor(0x66, 0x66, 0x66, 0xff);
    using var svgStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"{Assembly.GetExecutingAssembly().GetName().Name}.Resources.Icons.SchematikCopyDesign.svg");
    
    if (svgStream == null) return CreateBigGlyphIcon(Glyphs.QuestionMark, color.ToDrawingColor());
    
    using SKSvg svg = new();
    svg.Load(svgStream);

    return BigSvgIcon(svg, isDarkMode);
}

 

0 Likes