Look,
The code from line 1 to line 23 does not work!
The code from line 25 to line 43 does.
Line 15 is sending the same info as line 36.
The question is WHY won't the code from line 1 to 23 process the AddRegAppTable correctly while the other code does???
1 Public Sub SetXData()
2 Dim form As New tagform
3 Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form)
4 Dim doc As Document = Application.DocumentManager.MdiActiveDocument
5 Dim ed As Editor = doc.Editor
6 ' Ask the user to select an entity
7 ' for which to set XData
8 Dim opt As PromptEntityOptions = New PromptEntityOptions("" & vbLf & "Select entity: ")
9 Dim res As PromptSelectionResult = ed.GetSelection
10 Dim I As Long
11 If IsNothing(res.Value) = False Then
12 For I = 1 To res.Value.Count
13 Dim tr As Transaction = doc.TransactionManager.StartTransaction
14 Dim myObject As EditorInput.SelectedObject = res.Value.Item(I - 1)
15 Dim obj As DBObject = tr.GetObject(myObject.ObjectId, OpenMode.ForWrite)
16 AddRegAppTableRecord("TCB")
17 Dim rb As ResultBuffer = New ResultBuffer(New TypedValue(1001, "TCB"), New TypedValue(1000, Mat), New TypedValue(1000, Qty))
18 obj.XData = rb
19 rb.Dispose()
20 tr.Commit()
21 Next
22 End If
23 End Sub
25 Public Sub SetXData()
26 Dim form As New tagform
27 Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form)
28 Dim doc As Document = Application.DocumentManager.MdiActiveDocument
29 Dim ed As Editor = doc.Editor
30 ' Ask the user to select an entity
31 ' for which to set XData
32 Dim opt As PromptEntityOptions = New PromptEntityOptions("" & vbLf & "Select entity: ")
33 Dim res As PromptEntityResult = ed.GetEntity(opt)
34 If (res.Status = PromptStatus.OK) Then
35 Dim tr As Transaction = doc.TransactionManager.StartTransaction
36 Dim obj As DBObject = tr.GetObject(res.ObjectId, OpenMode.ForWrite)
37 AddRegAppTableRecord("TCB")
38 Dim rb As ResultBuffer = New ResultBuffer(New TypedValue(1001, "TCB"), New TypedValue(1000, Mat), New TypedValue(1000, Qty))
39 obj.XData = rb
40 rb.Dispose()
41 tr.Commit()
42 End If
43 Private Sub AddRegAppTableRecord(ByVal regAppName As String)
44 End Sub
Private Sub AddRegAppTableRecord(ByVal regAppName As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tr As Transaction = doc.TransactionManager.StartTransaction
Dim rat As RegAppTable = CType(tr.GetObject(db.RegAppTableId, OpenMode.ForRead, False), RegAppTable)
If Not rat.Has(regAppName) Then
rat.UpgradeOpen()
Dim ratr As RegAppTableRecord = New RegAppTableRecord
ratr.Name = regAppName
rat.Add(ratr)
tr.AddNewlyCreatedDBObject(ratr, True)
End If
tr.Commit()
End Sub