Author Topic: global variable?  (Read 1930 times)

0 Members and 1 Guest are viewing this topic.

MexicanCustard

  • Swamp Rat
  • Posts: 705
global variable?
« on: June 27, 2011, 08:23:06 PM »
What's the best way to keep track of things between method calls?

I.E. I'm isolating layers on one method call "IsolateNestedEntities". Then I want to revert the layer's on/off back to pre-isolation "UnIsolateNestedEntities"?

Currently I'm using a global variable,  will this stay the same if the user changes active documents during the session or is a new instance started for each document?
Revit 2019, AMEP 2019 64bit Win 10

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: global variable?
« Reply #1 on: June 27, 2011, 08:36:32 PM »
If is per document storage you're looking for,  have a look at Autodesk.AutoCAD.ApplicationServices.Document.UserData

kaefer

  • Guest
Re: global variable?
« Reply #2 on: June 28, 2011, 04:23:38 AM »
If is per document storage you're looking for,  have a look at Autodesk.AutoCAD.ApplicationServices.Document.UserData

Why do I need the UserData hashtable at all when I can instantiate arbitrary data structures in the constructor of the class containing instance command methods? I.e.
Code: [Select]
    public class MyCommandClass
    {
        MyData myData = null;
        MyCommandClass() {
            mydata = new MyData();
        }

        [CommandMethod("InstanceCommand")]
        public void InstanceCommand() {
            // There's a MyData instance for each Document the command runs in
            ...
        }
    }

kaefer

  • Guest
Re: global variable?
« Reply #3 on: June 28, 2011, 06:08:34 AM »
If is per document storage you're looking for,  have a look at Autodesk.AutoCAD.ApplicationServices.Document.UserData

Why do I need the UserData hashtable at all when I can instantiate arbitrary data structures in the constructor of the class containing instance command methods?

Answering my own question: I need it if I want to know what the UserData for the other Documents is, of course.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: global variable?
« Reply #4 on: June 28, 2011, 07:00:08 AM »
Also, I prefer static command methods over non, there is a bit less overhead when invoking.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: global variable?
« Reply #5 on: June 28, 2011, 08:14:26 AM »
Thanks guys! That answers my question.

Doing a search on UserData I found this:
http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_1.html
Revit 2019, AMEP 2019 64bit Win 10