Visual Basic Customization

Visual Basic Customization

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

Attaching Object Data using VB.NET 2003

852 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
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
Distinguished Contributor
cadger
Posts: 378
Registered: ‎03-28-2007
Message 2 of 2 (852 Views)

Re: Attaching Object Data using VB.NET 2003

04-02-2008 08:38 AM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.