TheSwamp
Code Red => .NET => Topic started 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:
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.
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
-
I'm an idiot.
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
not
Autodesk.AutoCAD.ApplicationServices.DocumentManager.MdiActiveDocument
-
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.
-
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.
-
One way to do it
... though it's nothing special and you've probably seen this
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
..
..
static public void
whatever()
{
Document pDoc = AcadApp.DocumentManager.MdiActiveDocument;
Database pDb = pDoc.Database;
Editor pEd = pDoc.Editor;
-
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.