Sie sind auf Seite 1von 4

Per-document data in AutoCAD .

NET applications - Part 1 - Through the Interface


http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_1.html[21/01/2014 16:49:37]
Translate this page Spanish
Microsoft

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 ObjectARX | Main | Per-document data in AutoCAD
.NET applications - Part 2
October 12, 2006
Per-document data in AutoCAD .NET applications - Part 1
The last few posts have focused on the history of MDI in AutoCAD and how to
store per-document data in ObjectARX applications. Now lets take a look at what
can be done for AutoCAD .NET applications...
There are two main approaches for storing per-document data in managed
applications loaded into AutoCAD Ill take a look at the first in this entry and
tackle the second technique next time.
Define commands as instance members of a class
In managed applications you can declare instance or static methods. Static
methods are those specified as static in C#or Shared in VB.NET. Methods that
are not shared/static are known as instance methods.
Static methods are global they do not use data that is specific to an instance
of the class they belong to. Its common to call static methods directly from the
class namespace (MyClass.myMethod()) rather than from specific instance of the
class (myObject.myMethod()). To declare a method as static, you use the static
keyword in C#and the Shared keyword in VB.NET.
Predictably enough, MSDN contains some good information on static classes and
static class members.
Instance methods can be considered local in scope they work on a specific
instance of a class. A method not declared as static/Shared will be an instance
method by default.
So what does this mean for us, as implementers of AutoCAD commands in .NET?
Heres what the documentation says:
"For an instance command method, the method's enclosing type is
instantiated separately for each open document. This means that
each document gets a private copy of the command's instance data.
Thus there is no danger of overwriting document-specific data when
the user switches documents. If an instance method needs to share
data globally, it can do so by declaring static or Shared member
variables."
So to get the benefits of per-document data in a .NET application, you simply
need to declare the relevant command(s) as instance (non-static). Heres some
sample C#code defining two separate commands: one is declared as static
(accessing static data and even contained within a static class) while the other is
an instance method:
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 ;
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

Accessing the active
space or layout in an
AutoCAD drawing using
.NET
Loading blocked and
network-hosted
assemblies with .NET 4
My AU 2008
Using AutoCAD to debug
external ray-tracing
routines
Exposing AutoCAD's
Properties Palette
functionality to .NET - Part
1
At AU 2010
AU 2010 Handout:
Integrate F#into Your C#
or VB.NET Application for
an 8x Performance Boost
AU 2008 class schedule
published
Returning data from .NET
to J avaScript inside
AutoCAD
Kinect for Xbox One
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
Spanish

Per-document data in AutoCAD .NET applications - Part 1 - Through the Interface


http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_1.html[21/01/2014 16:49:37]
A U T O D E S K B L O G S
AutoCAD Insider
Between the Lines
It's Alive in the Lab
Mod the Machine
The Building Coder
It's All J ust Ones and Zeros
Dances with Elephants
AutoCAD DevBlog
Cloud and Mobile DevBlog
AEC DevBlog
Manufacturing DevBlog
Infrastructure Modeling DevBlog
Around the Corner
More on autodesk.com...
[ assembl y: CommandCl ass( t ypeof ( CommandCl asses. Fi r st Cl ass ) ) ]
[ assembl y: CommandCl ass( t ypeof ( CommandCl asses. SecondCl ass) ) ]
namespace CommandCl asses
{
st at i c publ i c cl ass Fi r st Cl ass
{
pr i vat e st at i c i nt count er = 0;
[ Aut odesk. Aut oCAD. Runt i me. CommandMet hod( " gl ob" ) ]
publ i c st at i c voi d gl obal ( )
{
Edi t or ed = Appl i cat i on. Document Manager . Mdi Act i veDocument . Edi t or ;
ed. Wr i t eMessage( " \ nCount er val ue i s: " + count er ++) ;
}
}
publ i c cl ass SecondCl ass
{
pr i vat e i nt count er = 0;
[ Aut odesk. Aut oCAD. Runt i me. CommandMet hod( " l oc" ) ]
publ i c voi d l ocal ( )
{
Edi t or ed = Appl i cat i on. Document Manager . Mdi Act i veDocument . Edi t or ;
ed. Wr i t eMessage( " \ nCount er val ue i s: " + count er ++) ;
}
}
}
Heres what happens when you execute the two commands in two separate
documents:
[From first drawing...]
Command: gl ob
Count er val ue i s: 0
Command: gl ob
Count er val ue i s: 1
Command: gl ob
Count er val ue i s: 2
Command: l oc
Count er val ue i s: 0
Command: l oc
Count er val ue i s: 1
Command: l oc
Count er val ue i s: 2
Command: new
[From second drawing...]
Command: gl ob
Count er val ue i s: 3
Command: gl ob
Count er val ue i s: 4
Command: gl ob
Count er val ue i s: 5
Command: l oc
Count er val ue i s: 0
Command: l oc
Count er val ue i s: 1
Command: l oc
Count er val ue i s: 2
Exchange AutoLISP /
Visual LISP Azure Batch
processing Blocks Books
Civil 3D Commands
Concurrent programming
Conferences Core
Console Custom objects
Database Debugging
Design DesignScript
DevCasts DevTV
Dimensions Documents
Draw order Drawing
structure DWF Dynamic
Dynamic Blocks Excel
F# Facebook Fields
Fractals Freewheel
Games Geometry
Graphics system
Hatches HTML
Installation Instructables
Interviews Inventor iOS
IronPython IronRuby
J ava J avaScript J igs
J SON Kinect Leap
Motion LINQ Mac
Mobile Morgan Netduino
Notification / Events
Object properties
ObjectARX Overrules
Personal Plotting Plugin
of the Month Point
clouds Purge Python
Raspberry Pi RealDWG
Reality capture REST
Retro computing Revit
Robotics Ruby Runtime
SaaS Security
Selection Social media
Solid modeling Tables
Tinkercad Training
Transactions Translation
Travel Unity3D User
interface Visual Basic &
VBA Visual Studio
Web/Tech Weblogs
WinRT WPF XML
R E C E N T
P O S T S
Previewing geometry as it
streams into AutoCAD
using .NET
Leaving Israel
Impressions of Tel Aviv
Forcing AutoCAD object
snapping using .NET
Update on purging DGN
linestyles from AutoCAD
drawings using .NET
AU 2013 classes available
on-demand
Attack of the robots
Happy 2014
Merry Christmas!
Moving text in an
AutoCAD block using
.NET Part 3
R E C E N T
C O M M E N T S
Kean Walmsley on Taking
Per-document data in AutoCAD .NET applications - Part 1 - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_1.html[21/01/2014 16:49:37]
Comments
Comment below or sign in with Typepad Facebook Twitter Google+
and more...
(You can use HTML tags like <b> <i> and <ul> to style your text. URLs
automatically linked.)
Email address is not displayed with comment.

