16 Posts
3 Kudos
Registered: ‎06-24-2010
Post 1 of 5


779 Views, 4 Replies
03-28-2012 04:31 PM

I'm having trouble trying to get the GetAcadDocument method to work.


2012 code:

ThisDrawing = DocumentManager.MdiActiveDocument.AcadDocument



ThisDrawing = DocumentExtension.GetAcadDocument(Application.DocumentManager.MdiActiveDocument)


Produces a run time error.  I know just enough .net to brute force my app to do what I want and would appreciate any help.




*Expert Elite*
9,809 Posts
1,210 Kudos
Registered: ‎06-29-2007
Post 2 of 5

Re: GetAcadDocument

03-28-2012 11:29 PM in reply to: phil



for me it's running (it used time to find the alternative to .AcadDocument but with the method same to yours it's working for me. How is ThisDrawing declared at your code, what runtime-error do you get exactly?


- alfred -

Ingenieur Studio HOLLAUS ... www.hollaus.at
16 Posts
3 Kudos
Registered: ‎06-24-2010
Post 3 of 5

Re: GetAcadDocument

03-29-2012 08:44 AM in reply to: Alfred.NESWADBA

Thanks for the response Alfred...confirming the code was ok made me look for a more fundamental problem and I realized I had a bad reference.

Active Member
8 Posts
0 Kudos
Registered: ‎07-22-2013
Post 4 of 5

Re: GetAcadDocument

07-26-2013 08:25 AM in reply to: phil

Greetings, I have the same problem you had, I would like you to help me solve mine, with some questions
. How did you fix it?
- Versiond and vb.net What did you use?
- What version of AutoCAD are you?
- What references did you use?

I await your reply, thanks.

*Expert Elite*
2,140 Posts
253 Kudos
Registered: ‎04-29-2006
Post 5 of 5

Re: GetAcadDocument

07-28-2013 03:50 AM in reply to: jrenatto



Just a little precision about GetAcadDocument() method.


It's an extension method which extents the Document type (defining extension isn't exactly the same with C# or VB).


Extension methods can be called both way (assuming doc = MdiActivedocument):


- as static (Shared) methods as shown upper:

ThisDrawing = DocumentExension.GetAcadDocument(doc)


- as instance methods of the extended type:

ThisDrawing = doc.GetAcadDocument():


The second one will directly work with C# because DocumentExtension is a class of the ApplicationServices namespace.

But with VB extension methods have to be defined in a Module, so, the DocumentExtension module have to be imported for this behavior to be available.

Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

Gilles Chanteau
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!