Add-in equivalent of iLogic's "SharedVariable"

Add-in equivalent of iLogic's "SharedVariable"

DRoam
Mentor Mentor
951 Views
4 Replies
Message 1 of 5

Add-in equivalent of iLogic's "SharedVariable"

DRoam
Mentor
Mentor

In iLogic, I can create a SharedVariable to store values during the current session. These variables are shared (accessible by all iLogic scripts) and persist during the entire Inventor session.

 

I'm wondering how to do something equivalent to this but in an add-in. I'm writing a couple of add-ins that have a bit of functionality overlap, and I need them to be able to "talk" to each other by checking some application-global variables. These variables should last until the Inventor session is closed.

 

@MjDeck, can you shed some light on how the SharedVariables work under the hood, and how to emulate that with straight VB code?

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

MjDeck
Autodesk
Autodesk

Well, iLogic is just one add-in, and the SharedVariables are only visible in iLogic rules. So this would be beyond what iLogic does. But yes, you can do it.

The SharedVariable storage is a generic .NET Dictionary(Of String, Object)

To make an object like that visible to another add-in, you could put it in a common or base add-in. That add-in would be required by the other ones. Declare a public Shared (or static in C#) object in the base add-in.
In the Visual Studio project for the other add-ins, add a Reference to the compiled DLL from the base. Then you'll be able to see that static object in the other add-in and use it in code.
Add a check to see if it's Nothing (null in C#). That will prevent your code from throwing an exception at runtime if the base add-in is not loaded.

There are other ways to do something like this, but this is a .NET-only way that will give you the ability to share any .NET object.


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 5

DRoam
Mentor
Mentor

@MjDeck wrote:

Well, iLogic is just one add-in, and the SharedVariables are only visible in iLogic rules. So this would be beyond what iLogic does.


Ahh, I didn't even think of that. Great point.

 

But the method you shared should work just fine. I'll give that a try.

0 Likes
Message 4 of 5

DRoam
Mentor
Mentor

Just to make sure, so there's no way to store a variable "on" or "inside" the Inventor application instance itself? For example, we have AttributeSets on various Inventor objects such as documents. Is there anything like that on the Application object that I could access?

0 Likes
Message 5 of 5

MjDeck
Autodesk
Autodesk

There's no AttributeSets on the application object. But you could create a Transient AttributeSet on a document. At any given time, every add-in can see the same documents.

Another .NET method might be AppDomain.SetData and AppDomain.GetData. I've used that a bit for individual strings and integers.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes