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: 

Object Data - How to Get ODRecords?

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
2469 Views, 12 Replies

Object Data - How to Get ODRecords?

I'm using VBA with AutoCad Map 4 and I need to get the
attribute values of records of a specific Object Data
Table. The follow code is returning the runtime
error "Method 'Record' of objetc 'ODRecords' failed". My
drawing contain any lines attached to three ODTables.
Can you helpme ??

Sincerely,

Marcelo
BRAZIL


Public Sub ViewItem()
Dim Objeto As acadObject
Dim Mapas As AcadMap
Set Mapas =
ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
For Each Objeto In ThisDrawing.ModelSpace
If Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords.Init(Objeto,
True, False) Then
Debug.Print
Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords.Record.Item(1).Value
End If
Next
End Sub
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

"Marcelo" wrote in message
news:62A3307B3213D62538CFAB31B5F88AD5@in.WebX.maYIadrTaRb...
> I'm using VBA with AutoCad Map 4 and I need to get the
> attribute values of records of a specific Object Data
> Table. The follow code is returning the runtime
> error "Method 'Record' of objetc 'ODRecords' failed". My
> drawing contain any lines attached to three ODTables.
> Can you helpme ??

Hello Marcelo,

I don't have time to completely debug this code
at the moment, but it appears you are using the
ODRecords iterator incorrectly.

Object Data Records are not exposed as a typical
automation collection in this library, but as an
iterator which you must first allocate before use
and then sequentially traverse. During active
useage, you must keep a reference to that allocated
iterator.

I'm typing on the fly here, but adjust your entity
loop something like this:


'' declare the iterator
dim RecordIterator as ORecordIterator

For Each Objeto In ThisDrawing.ModelSpace

'' allocate the iterator for a specific table
set ORecordIterator =
Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords

'' initialize the iterator on a specific entity
if ORecordIterator.Init(Objeto, False, False) = True Then

'' print a specific field value
Debug.Print ORecordIterator.Record.Item(1).Value
End If
Next

Cheers-

rdh.
Message 3 of 13
Anonymous
in reply to: Anonymous

did you get the answer??
if you don't, i have examples for you.
tell me
i work with AutoCadMAp and developed
applications and i have to work with object data and tables

"Marcelo" escribió en el mensaje
news:62A3307B3213D62538CFAB31B5F88AD5@in.WebX.maYIadrTaRb...
> I'm using VBA with AutoCad Map 4 and I need to get the
> attribute values of records of a specific Object Data
> Table. The follow code is returning the runtime
> error "Method 'Record' of objetc 'ODRecords' failed". My
> drawing contain any lines attached to three ODTables.
> Can you helpme ??
>
> Sincerely,
>
> Marcelo
> BRAZIL
>
>
> Public Sub ViewItem()
> Dim Objeto As acadObject
> Dim Mapas As AcadMap
> Set Mapas =
> ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
> For Each Objeto In ThisDrawing.ModelSpace
> If
Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords.Init(Objeto,
> True, False) Then
> Debug.Print
> Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords.Record.Item(1).Value
> End If
> Next
> End Sub
>
>
>
Message 4 of 13
Anonymous
in reply to: Anonymous

Jamie,
If you don't mind sharing your examples I wont like to look at it also. If
you don't want to post it here or in the customer files group you can e-mail
it to me. Jmurphy@cemc.org
Thanks,
Murph


"Jaime Lopez" wrote in message
news:AF6737DF8729F7C52EF7D7C0684B9AE8@in.WebX.maYIadrTaRb...
> did you get the answer??
> if you don't, i have examples for you.
> tell me
> i work with AutoCadMAp and developed
> applications and i have to work with object data and tables
>
Message 5 of 13
Anonymous
in reply to: Anonymous

Maybe this will help - the following sub prompts for an entity, then loops
through all the ODTables in the dwg and gathers all the ODrecords for the
entity.

