<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: VB Public variable of inventor app is not read from other subs. in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9598416#M61669</link>
    <description>&lt;P&gt;Can you post the error you are getting?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this, although I'm not sure how it works for global variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jun 2020 12:54:28 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-06-24T12:54:28Z</dc:date>
    <item>
      <title>VB Public variable of inventor app is not read from other subs.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9596955#M61666</link>
      <description>&lt;P&gt;So I start w/ this, I'm using VB.net through Visual studio&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imports System&lt;BR /&gt;Imports System.Type&lt;BR /&gt;Imports System.Activator&lt;BR /&gt;Imports System.Runtime.InteropServices&lt;BR /&gt;Imports Inventor&lt;BR /&gt;'Imports AutoCAD&lt;BR /&gt;Imports System.Windows.Forms&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Module GlobalVariables&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Public _invApp As Inventor.Application&lt;/P&gt;&lt;P&gt;End Module&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I added&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Private Sub Get_Volumes_Click_1(sender As Object, e As EventArgs) Handles Get_Volumes.Click&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Dim ptCurrent As _invapp.ActiveDocument&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim mpropProp As Inventor.MassProperties&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mpropProp = ptCurrent.componentdefinition.massproperties&lt;/P&gt;&lt;P&gt;End Sub&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;_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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone know what I did wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 20:15:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9596955#M61666</guid>
      <dc:creator>JBEDsol</dc:creator>
      <dc:date>2020-06-23T20:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: VB Public variable of inventor app is not read from other subs.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9596989#M61667</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I think your issue is you are trying to Dim&amp;nbsp;ptCurrent As _invapp.ActiveDocument, where .ActiveDocument get/sets the active inventor document and isn't an object type. I think you are looking for.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dim&amp;nbsp;ptCurrent As Document = _invapp.ActiveDocument&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 20:26:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9596989#M61667</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-23T20:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: VB Public variable of inventor app is not read from other subs.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9598375#M61668</link>
      <description>&lt;P&gt;That is a good point, need to fix my code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the problem I'm having is before that.&amp;nbsp; _invApp should be recognized as an application but it's not recognized.&amp;nbsp; 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.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 12:34:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9598375#M61668</guid>
      <dc:creator>JBEDsol</dc:creator>
      <dc:date>2020-06-24T12:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: VB Public variable of inventor app is not read from other subs.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9598416#M61669</link>
      <description>&lt;P&gt;Can you post the error you are getting?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this, although I'm not sure how it works for global variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 12:54:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9598416#M61669</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-24T12:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: VB Public variable of inventor app is not read from other subs.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9598485#M61670</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/22738243/how-would-i-declare-a-global-variable-in-visual-basic" target="_blank" rel="noopener"&gt;Thread 1&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/4529862/declare-global-variables-in-visual-studio-2010-and-vb-net" target="_blank" rel="noopener"&gt;Thread 2&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 13:17:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vb-public-variable-of-inventor-app-is-not-read-from-other-subs/m-p/9598485#M61670</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-24T13:17:58Z</dc:date>
    </item>
  </channel>
</rss>

