How to execute Addin

How to execute Addin

Anonymous
Not applicable
3,617 Views
12 Replies
Message 1 of 13

How to execute Addin

Anonymous
Not applicable

Hello there,

 

I made a VB.NET programm in Visual Studio to execute the "Pack and Go" command. It works fine if I make a normal VB project, create a Windows Form with a Button which then executes the Sub.

 

Now I want to create an Inventor Addin, so I can run the command directly. At first with a simple Button to start it. I created an Inventor Addin Project in Visual Studio. The paths for the .addin and .dll files have been set (automatically). The Addin also shows up in the Add-In Manager as "Loaded". And the syntax should be correct because it works in the non-addin version via Windows form.

 

In the debug properties of Visual Studio I put in the Inventor.exe to start when I'm executing the programm. When I run the code, inventor starts but then nothing happens. Shouldn't the addin be executed, showing me the User Form with the Button?

 

This is my Code

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent
        Dim oPacknGo As PackAndGoLib.PackAndGo

        oPacknGo = oPacknGoComp.CreatePackAndGo("source path", "destination path")
        oPacknGo.ProjectFile = "project file path"

        Dim sRefFiles = New String() {}
        Dim sMissFiles = New Object

        oPacknGo.SkipLibraries = True
        oPacknGo.SkipStyles = True
        oPacknGo.SkipTemplates = True
        oPacknGo.CollectWorkgroups = False
        oPacknGo.KeepFolderHierarchy = True
        oPacknGo.IncludeLinkedFiles = True

        oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles)
        oPacknGo.AddFilesToPackage(sRefFiles)
        oPacknGo.CreatePackage()
    End Sub
End Class

 

 

 

0 Likes
Accepted solutions (1)
3,618 Views
12 Replies
Replies (12)
Message 2 of 13

bradeneuropeArthur
Mentor
Mentor

hi,

 

Can you please provide the complete add in as text file.

Seems to be that you haven't added the code to an event!!

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
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:
My 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 !


 


EESignature

0 Likes
Message 3 of 13

Frederick_Law
Mentor
Mentor

You need to create an icon in the ribbon which will execute the command when click.

0 Likes
Message 4 of 13

Anonymous
Not applicable

Thanks for your reply.

 

Sorry I'm not sure which files you need exactly (or is there a way to export the complete add in as text file?)

 

Are the files in the attachment the ones you need?

0 Likes
Message 5 of 13

bradeneuropeArthur
Mentor
Mentor

Yes that is also what I meant.

 

You need to implement:

 

Public Sub Activate(ByVal......) etc to add a button or else what to the ribbon.

Also to add events from inventor

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
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:
My 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 !


 


EESignature

0 Likes
Message 6 of 13

bradeneuropeArthur
Mentor
Mentor

As I can see your add in is not complete........

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
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:
My 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 !


 


EESignature

0 Likes
Message 7 of 13

Anonymous
Not applicable

Thanks for your reply

 

I tried to make a button which can execute the command.

 

I added a new class to my Addin Project with this Code, but it doesn't do anything. Do I have to make an separate project which creates the button?

 

 

Imports Microsoft.VisualBasic

Public Class Class1

    ' Declare member variables.
    Private m_inventorApplication As Inventor.Application
    Private m_ClientID As String
    Private WithEvents m_featureCountButtonDef As ButtonDefinition

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

        ' Get the ClassID for this addin And save it in a 
        ' member variable to use wherever a ClientID is needed. 
        m_ClientID = AddInGuid(GetType(StandardAddInServer))

        ' Create the button definition.
        Dim controlDefs As ControlDefinitions
        controlDefs = m_inventorApplication.CommandManager.ControlDefinitions

        m_featureCountButtonDef = controlDefs.AddButtonDefinition("Pack and Go", "PacknGo_test", CommandTypesEnum.kQueryOnlyCmdType, m_ClientID, "beschreibung", "tooltip")

        If firstTime Then
            ' Create a new command bar(toolbar) And make it visible.        
            Dim commandBars As CommandBars
            commandBars = m_inventorApplication.UserInterfaceManager.CommandBars
            Dim commandBar As CommandBar
            commandBar = commandBars.Add("My Macros", "PacknGoInMyMacros",, m_ClientID)
            commandBar.Visible = True
            ' Add the controlto the command bar.

            commandBar.Controls.AddButton(m_featureCountButtonDef)
        End If
    End Sub