Good Luck,

Private Sub cmdSelect_Click()
Dim ent As Object
Dim sset As AcadSelectionSet
Dim odTables As odTables
Dim odTable As odTable
Dim RecordIterator As odRecords
Dim odRecord As odRecord
Dim odValue As ODFieldValue
Dim msg As String
Dim count As Integer


'' create a new selection set
Set sset = ThisDrawing.SelectionSets.Add("OD_SSET")

'' clear entity
Set ent = Nothing

'' hide our form and activate acad window
Me.Hide
AppActivate ThisDrawing.Application.Caption

'' let user select an entity
sset.SelectOnScreen
If sset.count > 0 Then
Set ent = sset.Item(0)
End If

'' remove selection set
sset.Delete

'' if we got an entity
If Not ent Is Nothing Then

'' clear message
msg = ""

'' get the selected object data table and iterator
Set odTables = amap.Projects(ThisDrawing).odTables
For Each odTable In odTables
Set RecordIterator = odTable.GetODRecords

'' initilize iterator on entity
If RecordIterator.Init(ent, False, False) = True Then

'' oops, that entity has no od attached to specified table
If RecordIterator.IsDone Then
msg = msg & "Entity has no data from Object Data Table:
" & odTable.Name
End If

'' loop through all attached records from specified table
Do Until RecordIterator.IsDone

'' get record data
Set odRecord = RecordIterator.Record

'' initialize field counter
count = 0

'' loop through each od field
For Each odValue In odRecord

'' get field name from defs
msg = msg & odTable.ODFieldDefs.Item(count).Name

'' and show field value
Select Case odValue.Type
Case 0, 1, 2, 3
msg = msg & " = " & CStr(odValue.Value) &
Chr(10)
Case 4
msg = msg & " = " & CStr(odValue.Value.X) &
"," & CStr(odValue.Value.Y) & "," & CStr(odValue.Value.X) & Chr(10)
End Select

'' increment field counter
count = count + 1
Next

'' there may be more records attached
RecordIterator.Next
Loop


'' error getting iterator

Else

'' report the bad news
msg = "Error iterating Object Data Table: " & odTable.Name
End If
Next
'' update text box
txtOD.Text = msg

End If

'' restore our form after acad selection
Me.Show

End Sub


"Marcelo" wrote in message
news:62A3307B3213D62538CFAB31B5F88AD5@in.WebX.maYIadrTaRb...
> I'm using VBA with AutoCad Map 4 and I need to get the
> attribute values of records of a specific Object Data
> Table. The follow code is returning the runtime
> error "Method 'Record' of objetc 'ODRecords' failed". My
> drawing contain any lines attached to three ODTables.
> Can you helpme ??
>
> Sincerely,
>
> Marcelo
> BRAZIL
>
>
> Public Sub ViewItem()
> Dim Objeto As acadObject
> Dim Mapas As AcadMap
> Set Mapas =
> ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
> For Each Objeto In ThisDrawing.ModelSpace
> If
Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords.Init(Objeto,
> True, False) Then
> Debug.Print
> Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords.Record.Item(1).Value
> End If
> Next
> End Sub
>
>
>
Message 6 of 13
Anonymous
in reply to: Anonymous

When I try and run this I get error: user defined type not defined. Code
breaks at:
Dim odTables as odtables. What does it mean to dim something as itself?

thanks,

