Posts: 16
Registered: ‎06-24-2010
Message 1 of 5 (739 Views)


739 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*
Posts: 9,216
Registered: ‎06-29-2007
Message 2 of 5 (721 Views)

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
Posts: 16
Registered: ‎06-24-2010
Message 3 of 5 (702 Views)

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
Posts: 8
Registered: ‎07-22-2013
Message 4 of 5 (332 Views)

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*
Posts: 2,104
Registered: ‎04-29-2006
Message 5 of 5 (299 Views)

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
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.