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
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 -
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.
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.
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,
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?
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.MdiActiveDocumen
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.
Norman Yuan
Can't find what you're looking for? Ask the community or share your knowledge.