Per document global vars using .net API
My goal is to create a .net object I can re-use in each drawing. The creation process of my objects is not trivial (tin surfaces), so its not an option to reload every time needed.
I originally wrote the program for autocad, now am adapting for bricscad. I kind of expect the API's to behave the same, and I would guess the intent of Bricsys is to do that, so likey have come accross an accidental difference.
In autocad, you can make per drawing ,net objects by simply declaring a class as non-static. This is explained in: http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_1.html
so my class looks like:
[assembly: CommandClass(typeof(CTCivilXtra.LispCommands))]
namespace CTCivilXtra {
public class LispCommands {
public TinSurfaceBase Surf1;
//this next line added because bcad does not seem to recognize lispfunctions unless I do it????why?????
private Database db = AcAp.DocumentManager.MdiActiveDocument.Database;
[LispFunction("LispLoadSurfFromFile")]
public ResultBuffer LispLoadSurfFromFile(ResultBuffer args) { code clipped....}
}
Comments
-
so I tried a couple things, one thing seems to work.
Make the global variables as static (not the class though), like:
static public TinSurfaceBase Surf1;
I guess I see now that static vars within a non-static class, are "shared" within a prog. I knew this book-wise, but have never needed it before.
I am still wondering why i need that db reference. It took me 4 hours of narrowing down why one of my progs with lispfuctions worked in bcad, and one did not. It turns out the one that worked had some code that collected acad layers when it started so I figured out that was the key.
I am now having trouble with transient entity display, another thread....
0 -
You can use Document.UserData for storing per document information0