Author Topic: DocumentManager.MdiActiveDocument  (Read 7651 times)

0 Members and 1 Guest are viewing this topic.

TR

  • Guest
DocumentManager.MdiActiveDocument
« 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

TR

  • Guest
DocumentManager.MdiActiveDocument
« Reply #1 on: August 18, 2005, 02:02:13 PM »
I'm an idiot.

Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

not

Autodesk.AutoCAD.ApplicationServices.DocumentManager.MdiActiveDocument

Draftek

  • Water Moccasin
  • Posts: 1501
DocumentManager.MdiActiveDocument
« Reply #2 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.
Soli Deo Gloria

TR

  • Guest
DocumentManager.MdiActiveDocument
« Reply #3 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
DocumentManager.MdiActiveDocument
« Reply #4 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;

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
DocumentManager.MdiActiveDocument
« Reply #5 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.
Me