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

VB/Map 3D - Reading Object Data tables from dwg in side database

6 REPLIES 6
Reply
Message 1 of 7
thoman999
2199 Views, 6 Replies

VB/Map 3D - Reading Object Data tables from dwg in side database

Hello All,

 

Would you have a solution to accessing ODTables for a dwg object only loaded into memory? I have 1000+ dwgs that I want to return a string with the names of the various ODTable names for auding purposes that I would prefer to just side load rather than full load for performance reasons.

 

 I'm attempting to use something like this (which works fine on an open drawing):

==================================

 Public Function ReturnOBJData(acObjIDIn As ObjectId, intOffset As IntegerAs String
    'Don't forget that table is 0 based offset so....plan accordingly
    Dim strRet As String = ""
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acDb As Database = acDoc.Database
    Dim acEd As Editor = acDoc.Editor
 
    Dim acMapApp As MapApplication = HostMapApplicationServices.Application
    Dim acActiveProject As Project.ProjectModel = acMapApp.ActiveProject
    Dim acTableList As Tables = acActiveProject.ODTables
    Dim acTable As ObjectData.Table
    Dim acRecs As ObjectData.Records
    Dim acRec As ObjectData.Record
    Dim acVal As Autodesk.Gis.Map.Utilities.MapValue
 
    Dim acEnt As Entity
 
    Using actrans As Transaction = acDb.TransactionManager.StartTransaction
      acEnt = actrans.GetObject(acObjIDIn, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
      Try
        acTable = acTableList("Parcels")
        acRecs = acTable.GetObjectTableRecords(0, acObjIDIn, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, True)
        acRec = acRecs.Item(0)
        'We should have the record so return the value
        acVal = acRec(intOffset)
        Select Case acVal.Type
          Case Autodesk.Gis.Map.Constants.DataType.Character
            strRet = acVal.StrValue
          Case Autodesk.Gis.Map.Constants.DataType.Integer
            strRet = acVal.Int32Value.ToString
        End Select
      Catch ex As System.Exception
 
      End Try
    End Using
    'Clean up and dispose
    Return strRet
  End Function

==============================

In a fashion along the lines of

==============================
 Public Function GetTables(strFileIn As StringAs List(Of String)
    Dim lstReturn As New List(Of String)
    Dim acMapApp As MapApplication = HostMapApplicationServices.Application
    Dim acActiveProject As Project.ProjectModel = acMapApp.ActiveProject
    Dim acTableList As Tables = acActiveProject.ODTables
    Dim acTable As ObjectData.Table
    Try
 
      Using acDb As New Database(FalseTrue)
        'Just work with dwg in memory rather than displaying it
        acDb.ReadDwgFile(strFileIn, FileOpenMode.OpenForReadAndAllShare, False"")
        acDb.CloseInput(True)
        Using actrans As Transaction = acDb.TransactionManager.StartTransaction
          MsgBox(acTableList.TablesCount)
        End Using       End Using     Catch ex As System.Exception       MsgBox(ex.ToString, , "Problem Getting Tables")     End Try     Return lstReturn   End Function

================================

The problem is that I can't seem to link the ODTables object off of the memory database object. In this sample, the msgbox always returns a count of 0 where I would expect it to be in the range of 1-4.

Any pointers would be greatly appreciated

Regards,

Tom
6 REPLIES 6
Message 2 of 7

See MapApplication.GetProjectForDB()

Message 3 of 7
norman.yuan
in reply to: thoman999

ObjectData table (ODTable) can only be accessed via ProjectModel object in a MapApplication. A ProjectModel object is, similar to AutoCAD.ApplicationServices.Document object, based on each opened document in AutoCAD Map. That is, MapApplication.Projects are corresponding to documents opened in AutoCAD Map.

 

Also, MapApplication.GetProjectForDB() can only return a ProjectModel object when a Database of currently opened drawing is passed in. That is, this method is equivalent to MapApplication.Projects[key/index].

 

Since you must get a ProjectModel based on a opened drawing, so, you cannot access ODTables in a map drawing without being opened in AutoCAD Map via Map's ObjectArx .NET API. Creating a side database does not make it into MapApplication, nor can you create a ProjectModel object from it (e.g. ProjectModel can only be created by AutoCAD Map itself when a drawing is opened by AutoCAD Map, not by .NET API code. It is kind of "read-only").

 

However, with AutoCAD Map, if you attach many drawings in one drawing that opened in AutoCAD Map, then the ODTables of all attached drawings can be accessed in the ProjectModel of the opened drawing. I am not sure if attaching 1000 drawings is doable (never tried that. Mostly, I'd only need to attach less than 10). You may try to attach 20, 30, or 50, depending on the drawing's size. Well, in this way, it seems there is no way to tell which ODTable is from which drawing (I did not play with it very much, so I may be wrong on this). But if you only need to ODTable names and its fields...

 

It looks like internally AutoCAD does read map related data (ODTable) vis side database without opening it in editor (attached drawings), but this is not exposed in Map's ObjectARX .NET API.

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 7
Alfred.NESWADBA
in reply to: thoman999

Hi,

 

look to >>>this thread (post 4)<<<

chiefbrandcloud assigns there a database (which is not loaded into the editor) temporary for a few code-steps to the HostApplicationServices.WorkingDatabase.

I don't know how stable that is for Map3D, I also have not tried it (to access ODRecords then), but I guess it's worth to try.

 

Good luck, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 7


@Alfred.NESWADBA wrote:

Hi,

 

look to >>>this thread (post 4)<<<

 


The code in the referenced post is dangerous, because it doesn't ensure that the working database is restored to the database of the active document in the event an exception occured before the line that does that.

 

Anyone (including the author of that code) that is going to change the working database should learn how to use termination handling (e.g., try/finally, or a wrapper class that uses the Disposable pattern), when it is critically-essential as is the case here.

Message 6 of 7

Hi,

 

>> The code in the referenced post is dangerous, because it doesn't ensure that the working database

>> is restored to the database of the active document

That's why I wrote "I don't know how stable that is for Map3D". Isn't that enough warning? No, double warnings is better.

 

And as we are warning: an additionally risk is (or might be) that Map3D might even not recognize for it's project-handling that the property workingdatabase is now pointing to the database different to the one in the editor (Map3D is sometimes critical to things like that with all API's).

 

- alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 7
thoman999
in reply to: Alfred.NESWADBA

Duly Noted and thanks all for your assistance. I'll just have to open the drawing normally.

 

Tom

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