VB Public variable of inventor app is not read from other subs.

VB Public variable of inventor app is not read from other subs.

JBEDsol
Collaborator Collaborator
474 Views
4 Replies
Message 1 of 5

VB Public variable of inventor app is not read from other subs.

JBEDsol
Collaborator
Collaborator

So I start w/ this, I'm using VB.net through Visual studio

 

Imports System
Imports System.Type
Imports System.Activator
Imports System.Runtime.InteropServices
Imports Inventor
'Imports AutoCAD
Imports System.Windows.Forms

 

Module GlobalVariables

     Public _invApp As Inventor.Application

End Module

 

Then I added

 

Private Sub Get_Volumes_Click_1(sender As Object, e As EventArgs) Handles Get_Volumes.Click
    Dim ptCurrent As _invapp.ActiveDocument

    Dim mpropProp As Inventor.MassProperties
        mpropProp = ptCurrent.componentdefinition.massproperties

End Sub

 

_invApp is used on other subs in the class but for some reason I can't get the new button's code to recognize _invApp.

 

Anyone know what I did wrong?

0 Likes
475 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

I think your issue is you are trying to Dim ptCurrent As _invapp.ActiveDocument, where .ActiveDocument get/sets the active inventor document and isn't an object type. I think you are looking for. 

Dim ptCurrent As Document = _invapp.ActiveDocument

 

0 Likes
Message 3 of 5

JBEDsol
Collaborator
Collaborator

That is a good point, need to fix my code.  

 

However the problem I'm having is before that.  _invApp should be recognized as an application but it's not recognized.  I'm not sure why the public application declared can't be found, it should be seen as a public variable but it's not.  

0 Likes
Message 4 of 5

Anonymous
Not applicable

Can you post the error you are getting?

 

Also do you have something that is connecting the Inventor Application to your object? Because based on the code you posted, you are but defining _invApp as Inventor.Application but aren't assigning the actual application to it. So _invApp is typed as Inventor.Application but doesn't actually contain the application itself so .ActiveDocument won't find anything

 

Something like this, although I'm not sure how it works for global variables.

 

Dim _invApp as Inventor.Application = Get_invApp()

Function Get_invApp()
		Dim oinvApp As Inventor.Application
		Try
			oinvApp = Marshal.GetActiveObject("Inventor.Application")
			Return oinvApp 
		Catch ex2 As Exception
			MsgBox(ex2.ToString())
			MsgBox("Unable to get or start Inventor")
			Return Nothing
		End Try
	End Function

 

 

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Based on some searching it could be an issue with how you are defining a global variable. I'm not familiar with it myself but I will post some threads that go into it.

 

Thread 1 

Thread 2 

0 Likes