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: 

Add icon for button ribbon

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
SandmanINV
2202 Views, 8 Replies

Add icon for button ribbon

Hi everyone, 

yes, like my topic. I also read many topic about this, but i am stilling stuck on it, mybe too much way.

I can create a ribbon, panel, and add button on it. 

But i dont know how to put an icon for that button. Somebody help me please.

This is my current fail code.

        Dim oStream1 As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("Inventor_Sheet.favicon4.ico")
        Dim oIcon1 As Drawing.Icon = New Drawing.Icon(oStream1)
        Dim oIPictureDisp1 As Object = AxHostConverter.ImageToPictureDisp(oIcon1.ToBitmap())

        Dim oCtrlDefs As ControlDefinitions = oinv.CommandManager.ControlDefinitions
        Dim oButtonDef As ButtonDefinition = oCtrlDefs.AddButtonDefinition("Doi sheet", "btn_doisheet", CommandTypesEnum.kQueryOnlyCmdType, "AddInGuid",
                             "Description", "Tolltip text", oIPictureDisp1, oIPictureDisp1,
                                                                           ButtonDisplayEnum.kDisplayTextInLearningMode)

Thank you

8 REPLIES 8
Message 2 of 9

For which version of inventor?

 

 

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 9

Thank you, I am using inventor 2020.

Message 4 of 9

then use This:

Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports VB = Connectivity.Application.VaultBase
Imports System.Collections.Generic
Imports AuCoWebs = Autodesk.Connectivity.WebServices
Imports Autodesk.Connectivity.WebServices

Namespace gggg_
    <ProgIdAttribute("gggg"),
    GuidAttribute("gggg")>
    Public Class StandardAddInServer
        Implements Inventor.ApplicationAddInServer
 
        Private WithEvents m_uiEvents As UserInterfaceEvents
        Private WithEvents m_InvAppEvents As Inventor.ApplicationEvents
        Private WithEvents m_sampleButton As ButtonDefinition

#Region "ApplicationAddInServer Members"

        ' This method is called by Inventor when it loads the AddIn. The AddInSiteObject provides access  
        ' to the Inventor Application object. The FirstTime flag indicates if the AddIn is loaded for
        ' the first time. However, with the introduction of the ribbon this argument is always true.
        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
            m_InvAppEvents = g_inventorApplication.ApplicationEvents
'' TODO: Add button definitions.

            '' Sample to illustrate creating a button definition.
            Dim largeIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.Rev)
            Dim smallIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.YourSmallImage)
            Dim controlDefs As Inventor.ControlDefinitions = g_inventorApplication.CommandManager.ControlDefinitions
            m_sampleButton = controlDefs.AddButtonDefinition("Command Namex", "Internal Namex", CommandTypesEnum.kShapeEditCmdType, AddInClientID)


#Region "Image Converter"
    ' Class used to convert bitmaps and icons from their .Net native types into
    ' an IPictureDisp object which is what the Inventor API requires. A typical
    ' usage is shown below where MyIcon is a bitmap or icon that's available
    ' as a resource of the project.
    '
    ' Dim smallIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.MyIcon)

    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
#End Region

End Module

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 5 of 9

Thank you for your help,

After create class "PictureDispConverter"

I have an error  in GUIDline : value of type"Guid" can not to GUID. How do I solve this ?

After having that class, i use like this, right ?: 

Dim mIPictureDisp1 As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.ico_1)

 I have an icon 24x24 .bmp which be named : ico_1

 

Message 6 of 9
SandmanINV
in reply to: SandmanINV

I still stuck on it...help me pls.

Message 7 of 9

I am far from my desk.

Earliest monday morning I am able to take a closer look.

 

Regards 

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 8 of 9

Thank you, 

I also work follow help API, but result also like this image....

Capture.JPG

This is my current code

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim oDoc As Document = oinv.ActiveDocument
        Dim oUIMNG As UserInterfaceManager = oinv.UserInterfaceManager
        'Get ribbon Tab
        Dim oMy_ribbon_group As Inventor.Ribbon = oUIMNG.Ribbons.Item("ZeroDoc")

        For Each oribbon_trung As RibbonTab In oMy_ribbon_group.RibbonTabs
            If oribbon_trung.InternalName = "id_BuildTab" Then
                oribbon_trung.Delete()
            End If
        Next

        Dim oMy_ribbonTab As RibbonTab
        ' Try 
        oMy_ribbonTab = oMy_ribbon_group.RibbonTabs.Add("BuildTab", "id_BuildTab", "{5B9AA8AD-1D99-4957-8CB4-9870F23CBBFH}", "id_TabTools", True, False)
        'Catch ex As Exception
        'MsgBox(ex.Message)
        'End Try

        'Get panel
        For Each opanel_trung As RibbonPanel In oMy_ribbonTab.RibbonPanels
            If opanel_trung.InternalName = "id_doitensheet" Then
                opanel_trung.Delete()
            End If
        Next
        Dim onew_panel As RibbonPanel = oMy_ribbonTab.RibbonPanels.Add("Đổi tên sheet", "id_doitensheet", "Addanaddinid", "", False)
        Dim ocontrl_def As ControlDefinitions = oinv.CommandManager.ControlDefinitions

        Dim smallPicture As stdole.IPictureDisp = PictureConverter.ImageToPictureDisp(My.Resources.Image1)

        Dim largePicture As stdole.IPictureDisp = PictureConverter.ImageToPictureDisp(My.Resources.Image2)

        Dim obutton_def As ButtonDefinition = ocontrl_def.AddButtonDefinition("Check btn",
                                                                              "id_checkbtn", CommandTypesEnum.kNonShapeEditCmdType,
                                                                              "{311a4c02-49df-4947-a01c-47765ec06b27}", "Chekc descrip",
                                                                              "Check tooltip", , )
        obutton_def.StandardIcon = PictureConverter.ImageToPictureDisp(My.Resources.Image1)
        obutton_def.LargeIcon = PictureConverter.ImageToPictureDisp(My.Resources.Image2)
        onew_panel.CommandControls.AddButton(obutton_def, True, True,,)

    End Sub

End Class
'---------------------------

'---------------------------------------------------------------------------------------------------------------------------------
<System.ComponentModel.DesignerCategory("")>
Friend Class PictureConverter
    Inherits System.Windows.Forms.AxHost
    Private Sub New()
        MyBase.New(String.Empty)
    End Sub
    Public Shared Function ImageToPictureDisp(
                           ByVal image As System.Drawing.Image) As stdole.IPictureDisp
        Return CType(GetIPictureDispFromPicture(image), stdole.IPictureDisp)
    End Function
End Class
Message 9 of 9

try it this way:

 Dim controlDefs As Inventor.ControlDefinitions = g_inventorApplication.CommandManager.ControlDefinitions
            m_sampleButton = controlDefs.AddButtonDefinition("Command Namex", "Internal Namex", CommandTypesEnum.kShapeEditCmdType, AddInClientID)
  ' This function uses reflection to get the GuidAttribute associated with the add-in.
    Public Function AddInClientID() As String
        Dim guid As String = ""
        Try
            Dim t As Type = GetType(KnoorsInventorTools__Tester191202_.StandardAddInServer)
            Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False)
            Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute)
            guid = "{" + guidAttribute.Value.ToString() + "}"
        Catch
        End Try

        Return guid
    End Function

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

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

Post to forums  

Autodesk Design & Make Report