Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
saikiran.nT432F
554 Views, 4 Replies

Trying to add icon to button in Inventor plugin

Hi,

Iam trying to add an icon in Inventor plugin button but for the following code added icon is not displaying or getting the error saying "Parameter is incorrect" or if i change the line  

Dim largeIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.Arturo_Wibawa_Akar_Icon) to

Dim largeIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp("D:\Desktop\Videos\Arturo-Wibawa-Akar-Icon.ico")

 

iam using icon with size 96X96 and tried wityh sizes 32X36. 16X16.

 

Any help in resloving in this issue is much appreciataed. Thanks in advance.

Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
' Initialize AddIn members.
g_inventorApplication = addInSiteObject.Application

' Connect to the user-interface events to handle a ribbon reset.
m_uiEvents = g_inventorApplication.UserInterfaceManager.UserInterfaceEvents

' TODO: Add button definitions.

'Sample to illustrate creating a button definition.
Dim largeIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.YourBigImage)
Dim smallIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.YourSmallImage)

Dim controlDefs As Inventor.ControlDefinitions = g_inventorApplication.CommandManager.ControlDefinitions
m_sampleButton = controlDefs.AddButtonDefinition("sampledef", "Toapp", CommandTypesEnum.kShapeEditCmdType, AddInClientID)

m_sampleButton.LargeIcon = largeIcon
m_sampleButton.SmallIcon = smallIcon

' Add to the user interface, if it's the first time.
If firstTime Then
AddToUserInterface()
End If
End Sub

 

Public NotInheritable Class PictureDispConverter
<DllImport("OleAut32.dll", EntryPoint:="OleCreatePictureIndirect", ExactSpelling:=True, PreserveSig:=False)> _
Private Shared Function OleCreatePictureIndirect( _
<MarshalAs(UnmanagedType.AsAny)> ByVal picdesc As Object, _
ByRef iid As Guid, _
<MarshalAs(UnmanagedType.Bool)> ByVal fOwn As Boolean) As stdole.IPictureDisp
End Function

Shared iPictureDispGuid As Guid = GetType(stdole.IPictureDisp).GUID

Private NotInheritable Class PICTDESC
Private Sub New()
End Sub

'Picture Types
Public Const PICTYPE_BITMAP As Short = 1
Public Const PICTYPE_ICON As Short = 3

<StructLayout(LayoutKind.Sequential)> _
Public Class Icon
Friend cbSizeOfStruct As Integer = Marshal.SizeOf(GetType(PICTDESC.Icon))
Friend picType As Integer = PICTDESC.PICTYPE_ICON
Friend hicon As IntPtr = IntPtr.Zero
Friend unused1 As Integer
Friend unused2 As Integer

Friend Sub New(ByVal icon As System.Drawing.Icon)
Me.hicon = icon.ToBitmap().GetHicon()
End Sub
End Class

<StructLayout(LayoutKind.Sequential)> _
Public Class Bitmap
Friend cbSizeOfStruct As Integer = Marshal.SizeOf(GetType(PICTDESC.Bitmap))
Friend picType As Integer = PICTDESC.PICTYPE_BITMAP
Friend hbitmap As IntPtr = IntPtr.Zero
Friend hpal As IntPtr = IntPtr.Zero
Friend unused As Integer

Friend Sub New(ByVal bitmap As System.Drawing.Bitmap)
Me.hbitmap = bitmap.GetHbitmap()
End Sub
End Class
End Class

Public Shared Function ToIPictureDisp(ByVal icon As System.Drawing.Icon) As stdole.IPictureDisp
Dim pictIcon As New PICTDESC.Icon(icon)
Return OleCreatePictureIndirect(pictIcon, iPictureDispGuid, True)
End Function

Public Shared Function ToIPictureDisp(ByVal bmp As System.Drawing.Bitmap) As stdole.IPictureDisp
Dim pictBmp As New PICTDESC.Bitmap(bmp)
Return OleCreatePictureIndirect(pictBmp, iPictureDispGuid, True)
End Function
End Class