Visual Basic Customization

Visual Basic Customization

Active Contributor
Posts: 48
Registered: ‎05-16-2006
Message 1 of 2 (829 Views)

Attaching Object Data using VB.NET 2003

829 Views, 1 Replies
04-01-2008 10:34 PM
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
'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

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

End Sub

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

Kaushal Sharma
Distinguished Contributor
Posts: 367
Registered: ‎03-28-2007
Message 2 of 2 (829 Views)

Re: Attaching Object Data using VB.NET 2003

04-02-2008 08:38 AM in reply to: kashi_rock

map customization NG may be more helpful

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()

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)
Set ODtb = amap.Projects(ThisDrawing).ODTables.Item("Cover")
End If

Set ODrc = ODtb.CreateRecord


AppActivate Application.Caption
On Error Resume Next
On Error GoTo 0
Set sset = ThisDrawing.SelectionSets.Add("sset")
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
End Sub Message was edited by: cadger
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.