Code Red > .NET

DocumentManager.MdiActiveDocument

(1/2) > >>

TR:
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: ---Document doc = Autodesk.AutoCAD.ApplicationServices.DocumentManager.MdiActiveDocument;
--- End code ---

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'
--- End quote ---


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

Thanks,
Tim

TR:
I'm an idiot.

Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

not

Autodesk.AutoCAD.ApplicationServices.DocumentManager.MdiActiveDocument

Draftek:
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.

TR:
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.

Kerry:
One way to do it
... though it's nothing special and you've probably seen this

--- Code: ---
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

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


--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version