.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GetAcadDocument

6 REPLIES 6
Reply
Message 1 of 7
Pfilc
2648 Views, 6 Replies

GetAcadDocument

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

 

2012 code:

ThisDrawing = DocumentManager.MdiActiveDocument.AcadDocument

 

2013:

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.

 

Thanks,

Phil

6 REPLIES 6
Message 2 of 7
Alfred.NESWADBA
in reply to: Pfilc

Hi,

 

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 7
Pfilc
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.

Message 4 of 7
jrenatto
in reply to: Pfilc

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.

Message 5 of 7
_gile
in reply to: jrenatto

Hi,

 

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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 7
cadcamm99
in reply to: _gile

Gilles,

I am moving over my VB app to C#. 

 

I used this in VB

 

Public ReadOnly Property ThisDrawing() as AcadDocument

     Get

          Return

               Core.Application.DocumentManager.MdiActiveDocument.GetAcadDocument()

     End Get

End Property

 

then in a different sub

ThisDrawing.ObjectSnapMode = False  

 

 

However I couldn't do this in C# so I tried:

 

private readonly Document roDocument = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;

 

public object ThisDrawing
{
     get
     {
          return roDocument.GetAcadDocument();
     }
}

 

then in a different sub

ThisDrawing.ObjectSnapMode = False   - however ObjectSnapMode does not come up.

 

Do you have any ideas?

Message 7 of 7
norman.yuan
in reply to: cadcamm99

Your C# code

 

public object ThisDrawing
{
     get
     {
          return roDocument.GetAcadDocument();
     }
}

 

is not exactly equivalent to the original VB.NET code:

 

Public ReadOnly Property ThisDrawing() as AcadDocument

     Get

          Return

               Core.Application.DocumentManager.MdiActiveDocument.GetAcadDocument()

     End Get

End Property

 

In the VB.NET code, the property ThisDrawing is a type of AcadDocument (you must had reference to AutoCAD's COM API), while in the C# code, the same property ThisDrawing is type of object, thus you cannot have code like ThisDrawing.ObjectSnapMode=..... To make the C# code the same as VB.NET, you need to add reference to AutoCAD COM API and expose the property ThisDrawing as AcadDocument.

 

BTW, unless it is really necessary, in most cases, there is no need to mix COM APIs in the .NET API development, especially the VBA style of "ThisDrawing" shown in various code examples available on the net is bad-taste code used in AutoCAD .NET API programming, IMO.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost