Inventor Add in - reference active document in form button

Inventor Add in - reference active document in form button

Anonymous
Not applicable
1,133 Views
7 Replies
Message 1 of 8

Inventor Add in - reference active document in form button

Anonymous
Not applicable

Hello,

 

I've created an add-in using Inventor 2017 addin template with a basic form. The addin loads fine and I'm getting the form to appear. I'm going to have various buttons on the form that each add a custom iProperty. How do I declare the active document and custom prop set globally to use in each buttons sub.

 

I thought this would work but it not...

 

 

Imports Inventor

Public Class Form1

 

Dim oDoc As Document = g_inventorApplication.ActiveDocument
Dim oCustomPropertySet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
Dim prop As Inventor.Property

 

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

 Try
prop = oCustomPropertySet.Item("SAW")
Catch
oCustomPropertySet.Add("5", "SAW")
End Try

End Sub

 

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

Try

prop = oCustomPropertySet.Item("PUNCH")

Catch

oCustomPropertySet.Add("10", "PUNCH")

End Try

End Sub
End Class

0 Likes
1,134 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor
You need to give the inventorapplication of the add in to the form. Do this at new form and declare g_inventorApplication as inventor.application.

Hope this helps.

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 8

Anonymous
Not applicable

Could you give an example please? I'm struggling to understand where to do this

 

Is it here?

 

Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer

Private WithEvents m_uiEvents As UserInterfaceEvents
Private WithEvents m_sampleButton As ButtonDefinition
Dim MyForm As New Form1

0 Likes
Message 4 of 8

bradeneuropeArthur
Mentor
Mentor

 

Take a look.

Hope this explains.

Your form needs to know what the application is so you need to provide it from the add-in.

You understand now?

 

' this should be added to your add in:

Private _Form1 as Form1

'and this too with the m_inventorApplication as inventor app from the add in

_Form1 = New Form1(m_inventorApplication)

'this should be added to your form:
Public Class Form1

    Public m_InventorApplication As Inventor.Application

Public Sub New(InventorApp As Inventor.Application)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        m_InventorApplication = InventorApp

    End Sub
end class

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 5 of 8

Anonymous
Not applicable

Sorry I've tried a few things but still not getting it. Could you have a look at my two scripts attached, I've stripped them back to what I had originally.

0 Likes
Message 6 of 8

bradeneuropeArthur
Mentor
Mentor

Replace this:

Namespace AddOperations
    <ProgIdAttribute("AddOperations.StandardAddInServer"), _
    GuidAttribute("4273d4c1-ecdc-48da-a321-1e3e730949e7")> _
    Public Class StandardAddInServer
        Implements Inventor.ApplicationAddInServer

        Private WithEvents m_uiEvents As UserInterfaceEvents
        Private WithEvents m_sampleButton As ButtonDefinition
        
        Dim MyForm As  Form1

#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

		Dim MyForm As  Form1(g_inventorApplication)

......
......
end sub

 

Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute            'MsgBox("Button was clicked.")            MyForm.ShowDialog()                   End Sub

 

 

 

 

 

 

 

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 8

bradeneuropeArthur
Mentor
Mentor

sorry button coding was not visible I see.

 

Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute
            'MsgBox("Button was clicked.")

            MyForm.ShowDialog()
            

        End Sub

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 8 of 8

bradeneuropeArthur
Mentor
Mentor

and in the form with this:

 

Imports Inventor
Imports System.Windows.Forms

Public g_InventorApplication As Inventor.Application

Public Class Form1

Public Sub New(H_inventorApplication as inventor.application)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
G_inventorApplication =H_inventorApplication
End Sub
    Dim newpoint As New System.Drawing.Point
    Dim x, y As Integer

    Private Sub Panel1_MouseDown(sender As Object, e As Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
        x = MousePosition.X - Me.Location.X
        y = MousePosition.Y - Me.Location.Y
    End Sub

    Private Sub Panel1_MouseMove(sender As Object, e As Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            newpoint = MousePosition
            newpoint.X -= (x)
            newpoint.Y -= (y)
            Me.Location = newpoint
        End If
    End Sub

    Private Sub CloseButton_Click(sender As Object, e As EventArgs) Handles CloseButton.Click
        Close()
    End Sub

    Private Sub Add_BOND_Click(sender As Object, e As EventArgs) Handles Add_BOND.Click
        Dim oDoc As Document = g_inventorApplication.ActiveEditDocument
        Dim oCustomPropertySet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")

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