End Class

Sorry I'm not quite familiar with Visual Studio

 

0 Likes
Message 8 of 13

bradeneuropeArthur
Mentor
Mentor

please upload the complete add in as text.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
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:
My 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 !


 


EESignature

0 Likes
Message 9 of 13

Anonymous
Not applicable

I searchd for something to export the whole project as .txt but didn't find a tool.

 

I looked for all files which I can open and copied their content in a text file. Please see the "Text files.rar"

 

I added the StandardAddInServer.vb File seperatly, is this the one you need?

0 Likes
Message 10 of 13

bradeneuropeArthur
Mentor
Mentor
Yes please copy and paste this file only as txt

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
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:
My 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 !


 


EESignature

0 Likes
Message 11 of 13

Anonymous
Not applicable

Alright.

 

There is also the part which you mentioned earlier.

 

Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate

Also lots of (out) commented lines which are still TODO, but I'm not sure what I have to change there

0 Likes
Message 12 of 13

bradeneuropeArthur
Mentor
Mentor
As I can see you have all declarations regarding the buttons and icons disabled.

Why did uou do that?

You need it to declare buttons

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
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:
My 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 !


 


EESignature

0 Likes
Message 13 of 13

bradeneuropeArthur
Mentor
Mentor
Accepted solution

I have change the most crucial things.

Question:

Do you know how add ins work.

The very basic things are missing, so it seems to me that you need training first!!!

 

please let me know what level of understanding you have with add ins programming.

  • No experience
  • little
  • beginner
  • advanced user
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports Microsoft.VisualBasic.Compatibility.VB6

Namespace InventorAddIn1
    <ProgIdAttribute("InventorAddIn1.StandardAddInServer"),
    GuidAttribute("96dccdbb-dabe-4a88-95bf-c292d8b41f9f")>
    Public Class StandardAddInServer
        Implements Inventor.ApplicationAddInServer

        Private WithEvents m_uiEvents As UserInterfaceEvents
        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

            ' TODO: Add button definitions.

            ' Sample to illustrate creating a button definition.
            Dim largeIcon As Inventor.IPictureDisp = IconToIPicture(New System.Drawing.Icon(My.Resources.YourSmallImage, 32, 32))
            Dim smallIcon As Inventor.IPictureDisp = IconToIPicture(New System.Drawing.Icon(My.Resources.YourSmallImage, 16, 16))
            Dim controlDefs As Inventor.ControlDefinitions = g_inventorApplication.CommandManager.ControlDefinitions
            m_sampleButton = controlDefs.AddButtonDefinition("Command Name", "Internal Name", CommandTypesEnum.kShapeEditCmdType, 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.

            '** Sample to illustrate creating a button on a new panel of the Tools tab of the Part ribbon.

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

            '' Get the "Tools" tab.
            Dim toolsTab As RibbonTab = partRibbon.RibbonTabs.Item("id_TabTools")

            '' Create a new panel.
            Dim customPanel As RibbonPanel = toolsTab.RibbonPanels.Add("Sample", "MysSample", AddInClientID)

            '' Add a button.
            customPanel.CommandControls.AddButton(m_sampleButton)
        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

    End Class
End Namespace


Public Module Globals
    ' Inventor application object.
    Public g_inventorApplication As Inventor.Application

#Region "Function to get the add-in client ID."
    ' 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(InventorAddIn1.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
#End Region

#Region "hWnd Wrapper Class"
    ' This class is used to wrap a Win32 hWnd as a .Net IWind32Window class.
    ' This is primarily used for parenting a dialog to the Inventor window.
    '
    ' For example:
    ' myForm.Show(New WindowWrapper(g_inventorApplication.MainFrameHWND))
    '
    Public Class WindowWrapper
        Implements System.Windows.Forms.IWin32Window
        Public Sub New(ByVal handle As IntPtr)
            _hwnd = handle
        End Sub

        Public ReadOnly Property Handle() As IntPtr _
          Implements System.Windows.Forms.IWin32Window.Handle
            Get
                Return _hwnd
            End Get
        End Property

        Private _hwnd As IntPtr
    End Class
#End Region

#Region "Image Converter"

#End Region

End Module

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
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:
My 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 !


 


EESignature

0 Likes