Read Object Data, Map3D 2009

Read Object Data, Map3D 2009

Anonymous
Not applicable
476 Views
3 Replies
Message 1 of 4

Read Object Data, Map3D 2009

Anonymous
Not applicable
I have created a selection set of entities that I would like to annotate and move to certain layers based on their object data. I'm hung up on reading each entities object data. I have been able to find examples of how to change object data, but nothing on reading that object data into variables. My basic workflow is as follows:

1) Using MapImport, import a shapefile and read it's object data into an Object Data Table

2) Select the imported data, and based on the entities object data, place each polygon on it's appropriate layer and annotate from it's object data.

Suggestions?

Thanks
0 Likes
477 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

First, make sure you have the  appropriate
object reference loaded. My 2008 install had 'Autodesk Map 3d 2005' loaded along
with AutoCAD 2008 Type library

 

 

then:

 Dim Amap As AcadMap
 Dim ODrcs As
ODRecords

 Dim SSet As AcadSelectionSet
 Dim ent
As Object
 Dim BoolVal As Boolean

 Dim RetStr as String

  ' 

  Set Amap =
ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
 
Set ODrcs = Amap.Projects(ThisDrawing).ODTables.GetODRecords

  <initialize selection set & get
your data into the selection set by your favoriate means>

 

For each ent in SSet

    BoolVal = ODrcs.Init(ent, False,
False)
    RetStr =
VBA.Trim(ODrcs.Record.Item(0).Value)

    'When selecting values from the
ODrcs.record, remember that the table is an array starting at 0 for the first
element...
    <...Do what you need to with returned values
here...>

Next

 

'clean up after yourself

SSet.Clear

SSet.Delete

End Sub

 

Obviously I'm not including a lot of error checking
and such in this code. It's pulled from stuff I wrote 5+ years ago and haven't
revisited because nothing broke.

 

Hope this helps

Tom


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
have created a selection set of entities that I would like to annotate and
move to certain layers based on their object data. I'm hung up on reading each
entities object data. I have been able to find examples of how to change
object data, but nothing on reading that object data into variables. My basic
workflow is as follows: 1) Using MapImport, import a shapefile and read it's
object data into an Object Data Table 2) Select the imported data, and based
on the entities object data, place each polygon on it's appropriate layer and
annotate from it's object data. Suggestions? Thanks
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thanks Tom

For my next question:

I am getting run time error '-2145386418 (8020004e)': object was open for read

I am guessing that the script line BoolVal = ODRec.Init(ModObj, False, False) opens the record for reading. How do I close that record so that I can modify the object in ModObj (change it's layer and annotate it)

My code as of now:

Dim ModObj As Object

Dim DispNum As String, DispType As String, DispOwn As String, DispSurv As String, LTOPlan As String

Dim Amap As AcadMap
Dim ODRec As ODRecords
Dim BoolVal As Boolean

Set Amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
Set ODRec = Amap.Projects(ThisDrawing).ODTables.GetODRecords


For Each ModObj In objSS

BoolVal = ODRec.Init(ModObj, False, False)

DispNum = VBA.Trim(ODRec.Record.Item(1).Value)
DispType = VBA.Trim(ODRec.Record.Item(2).Value)
DispOwn = VBA.Trim(ODRec.Record.Item(3).Value)
DispSurv = VBA.Trim(ODRec.Record.Item(5).Value)
LTOPlan = VBA.Trim(ODRec.Record.Item(6).Value)

Debug.Print DispNum, DispType, DispOwn, DispSurv, LTOPlan

If DispType = "MSL" Then

'ModObj.Layer = "lse-bdy"

End If

Next

Kris Edited by: kristopherschmidt on Jun 23, 2009 11:34 AM
0 Likes
Message 4 of 4

Anonymous
Not applicable
As a follow-up, I have been able to figure this one out. Code as follows:

Dim ModObj As Object

Dim DispNum As String, DispType As String, DispOwn As String, DispSurv As String, LTOPlan As String

Dim Amap As AcadMap
Dim ODRec As ODRecords
Dim BoolVal As Boolean
Dim DispLbl As AcadMText
Dim TxtPoint As Variant
Dim TxtFormat As String

Set Amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
TxtFormat = "\Farrusn.shx;\H2.0;"

For Each ModObj In objSS

Set ODRec = Amap.Projects(ThisDrawing).ODTables.GetODRecords

BoolVal = ODRec.Init(ModObj, False, False)

DispNum = VBA.Trim(ODRec.Record.Item(1).Value)
DispType = VBA.Trim(ODRec.Record.Item(2).Value)
DispOwn = VBA.Trim(ODRec.Record.Item(3).Value)
DispSurv = VBA.Trim(ODRec.Record.Item(5).Value)
LTOPlan = VBA.Trim(ODRec.Record.Item(6).Value)



'Debug.Print DispNum, DispType, DispOwn, DispSurv, LTOPlan

Set ODRec = Nothing

If DispType = "MSL" Then
ModObj.Layer = "LSE-BDY"
End If

If DispType = "LOC" Then
ModObj.Layer = "LSE-LOC"
End If

If DispType = "PLA" And LTOPlan <> "" Then
ModObj.Layer = "ROW-REG"
End If

If DispType = "PLA" And LTOPlan = "" Then
ModObj.Layer = "ROW-UNR"
End If



Next Edited by: kristopherschmidt on Jun 24, 2009 4:25 PM
0 Likes