TheSwamp

Code Red => .NET => Topic started by: TR on August 18, 2005, 09:42:41 AM

Title: DocumentManager.MdiActiveDocument
Post by: TR on August 18, 2005, 09:42:41 AM
Can someone explain something to me?

I am trying to get the active document in AutoCAD using C#. To do this I am using:
Code: [Select]
Document doc = Autodesk.AutoCAD.ApplicationServices.DocumentManager.MdiActiveDocument;
To me this seems as if it should work as I am declaring the variable doc as a Document and assigning it as the active document in AutoCAD (MdiActiveDocument returns a Document). However when I try to compile my code I get an error stating.
Quote
c:\Documents and Settings\TJRiley\My Documents\SharpDevelop Projects\KSSetup\MainForm.cs(239,30): error CS0120: An object reference is required for the nonstatic field, method, or property 'Autodesk.AutoCAD.ApplicationServices.DocumentManager.MdiActiveDocument'


Can someone please explain to me what this error message means?

Thanks,
Tim
Title: DocumentManager.MdiActiveDocument
Post by: TR on August 18, 2005, 02:02:13 PM
I'm an idiot.

Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

not

Autodesk.AutoCAD.ApplicationServices.DocumentManager.MdiActiveDocument
Title: DocumentManager.MdiActiveDocument
Post by: Draftek on August 18, 2005, 02:09:06 PM
good catch, I was trying this and I was use "Application." without the namespaces and it worked okay too.

You will also get that error if your 'static' declaration of the variable does not match the method it's used in. I forget to do this sometimes when declaring objects outside of a static command method.
Title: DocumentManager.MdiActiveDocument
Post by: TR on August 18, 2005, 03:01:22 PM
I was trying to use "Application" too but it I was getting:'Application' is an ambiguous reference, so I decided to add the full path.
Title: DocumentManager.MdiActiveDocument
Post by: Kerry on August 18, 2005, 05:39:41 PM
One way to do it
... though it's nothing special and you've probably seen this
Code: [Select]

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

..
..
static public void
whatever()
{
Document pDoc = AcadApp.DocumentManager.MdiActiveDocument;
Database pDb  = pDoc.Database;
Editor pEd  = pDoc.Editor;

Title: DocumentManager.MdiActiveDocument
Post by: Glenn R on August 19, 2005, 10:15:49 PM
The 'ambiguous' reference is probably because you using System.Windows.Forms and this too has a 'Application' property...the compiler gets confused.

Kerry's suggestion is the way I use it as well.