.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

where is Document?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
elMarko
1291 Views, 4 Replies

where is Document?

per the AutoCad .Net Developers' Guide:
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
 

[CommandMethod("ListEntities")]
  public static void ListEntities()
  {
      // Get the current document and database, and start a transaction
      Document acDoc = Application.DocumentManager.MdiActiveDocument;
      Database acCurDb = acDoc.Database;
...and later acDoc.Editor.WriteMessage("\nModel space objects: ");

trying that i get the error:
Error 2 The type or namespace name 'Document' could not be found (are you missing a using directive or an assembly reference?) 

 

other samples i've found used:(skips the document and just goes into the database)
 Database db = HostApplicationServices.WorkingDatabase;

      Editor ed =
        AcAp.Application.DocumentManager.MdiActiveDocument.Editor;


and also:

using

AcAp = Autodesk.AutoCAD.ApplicationServices;

using

AcDb = Autodesk.AutoCAD.DatabaseServices;

Database db = AcAp.Application.DocumentManager.MdiActiveDocument.Database;

 

 


where does the Document object live? (what namespace do i need to be using)

 

and which method is correct for getting the database?

Database db = AcAp.Application.DocumentManager.MdiActiveDocument.Database;

 or

 Database db = HostApplicationServices.WorkingDatabase;

 

Thanks
mark

4 REPLIES 4
Message 2 of 5
malst
in reply to: elMarko

Document is an abstraction for DWG drawing opened in Acad, with editor where you can send commands, methods for open, save, etc. Document necessarily have database.

Database is an abstraction for set of primitives and tables (approximately, of course). Database can be not linked with Document (when opened in "silent" mode, without opening document window). Database linked to file, of course.

 

So, if you want just to wotk with database of current docuemnt, use Application.DocumentManager.MdiActiveDocument​.Database.  HostApplicationServices.WorkingDatabase, as I know, represents last database which your .NET application has operated (Acad guru, please corect if wrong).

 

You can open DWG file without opening window - and without opening Document in Acad (you just create a Database object with call new Database(false,false), and use ReadDwgFile() method.)

Message 3 of 5
elMarko
in reply to: malst

Thanks for the response.  I guess I don't need to use document to get to .Database, but the help file had it so was trying to figure out what I was doing wrong.

I do somewhat understand what a document is, what I don't understand is what namespace it's in.

why does the following error?

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

Error 2 The type or namespace name 'Document' could not be found (are you missing a using directive or an assembly reference?) 

 what  using directive would I need?

 

 

also for example

 

 if i try:

Autodesk.AutoCAD.ApplicationServices.Application.Document

this error occurs:

Error 2 The type name 'Document' does not exist in the type 'Autodesk.AutoCAD.ApplicationServices.Application' 

 

 

i would have assumed that MdiActiveDocument was of type Document?  obviously I'm wrong.

I would further assume since the line(orig post) came from acad's help system that there was a way to reference a document object.

Message 4 of 5
Jeffrey_H
in reply to: elMarko

It is in the Autodesk.AutoCAD.ApplicationServices NameSpace

 Look at the arxdoc.chm at MDI Overview and database, document, documentManager, etc.....

You can also find your answers @ TheSwamp
Message 5 of 5
elMarko
in reply to: Jeffrey_H

thanks, now i see what's wrong.

I was using some code snippets gotten from here and there and the lines at the top happened to be:

 

using

 

AcAp = Autodesk.AutoCAD.ApplicationServices;

using

 

AcDb = Autodesk.AutoCAD.DatabaseServices;

 

instead of

using Autodesk.AutoCAD.ApplicationServices;

 

thanks

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost