I have an addin which has an icon for a button. In Inventor 2012 it displays fine. In Inventor 2013 the icon appears to be enlarged by about 4x, and only the top left corner of the icon is visible. The api clearly states that Inventor will scale the image to size.
Does anyone else have this problem?
This is the C# code I'm using to load the icon. The icon is in my resources file.
object LookupIcon = Microsoft.VisualBasic.Compatibility.VB6.Support.IconToIPicture( InvAddIn.Properties.Resources.Lookup_Icon);
Edit: See attached pics.
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
Hi,
I am not sure what the problem is, could you take a look at this post if it helps? The 6th message of the post provides another way to convert icon to iPicture.
If it is still no helpful. Please share an icon file for diagnose.
Same problem here!
We switched our addin from framework 3.5 (2012) to framework 4.0 (2013)
When using Ribbon appearance :Compact in 2013 -> all our icons are enlarged by about 4x
Our icons contains 16x16, 32x32, 48x48
of course we could change all of our icons to only 16x16 but that's not a proper solotion.
Is this problem solved yet?
regards,
Geert
Remark: Attachment DataLINK.ico renamed to DataLINK.ico.txt
Code used:
Dim objNaarDataLINKCmdPicture AsIPictureDisp = clsPictureConverter.IconToIPictureDisp(My.Resources.DataLINK)
Class clsPictureConverter:
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Public ClassclsPictureConverter
Inherits System.Windows.Forms.AxHost
SubNew()
MyBase.New(Nothing)
EndSub
PublicSharedFunction ImageToIPictureDisp(ByVal image As System.Drawing.Image) As stdole.IPictureDisp
ReturnAxHost.GetIPictureDispFromPicture(image)
EndFunction
PublicSharedFunction IPictureDisptoImage(ByVal ipicturedisp As stdole.IPictureDisp) As System.Drawing.Image
ReturnAxHost.GetPictureFromIPicture(ipicturedisp)
EndFunction
'*** icon and bitmap through OLE ***********************************************************************************************
PublicSharedFunction IconToIPictureDisp(ByVal icon As System.Drawing.Icon) As stdole.IPictureDisp
Dim pictIcon AsNewPICTDESC.Icon(icon)
Return OleCreatePictureIndirect(pictIcon, iPictureDispGuid, True)
EndFunction
PublicSharedFunction BitmapToIPictureDisp(ByVal bmp As System.Drawing.Bitmap) As stdole.IPictureDisp
Dim pictBmp AsNewPICTDESC.Bitmap(bmp)
Return OleCreatePictureIndirect(pictBmp, iPictureDispGuid, True)
EndFunction
'Definitions
<
DllImport("OleAut32.dll", EntryPoint:="OleCreatePictureIndirect", ExactSpelling:=True, PreserveSig:=False)> _
PrivateSharedFunction OleCreatePictureIndirect(<MarshalAs(UnmanagedType.AsAny)> _
ByVal picdesc AsObject, ByRef iid AsGuid, <MarshalAs(UnmanagedType.Bool)> ByVal fOwn AsBoolean) As stdole.IPictureDisp
EndFunction
PrivateShared iPictureDispGuid AsGuid = GetType(stdole.IPictureDisp).GUID
PrivateNotInheritableClassPICTDESC
PrivateSubNew()
EndSub
'Picture Types
PublicConst PICTYPE_UNINITIALIZED AsShort = -1
PublicConst PICTYPE_NONE AsShort = 0
PublicConst PICTYPE_BITMAP AsShort = 1
PublicConst PICTYPE_METAFILE AsShort = 2
PublicConst PICTYPE_ICON AsShort = 3
PublicConst PICTYPE_ENHMETAFILE AsShort = 4
<
StructLayout(LayoutKind.Sequential)> _
PublicClassIcon
Friend cbSizeOfStruct AsInteger = Marshal.SizeOf(GetType(PICTDESC.Icon))
Friend picType AsInteger = PICTDESC.PICTYPE_ICON
Friend hicon AsIntPtr = IntPtr.Zero
Friend unused1 AsInteger
Friend unused2 AsInteger
FriendSubNew(ByVal icon As System.Drawing.Icon)
Me.hicon = icon.ToBitmap().GetHicon()
EndSub
EndClass
<
StructLayout(LayoutKind.Sequential)> _
PublicClassBitmap
Friend cbSizeOfStruct AsInteger = Marshal.SizeOf(GetType(PICTDESC.Bitmap))
Friend picType AsInteger = PICTDESC.PICTYPE_BITMAP
Friend hbitmap AsIntPtr = IntPtr.Zero
Friend hpal AsIntPtr = IntPtr.Zero
Friend unused AsInteger
FriendSubNew(ByVal bitmap As System.Drawing.Bitmap)
Me.hbitmap = bitmap.GetHbitmap()
EndSub
EndClass
EndClass
End
Class
I didn't realize Autodesk had given an answer here. In short, they claimed the previous automatic scaling of pictures(which I found very convenient) was an accidental feature, and was not intended to work that way.
For icon files that contain multiple sizes, this was their recommendation:
"I think you should be able to get the correct size from a multi-size icon like this, and then convert that to IPictureDisp:http://stackoverflow.com/questions/616500/windows-chooses-wrong-icon-from-multi-icon-file-and-self-r..."
I have not tested the above method. I chose to make 2 separate icons, one small and one large for each button used in my addins. It seemed like a simpler approach to the problem.
In short, I see it as a bug, Autodesk does not.
Hi,
I'm not sure why the change in behaviour appeared in this area, but it is logged in our system.
Even if it turns out to be an issue that needs fixing, you'd need a workaround in the meantime.
If your icon files contain the specific size you want then the solution should be quite easy - as pointed out in the previous reply.
E.g. in case of the SimpleAddIn VB.NET sample, you'd need to change this line:
Dim addSlotOptionIcon As Icon = New Icon(addSlotOptionImageStream)
to this:
Dim addSlotOptionIcon As Icon = New Icon(addSlotOptionImageStream, 16, 16)
It seemed to work fine when I tested it.
Hi,
First we could use 1 IPictureDisp with 1 icon with multiple formats:
Dim objNaarDataLINKCmdPicture As IPictureDisp = clsPictureConverter.IconToIPictureDisp(My.Resources.DataLINK)
Private WithEvents mobjNaarDataLINKCmd As Inventor.ButtonDefinition
mobjNaarDataLINKCmd = objControlDefs.AddButtonDefinition("", "NaarDataLINKCmd", Inventor.CommandTypesEnum.kQueryOnlyCmdType, m_ClientID, , "Ga naar DataLINK", objNaarDataLINKCmdPicture, objNaarDataLINKCmdPicture, ButtonDisplayEnum.kNoTextWithIcon)
The workaround I use now is to define 2 IPictureDisp with 2 seperate icons: (a lot more of work!)
Dim objNaarDataLINKCmdPicture_16 AsIPictureDisp = clsPictureConverter.IconToIPictureDisp(My.Resources.DataLINK_16)
Dim objNaarDataLINKCmdPicture_32 AsIPictureDisp = clsPictureConverter.IconToIPictureDisp(My.Resources.DataLINK_32)
Private WithEvents mobjNaarDataLINKCmd As Inventor.ButtonDefinition
mobjNaarDataLINKCmd = objControlDefs.AddButtonDefinition("", "NaarDataLINKCmd", Inventor.CommandTypesEnum.kQueryOnlyCmdType, m_ClientID, , "Ga naar DataLINK", objNaarDataLINKCmdPicture_16, objNaarDataLINKCmdPicture_32, ButtonDisplayEnum.kNoTextWithIcon)
It works, but is not so smart!
Glad it is logged.
Geert
Is this still not fixed? I just noticed the problem when I was changing icon size for a ribbon that I created for my addin.
Hi,
I don't know if it's solved today. (Autodesk???)
I still use my workaround (see my post) in Inventor 2019 and over the years (and multiple inventor versions) my code is still working so no use to alter it.
Kind regards,
Geert
I am using Inventor 2019.
I have created an add in and I have always put the same icon file as the large icon and the small icon in the inventor.ControlDefinitions.AddButtonDefinition command. This icon file contains a 32x32 icon size and a 16x16 icon size as created by default in visual studio when an icon file is first created. I have set the add in to default to the large button size so I haven't noticed the issue until now. I was reorganizing the ribbon changing some of the buttons to small buttons and noticed that the icon did not go to the smaller size image. The button simply cropped the large icon image (displayed the upper left corner of the large icon size). That is when I found this thread so I thought I would bring it up that it does not appear to be fixed since the issue was logged several years ago. I am currently using the work around but I would like for this to work correctly to minimize coding and file creation.
Hi @jcraig, @Anonymous,
I looked up the earlier help API documents to see if there has been any change regarding the icons over the years. Till the 2013 version, I could see that it was clearly mentioned in the API help document that "You can also supply a normal size icon for both the normal and large icons. Inventor will scale the normal size if the end-user chooses to display large icons....If an icon of a different size is provided, Inventor will scale it to fit."
From Inventor 2014 onwards, this seems to have changed. It just mentions "The Ribbon supports two sizes of icons; small icons are 16x16 pixels and the large icons are 32x32 pixels....."
I believe the auto scaling may have been removed for the later versions.
Regards,
Sajith
Can't find what you're looking for? Ask the community or share your knowledge.