Professional Documents
Culture Documents
Translator
K E A N W A L M S L E Y
About the Author
Kean on Google+
J A N U A R Y 2 0 1 4
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
P O S T I N D E X
R E V E R S E I N D E X
Per-document data in AutoCAD .NET applications - Part 1 | Main | A quick
Visual Studio tip - automatically implement interfaces in C#
October 19, 2006
Per-document data in AutoCAD .NET applications - Part 2
This entry completes the series of posts about per-document data. Here are the
previous entries:
Some background to AutoCAD's MDI implementation and per-document data
Per-document data in ObjectARX
Per-document data in AutoCAD .NET applications - Part 1
Document.UserData
Now let's take a look at a second technique in .NET for storing transient (non-
persisted) data with an AutoCAD document, the UserData property. The managed
framework for AutoCAD associates a hash table with each document, which can
be accessed using the UserData property. Hash tables are a great way to store
and access data quickly: each object you store in a hash table is associated with
a particular key, or lookup value. You then use this key to get at the data you've
stored in the hash table.
The UserData property returns an object of the standard .NET class,
System.Collections.Hashtable, so its advised to look on MSDN for further
examples of usage.
I've written some code to demonstrate how you might store and access per-
document data in the UserData property. The below C#code declares and
implements a simple class called MyData to store custom data, and then two
commands that store data in and use data from the UserData hash table.
The inc command checks whether theres an object under a particular
key, and if not, it creates and adds a MyData object. It then goes on to
increment the integer value stored in that object (and therefore in the
hash table)
The bogus command has some fun with the hash table, storing a
bogus object (a Point2D object) in the place where the "inc" command
expects to find a MyData object. This can only be run on a fresh
drawing one that has not had inc executed otherwise there will
already be an object stored in the hash table
Here's the code:
usi ng Aut odesk. Aut oCAD. Appl i cat i onSer vi ces;
usi ng Aut odesk. Aut oCAD. Runt i me;
usi ng Aut odesk. Aut oCAD. Edi t or I nput ;
usi ng Aut odesk. Aut oCAD. Geomet r y;
usi ng Syst em. Col l ect i ons;
[ assembl y: CommandCl ass( t ypeof ( CommandCl asses. User Dat aCl ass) ) ]
1 0 R A N D O M
P O S T S
F E E D / S H A R E
Subscribe via RSS
ShareThis
676 Like
S E A R C H
Drawing transient graphics
appropriately in AutoCAD
within multiple paperspace
viewports using .NET
Announcing DevBlogs
from ADN
Smoothly transitioning
between 3D AutoCAD
views using .NET - Part 2
Septembers Plugin of the
Month live on Autodesk
Labs: TransTips
Creating an AutoCAD
block using .NET
Inserting a specific Excel
sheet as an AutoCAD
table using .NET
Going West
Looking for API
developers to work with
Project Draw
This one made me smile...
Sectioning an AutoCAD
solid using F#
C A T E G O R I E S
3D printing 3ds Max
AJ AX Android Annotation
scaling Arduino
ASP.NET Async AU
Augmented Reality
AutoCAD
AutoCAD
.NET AutoCAD OEM
Autodesk Autodesk
Exchange AutoLISP /
Visual LISP Azure Batch
Spanish