VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Attaching Object Data using VB.NET 2003

1 REPLY 1
Reply
Message 1 of 2
kashi_rock
1134 Views, 1 Reply

Attaching Object Data using VB.NET 2003

Hi All,

I am trying to attach object data (OD Data) on the objects using following code for AutoCAD Map 2005. All the things are heppening in right manner except the AttachTo function.

Public Sub acdConvertNGOBJECTEN2(ByVal lngMSLINK As Long, ByVal strOCODE As String, ByRef oEntity As AcadEntity)

Dim ODtbl As ODTable
Dim AcadMap As AcadMap
Dim RecordEmunator As Object
Dim psarrDataType(2) As String
Dim psarrFieldName(2) As String
Dim ODrecs As AutocadMAP.ODRecords
Dim ODRecord As AutocadMAP.ODRecord
Dim acdActiveDocument As AcadDocument
Try
'Setting currently opened drawing as active document
acdActiveDocument = acdApplication.ActiveDocument

'Initiate autocad map object
AcadMap = acdActiveDocument.Application.GetInterfaceObject("AutoCADMap.Application.3")

'Get object data table
ODtbl = AcadMap.Projects.Item(0).ODTables.Item("NGOBJECTEN_DATA")

'Get records from the given table
ODrecs = ODtbl.GetODRecords
RecordEmunator = ODrecs.Init(oEntity, False, False)
'ODRecord = ODrecs.Record

'Defining field values
ODRecord = ODtbl.CreateRecord()
ODRecord.Item(0).Value = Convert.ToInt32(lngMSLINK)
ODRecord.Item(1).Value = strOCODE.ToString()

'Attaching field values to data table
ODRecord.AttachTo(Convert.ToInt32(oEntity.ObjectID))

Catch ex As Exception
'Rise an error message
Throw New Exception(ex.Message)
Finally
'Releasing all COM objects
clsMyUserClass.ReleaseComObject(ODRecord)
clsMyUserClass.ReleaseComObject(AcadMap)
End Try

End Sub

I am getting the error during the AttachTo Function. Can anybody help me out please.

Regards,
Kaushal Sharma
1 REPLY 1
Message 2 of 2
cadger
in reply to: kashi_rock

hello,

map customization NG may be more helpful

ODRecord.AttachTo(Convert.ToInt32(oEntity.ObjectID))
maybe Convert.ToInt32(oEntity.ObjectID should be Long, am not familiar with VB though

below is vba, previous version of Map code tidbit, hope is helpful

Private Sub addExtendedData_Click()
Me.Hide

Set amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application.2")
Set ODfdfs = amap.Projects(ThisDrawing).MapUtil.NewODFieldDefs
Set ODfdf = ODfdfs.Add("DA_ID", "Drainage Area ID", "", 0)
Set ODfdf = ODfdfs.Add("Pre_Post_Both", "Pre/Post Development or Both", "", 1)
Set ODfdf = ODfdfs.Add("HSG", "Hydrologic Soil Group", "", 2)
Set ODfdf = ODfdfs.Add("Onsite", "Within Property Boundaries", "", 3)
Set ODfdf = ODfdfs.Add("Cover", "Cover Type", "", 4)
Set ODfdf = ODfdfs.Add("Row", "Within Proposed ROW", "", 5)

If amap.Projects(ThisDrawing).ODTables.Item("Cover") Is Nothing Then
Set ODtb = amap.Projects(ThisDrawing).ODTables.Add("Cover", "Cover Xdata", ODfdfs, True)
Else
Set ODtb = amap.Projects(ThisDrawing).ODTables.Item("Cover")
amap.Projects(ThisDrawing).ODTables.GetODRecords
End If


Set ODrc = ODtb.CreateRecord

amap.Projects(ThisDrawing).ODTables.GetODRecords

AppActivate Application.Caption
On Error Resume Next
ThisDrawing.SelectionSets.Item("sset").delete
On Error GoTo 0
Set sset = ThisDrawing.SelectionSets.Add("sset")
sset.SelectOnScreen
For x = 1 To sset.count

ODrc.Item(0).Value = "0"
ODrc.Item(1).Value = "1"
ODrc.Item(2).Value = "2"
ODrc.Item(3).Value = "3"
ODrc.Item(4).Value = "4"
ODrc.Item(5).Value = "5"
ODrc.AttachTo (sset(x - 1).ObjectID)

Next x
sset.delete
Me.Show
End Sub Message was edited by: cadger

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

Post to forums  

Autodesk Design & Make Report

”Boost