Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ThisApplication in VB .Net ?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
TONELLAL
2675 Views, 6 Replies

ThisApplication in VB .Net ?

Hello,

I have a question which shouild be very simple for programmers...

I create an add-in with VB .Net 2012, which use a form. When I click on a button, I launch a sub in another module.

How can I have, in this sub, the equivalent of ThisApplication in VBA ? I think I have to get the active Inventor, but I missed something... For the moment, when I debug, the add-in ends on " m_inventorApplication = addInSiteObject.Application".

   

Sub renum(ByVal direction AsString)

       

Dim m_inventorApplication As Inventor.Application

Dim oDoc AsDrawingDocument

 

        m_inventorApplication = addInSiteObject.Application

        oDoc = m_inventorApplication.ActiveDocument

 

'.............

 

End Sub

 

 

 

PrivateFunction addInSiteObject() AsObject

 ThrowNewNotImplementedException   

End Function

6 REPLIES 6
Message 2 of 7
Ralf_Krieg
in reply to: TONELLAL

Hello

 

Paste following code in your form right under Public class ....

 

Private m_inventorApp As Inventor.Application

    Public Property InventorApplication() As Inventor.Application
        Get
            Return m_inventorApp
        End Get
        Set(ByVal value As Inventor.Application)
            m_inventorApp = value
        End Set
    End Property

 So you can access m_inventorApp elsewhere in your Sub's.


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
Message 3 of 7
planglais75
in reply to: TONELLAL

I work with Inventor 2011 and VB.Net 2010, so I hope it's work the same.

 

In the StandardAddInServer class add a property and initialise it in the Activate sub:

 

' Inventor application object
Property InventorApplication As Inventor.Application

Public Sub Activate(ByVal addInSiteObject As ApplicationAddInSite, ByVal firstTime As Boolean) Implements ApplicationAddInServer.Activate
            ' Initialize application object
            Me.InventorApplication = addInSiteObject.Application

...
End Sub

When you instantiate the form, you must do something like this:

Dim myForm as new Form1
myForm.Show

 In the Form1 code, create the same property, as above, for the Inventor application and before showing the form, set this property:

Dim myForm as new Form1
myForm.InventorApplication = Me.InventorApplication
myForm.Show

 You can now work with Me.InventorApplication anywhere in the Form1 class code.

 

 

Pascal

Message 4 of 7
TONELLAL
in reply to: planglais75

Thanks for your answers !

Krieg, your solution provoque a CER...

I found another solution :

In the module code : 

 

Imports System.Runtime.InteropServices

m_inventorApplication = Marshal.GetActiveObject("Inventor.application")

 

What is the difference ?

Message 5 of 7
planglais75
in reply to: TONELLAL

The Marshal.GetActiveObject method will return an instance of the application.  If you have more than once, you don't know which one it will returns.

 

If you have only one instance, it will works but I use this method only when I don't have choice.  By example, when I create an EXE application and I want to instantiate the Inventor.Application object.

 

Pascal

Message 6 of 7
ekinsb
in reply to: TONELLAL

Here's what I do in an add-in so I have access to the Inventor Application object from anywhere in the project.

 

I add the code below in one of the files of the project.  Often this will be in the .vb file where the add-in class is defined.  This code goes at the very bottom of the file, even outside the Namespace.

 

Public Module Globals
    Public g_inventorApplication As Inventor.Application
End Module

 

Next I delete the declaration of m_inventorApplication at the top of the add-in class and rename m_inventorApplication to g_inventorApplication wherever it was used.  I could even skip the renaming step if I left the "m_" name but I like identifying the name as being a global variable.  In either case I need to delete the declaration at the top of the class. 

 

Now anywhere in the project where you need to use the Application object you can use g_inventorApplication.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7
TONELLAL
in reply to: ekinsb

Thanks to everyone for the answers ! It's clearer now.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report