AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cant get ODTables from a sidedrawing

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
1378 Views, 5 Replies

Cant get ODTables from a sidedrawing

Hello!

 

First of all, sorry for bad english. I searched the internet for this and cant find a solution. 

I need to check multiple drawings if they have the correct layer, blocknames etc. This worked well, it was fast and no problems, however there are also object tables in the drawing that needs to be checked. The program can check the current drawing when selected from form with a checkbox, and it works.

So when i try to retrieve tables from a current drawing in this form it works:

Document doc = Application.DocumentManager.MdiActiveDocument;

Database db = doc.Database;

Tables odTables = Autodesk.Gis.Map.HostMapApplicationServices.Application.GetProjectForDB(db).ODTables;

 

But if i try to do this with a sidedrawing like this:

Database db = new Database(false,true);

db.ReadDwgFile(dwgPath, FileOpenMode.OpenForReadAndAllShare, false, "");

db.CloseInput(true);

Tables odTables = Autodesk.Gis.Map.HostMapApplicationServices.Application.GetProjectForDB(db).ODTables;

 

I get this error:

"Operation is not valid due to the current state of the object."

 

I read that this error means that the database cannot be opened for read (or to write?), but why is this different from the current opened drawing?

 

Tried a lot of things, but cant fix the problem, can someone solve this problem? How to get odtables from a dwg as a sidedrawing without opening it?

 

Thank you in andvance.

 

5 REPLIES 5
Message 2 of 6
norman.yuan
in reply to: Anonymous

As you already know, to access OD data, you need to create a connect ProjecyModel object with the context of MapApplication, with the method GetProjectFromDB(database). That means, the database (of a drawing) must be open in the MapApplication context (which does not necessarily mean being open in AutoCAD editor, though). When you only a side database with pure AutoCAD API, the side database is NOT opened in MapApplication context, thus the error of "Operation is not valid...".

 

Yes, AutoCAD Map does have its own method to open drawing as side database (that is, open drawing to access map specific data in it without actually opening in AutoCAD editor): Drawing Set. 

 

With Map .NET API, you can manually add alias/drawing set and then run your code against drawing in the drawing set to obtain OD information; or you can programmatically create alias/drawing set, attach the target drawing(s) to the drawing set, and then obtain ProjectModel object based on the attached drawing(s).

 

Hope this helps.

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 6
Anonymous
in reply to: norman.yuan

Thank you for the fast reply. Thanks to your help last night i clould make it work.
Message 4 of 6

Thank you for this. I think this might be what I'm looking for.  However, I'm trying locate drawings with certain DataSources. I'd like to do this without opening the drawings in the Editor. I have not been able to find a way to get the connected DataSources when attaching the drawings to a DrawingSet. 

Message 5 of 6
norman.yuan
in reply to: Anonymous

What is the "certain DataSource"? 

 

Regardless, the "Drawing Set" concept in Acad Map 3D is to "attach" a set of drawings in the current AutoCAD session (MapApplication), meaning these attached drawing is opened in AUtoCAD session's memory, but not visibly in AutoCAD editor, for the MapApplication to gain access to data in these drawing files.

 

If the "DataSource" means some kind of drawing file repository, other than local/network file system, then it is up to you (and the DataSource's API) to obtain drawing file(s) from it, which would be beyond the topic of this thread about accessing OD data from side database.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 6

The DataSource would be a FDO connection to a raster file. Normally, if I had the drawing open I would just do something like this: 

 

List<string> connectionStrings = new List<string>();
MapApplication mapApp = HostMapApplicationServices.Application;

DataSources srcs = mapApp.DataSources;
StringCollection col = new StringCollection();
srcs.GetConnectedDataSources(ref col);

 

But, I cannot make this work with a side database and was hoping I could tackle with the Drawing Set method you described.

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

Post to forums  

Technology Administrators


AutoCAD Beta