Author Topic: How can I get data from AutoCAD Map3D ObjectData so Fast!!!  (Read 2986 times)

0 Members and 1 Guest are viewing this topic.

kraz

  • Guest
How can I get data from AutoCAD Map3D ObjectData so Fast!!!
« on: March 17, 2015, 08:36:10 AM »
ObjectData is in Attribute format of Map3D.
I know lisp routine of get data from objectdata.
I usually use following lisp routine
(defun get_od_val(sn fld_name / tblname get_fld)
   (if (ade_odgettables sn)
      (progn
         (setq tblname (car (ade_odgettables sn)))
         (setq get_fld (ade_odgetfield sn tblname fld_name 0))
      )
      (setq get_fld nil)
   )
   get_fld
)
In my think, this routine doesn't so fast...I have a tons of data...
I think, Maybe..VB routine is faster than lisp??
I got a following routine...
(defun KZ:ODTableList ( / acMapObj projects acPrjObj odTblObjs lst)
   (setq acMapObj (vla-getinterFaceObject (vlax-get-acad-object) "AutoCADMap.Application")
      projects (vlax-get acMapObj 'projects)
      acPrjObj (vla-item projects 0)
      odTblObjs (vlax-get acPrjObj 'odTables)
      mapUtil (vlax-get acPrjObj 'mapUtil)
   )
   (vlax-for tblObj odTblObjs
      (setq lst (cons (vlax-get tblObj 'name) lst))
   )
   (reverse lst)
)
but I don't know how can I get/put data from/to entity like above(VB Style)...

Thanks, in advance.

kraz

  • Guest
Re: How can I get data from AutoCAD Map3D ObjectData so Fast!!!
« Reply #1 on: March 17, 2015, 08:29:23 PM »
please refer following vb code sample in acmapatm.chm


Code - vb.net: [Select]
  1. // The following example creates an object data table and attaches records to drawing objects.
  2.  
  3. // 1 Declare variables.
  4.  
  5. Dim amap As AcadMap
  6.  
  7. Dim acadObj As Object
  8.  
  9. Dim ODfdfs As ODFieldDefs
  10.  
  11. Dim ODfdf As ODFieldDef
  12.  
  13. Dim ODtb As ODTable
  14.  
  15. Dim ODrc As ODRecord
  16.  
  17. // 2 Set application and project objects.
  18.  
  19. Set amap = ThisDrawing.Application. _
  20.  
  21. GetInterfaceObject("AutoCADMap.Application")
  22.  
  23. // 3 Create the schema for the object data table.
  24.  
  25. Set ODfdfs = amap.Projects(ThisDrawing).MapUtil.NewODFieldDefs
  26.  
  27. // 4 Create fields for object data. For example, create fields for the name, color, and layer of a drawing object. Specify  default values, for example, empty string, AcRed,.and layer 0, respectively. Add the fields to the table using consecutive index numbers.
  28.  
  29. Set ODfdf = ODfdfs.Add("Entity", "Entity name", "", 0)
  30.  
  31. Set ODfdf = ODfdfs.Add("Color", "Object color", acRed, 1)
  32.  
  33. Set ODfdf = ODfdfs.Add("Layer", "Object layer", "0", 2)
  34.  
  35. // 5 Name the table and test the uniqueness of the name.
  36.  
  37. If amap.Projects(ThisDrawing).ODTables. _
  38.  
  39. Item("SampleOD3") Is Nothing Then
  40.  
  41. // 6 Register the OD Table in the drawing and specify the type of object data as Xdata.
  42.  
  43. Set ODtb = amap.Projects(ThisDrawing) _
  44.  
  45. .ODTables.Add("SampleOD3", "Sample Xdata", ODfdfs, True)
  46.  
  47. // 7 Create a record of data with defaults specified in step 4.
  48.  
  49. Set ODrc = ODtb.CreateRecord
  50.  
  51. // 8 Loop though each drawing object, get its values for the name, color, and layer of the object, and attach the data to the drawing object.
  52.  
  53. For Each acadObj In ThisDrawing.ModelSpace
  54.  
  55. ODrc.Item(0).Value = acadObj.EntityName
  56.  
  57. ODrc.Item(1).Value = acadObj.Color
  58.  
  59. ODrc.Item(2).Value = acadObj.Layer
  60.  
  61. ODrc.AttachTo (acadObj.ObjectID)
  62.  
  63. Next
  64.  
  65.