Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with icon for button (Inventor 2014 - VB.Net)

1 REPLY 1
Reply
Message 1 of 2
mthomas
2216 Views, 1 Reply

Help with icon for button (Inventor 2014 - VB.Net)

Sorry if this seems simple but I'm really struggling with getting an icon to appear on the button I've defined for the Inventor Ribbon. I'm using Inventor 2014 and Visual Studio VB.NET 2012

 

The Error I'm getting when launching Inventor is attached (System.ArgumentException.jpg)

 

I have attached my two .ico's to the project and changed their Build Action to "Embedded Resource"

 

My code is as follows...

 


m_PMPWFButton = New PMPWorkFeatureAddIn.PMPWorkFeatureButton()
m_PMPWFButton.CreateButton(m_inventorApplication, False, "PM&P WorkFeature", "Autodesk:CustomCommand:PMPWFButton", CommandTypesEnum.kShapeEditCmdType, m_addInCLSIDString, "Work with Work Features", "Work with Work Features", GetICOResource("WF_ICON16.ico"), GetICOResource("WF_ICON.ico"))

 

 

I copied in the procedures as defined at http://adndevblog.typepad.com/manufacturing/2013/07/creating-a-ribbon-item-for-inventor.html

 

I'm obviously missing something simple.... Help?

 

Thanks

 

Mike

 

 

Mike Thomas

Tags (1)
1 REPLY 1
Message 2 of 2
saseendrankombath
in reply to: mthomas

Try the below code, Change the icon name and project nams to your project and icon names. add these procedures to standardaddinserver

Private WithEvents oBtnProjectSketch As Inventor.ButtonDefinition

 declare the above and change the button name as you required.

 

Try : oBtnProjectSketch = CreateButton("Project" & vbCrLf & "Sketch", "IP:IntCmd:ProjectSketch", _
        Inventor.CommandTypesEnum.kNonShapeEditCmdType, True, m_AddInCLSIDString, _
        "Project Sketch", "Project Sketch - Selected Geometry only", "ProjectedSketch.Proj_Sketch32.png", _
        "ProjectedSketch.Proj_Sketch32.png", Inventor.ButtonDisplayEnum.kDisplayTextInLearningMode) : Catch : End Try

 define the button, change the names  and details as you want.

 

If firstTime Then
            Dim partRibbon As Ribbon = m_inventorApplication.UserInterfaceManager.Ribbons("Part")
            Dim partAddinTab As RibbonTab = partRibbon.RibbonTabs("id_AddInsTab")
            Dim partRenamePanel As RibbonPanel
            Try
                partRenamePanel = partAddinTab.RibbonPanels.Item("id_PanelP_Project_Sketch")
            Catch ex As Exception
                partRenamePanel = partAddinTab.RibbonPanels.Add("Sketch Tools", "id_PanelP_Sketch_Tools", m_AddInCLSIDString, , )
            End Try
            Dim partRenameCmdCtrls As CommandControls = partRenamePanel.CommandControls
            With partRenameCmdCtrls
                .AddButton(oBtnProjectSketch, True, True, , )
            End With
        End If

 use the below function to create button and to convert the icon file

 

Public Function CreateButton(ByRef strBtnDisplayName As String, ByRef strBtnInternalName As String, ByRef eBtnType As Inventor.CommandTypesEnum, ByRef blnAutoAddToGUI As Boolean, Optional ByRef strBtnClientId As String = "", Optional ByRef strBtnDescription As String = "", Optional ByRef strBtnToolTipText As String = "", Optional ByRef strBtnStdIcon As String = "", Optional ByRef strBtnLrgIcon As String = "", Optional ByRef eBtnDisplayEnum As Inventor.ButtonDisplayEnum = Inventor.ButtonDisplayEnum.kDisplayTextInLearningMode) As Inventor.ButtonDefinition

        Dim StandardIconIPictureDisp As Object = System.Type.Missing
        Dim LargeIconIPictureDisp As Object = System.Type.Missing
        Try
            If Not strBtnStdIcon Is Nothing Then
                Dim StandardIconStream As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream(strBtnStdIcon)
                Dim StandardIconImage As System.Drawing.Image = New System.Drawing.Bitmap(StandardIconStream)

                StandardIconIPictureDisp = ImageToPictureConverter.Convert(StandardIconImage)
            End If
        Catch ex As Exception
        End Try

        Try
            If Not strBtnLrgIcon Is Nothing Then
                Dim LargeIconStream As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream(strBtnLrgIcon)
                Dim LargeIconImage As System.Drawing.Image = New System.Drawing.Bitmap(LargeIconStream)

                LargeIconIPictureDisp = ImageToPictureConverter.Convert(LargeIconImage)
            End If
        Catch
        End Try

        CreateButton = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition(strBtnDisplayName, strBtnInternalName, eBtnType, strBtnClientId, strBtnDescription, strBtnToolTipText, StandardIconIPictureDisp, LargeIconIPictureDisp, eBtnDisplayEnum)

        If CreateButton Is Nothing Then
            MsgBox("Failed to create Button:" & strBtnDisplayName)
        End If

    End Function

#Region "ImageToPictureConverter"
    Public NotInheritable Class ImageToPictureConverter
        Inherits System.Windows.Forms.AxHost

        Private Sub New()
            MyBase.New(Nothing)
        End Sub

        Public Shared Function Convert(ByVal image As System.Drawing.Image) As stdole.IPictureDisp
            Return CType(System.Windows.Forms.AxHost.GetIPictureDispFromPicture(image), stdole.IPictureDisp)
        End Function

    End Class
#End Region

  Hope the above will help to solve your problem.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report