- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have lots of custom tools as VB & macros, I'm trying to improve on them and change them into Addons.
The problem I am having (have been hitting my head against a wall trying to solve this) What I'm trying to do is have an addon that fires when the user creates a new part document. I can have a form open up fine, but I can't get the form to talk to the active inventor part document.
So far I have added this into the StandardAddinServer.Vb section:
Public Sub oAppEvents_OnNewDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles oAppEvents.OnNewDocument Dim oApp As Application = m_inventorApplication Dim Doc As Document = oApp.ActiveDocument If Doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Dim DwgForm As New Form1 DwgForm.Show() End If End Sub
And this code in my form:
Imports Inventor
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.Win32
Imports System.Runtime.InteropServices
Public Class Form1
'Inherits System.Windows.Forms.Form
'Dim form2 As New DimChange
#Region "Data Members"
Private Shared m_inventorApplication As Inventor.Application
'Private Shared form2 As DimChange
#End Region
#Region "Properties"
Public Shared Property InventorApplication() As Inventor.Application
Get
InventorApplication = m_inventorApplication
End Get
Set(ByVal Value As Inventor.Application)
m_inventorApplication = Value
End Set
End Property
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oDoc As Document = InventorApplication.ActiveDocument
End Sub
End Class
But I keep getting the error "Object reference not set to an instance of an object" (Attached)
If anyone can help with this that would be great, like I said it's my first time trying to write an addon, I have gone through the inventor samples and tried to work it out for myself but with no luck.
Solved! Go to Solution.