Inventor Add-in - calling a window form from ribbon panel

Inventor Add-in - calling a window form from ribbon panel

Anonymous
Not applicable
1,087 Views
1 Reply
Message 1 of 2

Inventor Add-in - calling a window form from ribbon panel

Anonymous
Not applicable

Hello all,

 

I am a newbie to inventor and vb.net, working to create an interface that will list the components in an assembly, dimensions and volume.

 

I have a StandardAddInServer.vb and Form.Vb file. The idea is to create two buttons in the ribbon panel which on clicking will pop up the window forms with required information that can be closed with 'OK' or exported to excel using 'Export' buttons.

Problems faced

1. Dont know how to execute the windows form on clicking the button.

2. Help in listing the parts of an assembly.

 

My programming skills are very bad and not sure how much of below codes are correct. Will appreciate any suggestion/improvements.

 

Thank you

Mohamed

 

 

 

 

 

 

Imports Inventor
Imports System.Type
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Namespace InventorAddIn4
    <ProgIdAttribute("InventorAddIn4.StandardAddInServer"), _
    GuidAttribute("b6d4ba13-8fd1-4048-9284-cff6f4ae1d3a")> _
    Public Class StandardAddInServer
        Implements Inventor.ApplicationAddInServer
        Private WithEvents m_uiEvents As UserInterfaceEvents
        Private WithEvents m_MeasurePart As ButtonDefinition
        Private WithEvents m_ListParts 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

            ' TODO: Add button definitions.

            ' Sample to illustrate creating a button definition.
            Dim largeIcon1 As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.MeasurePart)
            Dim largeIcon1 As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.ListParts)
           

            Dim controlDefs As Inventor.ControlDefinitions = g_inventorApplication.CommandManager.ControlDefinitions
            m_MeasurePart = controlDefs.AddButtonDefinition("Measure Part", "MeasurePartCmd", CommandTypesEnum.kFileOperationsCmdType, AddInClientID)
            m_ListParts = controlDefs.AddButtonDefinition("List Parts", "ListPartCmd", CommandTypesEnum.kFileOperationsCmdType, AddInClientID)

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

        ' This method is called by Inventor when the AddIn is unloaded. The AddIn will be
        ' unloaded either manually by the user or when the Inventor session is terminated.
        Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate

            ' TODO:  Add ApplicationAddInServer.Deactivate implementation

            ' Release objects.
            m_uiEvents = Nothing
            g_inventorApplication = Nothing

            System.GC.Collect()
            System.GC.WaitForPendingFinalizers()
        End Sub

        ' This property is provided to allow the AddIn to expose an API of its own to other
        ' programs. Typically, this  would be done by implementing the AddIn's API
        ' interface in a class and returning that class object through this property.
        Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
            Get
                Return Nothing
            End Get
        End Property

        ' Note:this method is now obsolete, you should use the
        ' ControlDefinition functionality for implementing commands.
        Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
        End Sub

#End Region

#Region "User interface definition"
        ' Sub where the user-interface creation is done.  This is called when
        ' the add-in loaded and also if the user interface is reset.
        Private Sub AddToUserInterface()
            ' This is where you'll add code to add buttons to the ribbon.

            'Get the Part Ribbon
            Dim OPartRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Part")

            'Get the "Add-Ins" tab.
            Dim OAddIns As RibbonTab = OPartRibbon.RibbonTabs.Item("id_AddInsTab")

            'Create a Ribbon tab in Part Ribbon.
            ' Dim AnalyzeTab As RibbonTab = OPartRibbon.RibbonTabs.Add("Analyze", "AnalyzeTab", AddInClientID)

            'Create a Ribbon Panel
            Dim AnalyzePanel As RibbonPanel = OAddIns.RibbonPanels.Add("AnalyzeAsy", "AnalyzePanel", AddInClientID)

            'Add a button
            AnalyzePanel.CommandControls.AddButton(m_MeasurePart)
            AnalyzePanel.CommandControls.AddButton(m_ListParts)

        End Sub

        Private Sub m_uiEvents_OnResetRibbonInterface(Context As NameValueMap) Handles m_uiEvents.OnResetRibbonInterface
            ' The ribbon was reset, so add back the add-ins user-interface.
            AddToUserInterface()
        End Sub

        ' Sample handler for the button.
        'Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute
        '    MsgBox("Button was clicked.")
        'End Sub
#End Region

        Private Sub m_MeasurePart_OnExecute(Context As NameValueMap) Handles m_MeasurePart.OnExecute

        End Sub
    End Class
End Namespace

 

 

Public Class Form2
    Inherits System.Windows.Forms.Form


    Private Sub cmdOK_Click(sender As Object, e As EventArgs) Handles cmdOK.Click
        Me.Close()
    End Sub

    Public Sub DisplayEntityInformation(ByRef objSurfaceBody As Inventor.SurfaceBody)

        'detrmine the volume of the surface body

        Dim dblVolume As Double
        dblVolume = objSurfaceBody.Volume(1)

        Me.Show()

    End Sub

 

    Private Sub cmdExport_Click(sender As Object, e As EventArgs) Handles cmdExport.Click

    End Sub

 

    End Class

0 Likes
1,088 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Hello

You will need to compile the add-in and call the program as follows:

 

        private void ButtonDef12_OnExecute(NameValueMap Context)
        {
            try
            {
                System.Diagnostics.Process.Start(Path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


Path is where you have the program compiled.

 


For parts listing, see the Inventor API Help topic, 'Using the BOM APIs Sample API'.

 

I hope I have helped

0 Likes