GetObject(, "Inventor.Application") vs. Marshal.GetActiveObject("Inventor.Application")

GetObject(, "Inventor.Application") vs. Marshal.GetActiveObject("Inventor.Application")

Majjek
Advocate Advocate
3,140 Views
7 Replies
Message 1 of 8

GetObject(, "Inventor.Application") vs. Marshal.GetActiveObject("Inventor.Application")

Majjek
Advocate
Advocate

Hello,

 

I'm just interested, can anyone tell me the difference between the lines below to get an active Inventor application object?

And also is one of them preferred over the other?

 

GetObject(, "Inventor.Application")

vs.

Marshal.GetActiveObject("Inventor.Application")

0 Likes
Accepted solutions (1)
3,141 Views
7 Replies
Replies (7)
Message 2 of 8

Dev_rim
Advocate
Advocate
Accepted solution

Hi Majjek,

The answer can be really boring if you are not interested with inner object structure of Windows. We have multiple differences on these two functions and I will write the things I can remember. If there is any missing one, community can complete the rest.

First, GetObject function is on VB library. It does not means we can't use it in another languages but we have to reach VB6 library to use it on C# for example. (As soon as we are in .NET Framework)

GetActiveObject method is on System.Runtime.InteropServices Library. It's also usable for all .NET products. 

  • Object source:

GetObject method returns an object which provided by an ActiveX component. 

GetActiveObject gets the object from ROT(Running object table).

Inventor files and object are perfectly working with these two system but for other programs, in theory you can not get their object with GetObject method if they are not okay to reach with ActiveX, and also you can not get the object with GetActiveObject if programs session is not on the Running Object Table.

 

  • Capability

 With Marshall class we can get active objects (Marshal.GetActiveObject) and create objects. With GetObject method we can also specify the object we desire to get. For example for a drawing document:

 

Dim CADObject As Object
Set CADObject = GetObject("C:\CAD\SCHEMA.CAD")

 

in this scenario we will get the object itself and activate the file also. Windows will look at extension of the file and decide which object it needs to use.

 

Dim CADObject As Object
Set LayerObject = GetObject("C:\CAD\SCHEMA.CAD!Layer3")

 

In this example as you see we are reaching one of the specific layers of the object. For use it like that you can write ("FILE_PATH!SPECIFICATION")

 

Dim MyObject As Object
Set MyObject = GetObject("C:\DRAWINGS\SAMPLE.DRW", "FIGMENT.DRAWING")

 

In this last scenario, we are also specifying the object type as imaginary drawing viewer app Figment. 

 

At the end there is no differences on performance as soon as we collect garbage. Specially for Marshall Object, its better to collect garbage at the end of the process.

 

I hope these answers will be helpful.

Devrim

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
Message 3 of 8

Majjek
Advocate
Advocate

Hello Devrim,

 

Thanks for your detailed information.

It gives me some more insight in this matter.

Message 4 of 8

DonStauffer99
Advocate
Advocate

Is this a valid workaround to use when ThisApplication isn't available, say in a rule using the straight VB code option in Inventor? It seems to work, but I have no way of knowing if it will always work.

0 Likes
Message 5 of 8

Majjek
Advocate
Advocate

Can you give an example where ThisApplication isn't working?

I'm not really familiar with the Straight VB Code option.

But if you're running code from within Inventor, ThisApplication should always be available as far as I know.

Or if working with Inventor Server/ Design Automation APS, use ThisServer.

0 Likes
Message 6 of 8

mathijs_stevensNMV4V
Explorer
Explorer

If you check Straight VB Code you don't have immediate access to the iLogic functions. Whenever I have a rule with Straight VB Code checked it's usually to be used by other rules. Here's an example of how you can still use the iLogic functions.

 

Rule with Straight VB Code checked:

Public Class Example
	Private Property ThisDoc As ICadDoc
	
	Public Sub New(ThisDoc As ICadDoc)
		Me.ThisDoc = ThisDoc
	End Sub
	
	Public Sub ShowFileName()
		' Show the FileName to show the iLogic functions work
		MsgBox(ThisDoc.FileName)
	End Sub
End Class

Rule that uses the other rule:

AddVbRule "Straight VB Rule"
Dim oExample As New Example(ThisDoc)
	oExample.ShowFileName
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @DonStauffer99.  When your codes are in iLogic rules, you should pretty much never use GetObject or Marchal.GetActiveObject method to get the active/running instance of Inventor.  That should only be used from resources like an external EXE type program (or maybe an Inventor add-in, but I doubt even then).  As @mathijs_stevensNMV4V pointed out, there are ways to 'pass' that object reference to the externally referenced iLogic rule which is using that 'Straight VB Code' option, from the 'regular' rule that is referencing it.

The two most common ways to do this are:

  • Your externally referenced code resource can have a 'Public Property' that the 'calling/referencing' rule can access, and set the value of.
  • Your externally referenced code resource can have methods which ask for those iLogic 'Rule Objects' to be supplied to them, as an 'input parameter' when they are called by the 'regular' rule.
    • The most common iLogic 'Rule Object' to supply to an external resource is the ILowLevelSupport Interface, which is represented by the 'iLogicVb' rule object.  From that rule object, we can access many of the other uniquely iLogic objects.  Additionally, from that object, we an use its CreateObjectProvider method, which asks us for a Document object, then gives an IStandardObjectProvider Interface, which we can use to access most of the other 'Rule Objects'...and all the resulting rule objects will be associated with that supplied Document object.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

DonStauffer99
Advocate
Advocate

I pretty much knew that. I just was wondering because a line or two is a lot simpler, if it works.

0 Likes