russell
"Scott Friedrich" wrote in message
news:F835F9B81DC605FA2067A978093EA6D4@in.WebX.maYIadrTaRb...
> Maybe this will help - the following sub prompts for an entity, then loops
> through all the ODTables in the dwg and gathers all the ODrecords for the
> entity.
>
> Good Luck,
>
> Private Sub cmdSelect_Click()
> Dim ent As Object
> Dim sset As AcadSelectionSet
> Dim odTables As odTables
> Dim odTable As odTable
> Dim RecordIterator As odRecords
> Dim odRecord As odRecord
> Dim odValue As ODFieldValue
> Dim msg As String
> Dim count As Integer
>
>
> '' create a new selection set
> Set sset = ThisDrawing.SelectionSets.Add("OD_SSET")
>
> '' clear entity
> Set ent = Nothing
>
> '' hide our form and activate acad window
> Me.Hide
> AppActivate ThisDrawing.Application.Caption
>
> '' let user select an entity
> sset.SelectOnScreen
> If sset.count > 0 Then
> Set ent = sset.Item(0)
> End If
>
> '' remove selection set
> sset.Delete
>
> '' if we got an entity
> If Not ent Is Nothing Then
>
> '' clear message
> msg = ""
>
> '' get the selected object data table and iterator
> Set odTables = amap.Projects(ThisDrawing).odTables
> For Each odTable In odTables
> Set RecordIterator = odTable.GetODRecords
>
> '' initilize iterator on entity
> If RecordIterator.Init(ent, False, False) = True Then
>
> '' oops, that entity has no od attached to specified table
> If RecordIterator.IsDone Then
> msg = msg & "Entity has no data from Object Data
Table:
> " & odTable.Name
> End If
>
> '' loop through all attached records from specified table
> Do Until RecordIterator.IsDone
>
> '' get record data
> Set odRecord = RecordIterator.Record
>
> '' initialize field counter
> count = 0
>
> '' loop through each od field
> For Each odValue In odRecord
>
> '' get field name from defs
> msg = msg &
odTable.ODFieldDefs.Item(count).Name
>
> '' and show field value
> Select Case odValue.Type
> Case 0, 1, 2, 3
> msg = msg & " = " & CStr(odValue.Value) &
> Chr(10)
> Case 4
> msg = msg & " = " & CStr(odValue.Value.X)
&
> "," & CStr(odValue.Value.Y) & "," & CStr(odValue.Value.X) & Chr(10)
> End Select
>
> '' increment field counter
> count = count + 1
> Next
>
> '' there may be more records attached
> RecordIterator.Next
> Loop
>
>
> '' error getting iterator
>
> Else
>
> '' report the bad news
> msg = "Error iterating Object Data Table: " & odTable.Name
> End If
> Next
> '' update text box
> txtOD.Text = msg
>
> End If
>
> '' restore our form after acad selection
> Me.Show
>
> End Sub
>
>
> "Marcelo" wrote in message
> news:62A3307B3213D62538CFAB31B5F88AD5@in.WebX.maYIadrTaRb...
> > I'm using VBA with AutoCad Map 4 and I need to get the
> > attribute values of records of a specific Object Data
> > Table. The follow code is returning the runtime
> > error "Method 'Record' of objetc 'ODRecords' failed". My
> > drawing contain any lines attached to three ODTables.
> > Can you helpme ??
> >
> > Sincerely,
> >
> > Marcelo
> > BRAZIL
> >
> >
> > Public Sub ViewItem()
> > Dim Objeto As acadObject
> > Dim Mapas As AcadMap
> > Set Mapas =
> > ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
> > For Each Objeto In ThisDrawing.ModelSpace
> > If
> Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords.Init(Objeto,
> > True, False) Then
> > Debug.Print
> >
Mapas.Projects(ThisDrawing).ODTables(2).GetODRecords.Record.Item(1).Value
> > End If
> > Next
> > End Sub
> >
> >
> >
>
>
Message 7 of 13
Anonymous
in reply to: Anonymous

"RHeldt" wrote in message
news:44957E6AB9840C252812B54E3AAAAA4A@in.WebX.maYIadrTaRb...
> When I try and run this I get error: user defined type not defined. Code
> breaks at:
> Dim odTables as odtables. What does it mean to dim something as itself?
>
> thanks,
>
> russell

