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
Solved! Go to Solution.
Solved by Jeffrey_H. Go to Solution.
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.)
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.
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