XData更新问题
在网上找了段代码,设置元素的XData,第一次是可以的,XData都设置成功了,但是我想修改这个元素的XData,调用这个方法就不行了,程序没有报错。修改的数据写不进去,还是原来的XData,有知道怎么修改XData的朋友可以帮下忙吗,谢谢!===============================================================
Public Shared Sub addXData(ByVal regAppName As String, ByVal ent As Entity, ByVal attribles As Dictionary(Of String, String))
Try
Using trans As Transaction = mDB.TransactionManager.StartTransaction
Dim obj As DBObject = trans.GetObject(ent.ObjectId, OpenMode.ForWrite)
AddRegAppTableRecord(regAppName)
Dim rb As New ResultBuffer()
rb.Add(New TypedValue(1001, regAppName))
Dim pair As KeyValuePair(Of String, String)
For Each item As Object In attribles
pair = item
Dim str As String = pair.Key & "=" & pair.Value
rb.Add(New TypedValue(1000, str))
Next
obj.XData = rb
rb.Dispose()
trans.Commit()
trans.Dispose()
End Using
Catch ex As Exception
mEdt.WriteMessage(vbCrLf & "addXData err " & ex.Message)
End Try
End Sub
Private Shared Sub AddRegAppTableRecord(ByVal regAppName As String)
Using trans As Transaction = mDoc.TransactionManager.StartTransaction()
Dim rat As RegAppTable = DirectCast(trans.GetObject(mDB.RegAppTableId, OpenMode.ForRead, False), RegAppTable)
If Not rat.Has(regAppName) Then
rat.UpgradeOpen()
Dim ratr As New RegAppTableRecord()
ratr.Name = regAppName
rat.Add(ratr)
trans.AddNewlyCreatedDBObject(ratr, True)
End If
trans.Commit()
trans.Dispose()
End Using
End Sub
我觉得你代码没有问题 本帖最后由 ivde 于 2014-11-2 07:23 编辑
要先判断是否有旧的,有就需要新的旧的合并再设置
setxdata对实体而言,你写入什么就拥有什么,没有以前的 ivde 发表于 2014-11-2 07:20 static/image/common/back.gif
要先判断是否有旧的,有就需要新的旧的合并再设置
setxdata对实体而言,你写入什么就拥有什么,没有以前 ...
你好,我还处于学习中,能详细讲下怎么合并吗,可不可以给段代码看看,谢谢! 试试看把 rb.Dispose() 这句取消或移到 trans.Commit() trans.Dispose() 后面去
页:
[1]