So you can see that when you create and switch to a new document, the glob
command (a static method) continues counting from where it left off. The loc
command (an instance method) starts from zero, as a new instance of its
command class has been created.
If you choose to mix static and instance methods & data in your class, then you
will need to be a little careful about making sure the data gets initialized at the
right time and place. In the above example Ive kept things separate and have
simply used variable initialization to specify the initial values for the two counters
you will probably want to define your own constructors (static or instance) if you
have more complex scenarios to deal with.
In my next post Ill take a look at the Document.UserData container, the
alternative approach to managing per-document data in an AutoCAD .NET
application.
You might also like:
Per-document data in AutoCAD .NET applications - Part 2
Per-document data in ObjectARX
Some background to AutoCAD's MDI implementation and per-document data
Initialization code in your AutoCAD .NET application
Linkwithin
Posted at 06:12 PM in AutoCAD, AutoCAD .NET | Permalink
TrackBack
TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83452464869e200d83535ab6253ef
Listed below are links to weblogs that reference Per-document data in AutoCAD
.NET applications - Part 1:
a screenshot of a user-
selected portion of a
drawing using .NET
Dominik Hepp on Taking
a screenshot of a user-
selected portion of a
drawing using .NET
Kean Walmsley on First
impressions of Kinect for
Windows 2.0 pre-release
Andrew on First
impressions of Kinect for
Windows 2.0 pre-release
Kean Walmsley on
Adding to AutoCADs
Application Menu and
Quick Access Toolbar
using .NET
Dharmarajan on Adding to
AutoCADs Application
Menu and Quick Access
Toolbar using .NET
Kean Walmsley on
Updating a specific
attribute inside an
AutoCAD drawing using
.NET
Kean Walmsley on
AutoCAD DGN Hotfix now
available
Greg Robinson on
Gathering points defining
3D AutoCAD geometry
using .NET
Kean Walmsley on
AutoCAD 2014 for
developers
A R C H I V E S
J anuary 2014 (8)
December 2013 (9)
November 2013 (13)
October 2013 (13)
September 2013 (13)
August 2013 (14)
J uly 2013 (14)
J une 2013 (12)
May 2013 (14)
April 2013 (13)
March 2013 (12)
February 2013 (12)
J anuary 2013 (15)
December 2012 (12)
November 2012 (13)
October 2012 (14)
September 2012 (12)
August 2012 (13)
J uly 2012 (9)
Name
Email Address
Web Site URL
Post Preview
Per-document data in AutoCAD .NET applications - Part 1 - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_1.html[21/01/2014 16:49:37]
J une 2012 (13)
More...

Das könnte Ihnen auch gefallen