It sounds like the Map Type library is not being referenced - within your
VBA project, go to Tools>References and make sure the AutoCAD Map 2000i
Release 4.5 Type Library is listed and checked. There is no significance to
the naming of variables - that line could be 'dim Scott as odtables' for
that matter.

Scott
Message 8 of 13
Anonymous
in reply to: Anonymous

Hello Jaime

Yes, that would be really nice, if I could only grab a hold of codes like the one you mentioned -- my life would be so much brighter.

Matt
Message 9 of 13
Anonymous
in reply to: Anonymous

Hi,
We have the following line in our code as

line 1:Set oDtb = amap.Projects(m_oActiveDocument).ODTables.Item(DBLINK_TABLE)
line 2:Set oDrc = oDtb.GetODRecords

We get an error like 'Object variable or with block variable not set'.

The scenario is like this, the user need to perform the operation in a source dwg file, but if he performs in architecture or funiture dwg file, then the DBLINKS item would not be found and hence it would give the above error.

My requirement is to give a meaningful error like saying 'you need to perform this operation in source dwg and not in architecute dwg'.

Please let me know the solution,
Deepti
(india)
Message 10 of 13
Anonymous
in reply to: Anonymous

It is most likely, when the drawing does not contain an object table
(ODTable) with name DBLINK_TABLE (its value).

So, you can

1. Loop through all ODTable to see if there is a ODTable with that name
before lettiing the code go further;

such as (assume m_oActiveDocument is a valid AcadDocument object):

Dim t As ODTable
Dim exists As Boolean
For Each t in amap.Projects(m_oActiveDocument).ODTables
If UCase(t.Name)=UCase(DBLINK_TABLE) THEN
exists=True
Exit For
End If
Next

If Not exists Then
MsgBox "This Drawing does not contain required data!"
Exit Sub
End If

Set oDtb = amap.Projects(m_oActiveDocument).ODTables.Item(DBLINK_TABLE)
Set oDrc = oDtb.GetODRecords

'Do something
...


2. You can simply do error handling:

Such as:

On Error Go To ErrorExit

Set oDtb = amap.Projects(m_oActiveDocument).ODTables.Item(DBLINK_TABLE)
Set oDrc = oDtb.GetODRecords
'Do something
Exit Sub

ErrorExist:
Msgbox "Error: " & Err.Description
End Sub


wrote in message news:5762881@discussion.autodesk.com...
Hi,
We have the following line in our code as

line 1:Set oDtb =
amap.Projects(m_oActiveDocument).ODTables.Item(DBLINK_TABLE)
line 2:Set oDrc = oDtb.GetODRecords

We get an error like 'Object variable or with block variable not set'.

The scenario is like this, the user need to perform the operation in a
source dwg file, but if he performs in architecture or funiture dwg file,
then the DBLINKS item would not be found and hence it would give the above
error.

My requirement is to give a meaningful error like saying 'you need to
perform this operation in source dwg and not in architecute dwg'.

Please let me know the solution,
Deepti
(india)
Message 11 of 13
Anonymous
in reply to: Anonymous

Hi,

Thanks a lot . this really helped me to solve my problem.

Regards,
Deepti
(India)
Message 12 of 13
Anonymous
in reply to: Anonymous

Hi,

Currently i am developing my application with auto cad 2002 files, if we use the drawing files created in auto cad's higher version, will my application support or are there any specific list of functions that are not supported in autocad 2007, that are defined in autocad 2002

Please let me know.

Regards,
Deepti
Message 13 of 13
Anonymous
in reply to: Anonymous

Hello Sir,

  I  have a small doubt in Autocad VBA.I need to draw polyline.after clicking the polyline it should show object data TABLE (suppose  table name "UNIT") .after that i need to attach fields to that TABLE(like layer  name..etc ) and after attaching the field i need to update value to that field (like "UNIT").

hope you do this asap.

Its Urgent

can i have your mail id???

 

~abhishek

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

Post to forums  

Autodesk Design & Make Report

”Boost