Loading an Icon in Inventor 2025

Loading an Icon in Inventor 2025

pfk
Enthusiast Enthusiast
855 Views
5 Replies
Message 1 of 6

Loading an Icon in Inventor 2025

pfk
Enthusiast
Enthusiast

Hi

 

My Inventor 2024 addin uses the following to put a button with an icon on the toolbar.

 

 

            stdole.IPictureDisp standardIconIPictureDisp = null;
            stdole.IPictureDisp largeIconIPictureDisp = null;
            if (standardIcon != null)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                standardIconIPictureDisp = Support.IconToIPicture(standardIcon) as stdole.IPictureDisp;
                largeIconIPictureDisp = (stdole.IPictureDisp)Support.IconToIPicture(largeIcon);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            mButtonDef = AddinGlobal.InventorApp.CommandManager.ControlDefinitions.AddButtonDefinition(
                displayName, internalName, commandType,
                clientId, description, tooltip,
                standardIconIPictureDisp, largeIconIPictureDisp, buttonDisplayType);

 

 

However this does not work with Inventor 2025 as .NET no longer supports Microsoft.VisualBasic.Compatibility.VB6 which provides the Support.IconToIPicture function.

 

Thanks

 

Paul

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

WCrihfield
Mentor
Mentor

Hi @pfk.  I do not currently create Inventor add-ins, or code with C#, but I may be able to help with this specific issue.  There has been a newer way to convert between the 'IPictureDisp' type and the 'Image' type for further processing/conversion.  It uses the System.Windows.Forms.AxHost Class, or at least a sub class that utilizes that class.  Below are a few links you can look into.  The first is the oldest.

https://modthemachine.typepad.com/my_weblog/2012/05/thumbnail-viewer-component-on-a-64-bit-system.ht... 

https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogicmini-toolbar-combo-box-list-item-ic... 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.axhost 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.axhost.getipicturedispfrompicture 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.axhost.getpicturefromipicturedisp 

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image 

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image.save 

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image.getthumbnailimage 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

See the Inventor 2025 SDK. There is a sample how to convert Icon to IPictureDisp

...\DeveloperTools\Samples\VCSharp.NET\AddIns\SimpleAddIn\PictureDispConverter.cs

Message 4 of 6

JelteDeJong
Mentor
Mentor

There is an alternative to the "Microsoft.VisualBasic.Compatibility.VB6 ". You can create your own utility class that lets you get rid of that namespace functionality.

You can find the code for the utility class here:

https://adndevblog.typepad.com/manufacturing/2012/06/how-to-convert-iconbitmap-to-ipicturedisp-witho...

In my tutorial post "Adding icons to your buttons" you can see how to use the utility class. However, it's written in vb.net

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

Message 5 of 6

pfk
Enthusiast
Enthusiast

...\DeveloperTools\Samples\VCSharp.NET\AddIns\SimpleAddIn\PictureDispConverter.cs worked nicely - thank you.

 

Paul

Message 6 of 6

gilsdorf_e
Collaborator
Collaborator

Honestly, it seems very cumbersome just to have icons loaded in Inventor addons. And it did not get better with .NET 8.0. Is this something that could be tackled by the Autodesk developers in the Inventor API?

0 Likes