.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
can't dispose xdata
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
i have a combo box which choose from 3 items one is blank. the triggered item changed event will erase the old set of corresponding xdata in the selected object and populate with new ones read from different text boxes. i was able to set the xdata for the first time ok. but when trying to dispose it won't dispose.
Imports System.Runtime
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Create_Pipe_Data.ActiveDrawing
Public Class Container1
Public oSelectedObjID As ObjectId
Public WithEvents doc As Document
Public AppName As String = "CreatePipeData"
Private m_DocData As MyDocData = Nothing
Friend Shared ps As Autodesk.AutoCAD.Windows.PaletteSet = Nothing
Dim myPalette As Container1
<CommandMethod("tp", CommandFlags.Transparent)> _
Public Sub DoIt()
If m_DocData Is Nothing Then m_DocData = New MyDocData
AddHandler AcApp.DocumentManager.DocumentActivated, AddressOf Me.DocumentManager_DocumentActivated
AddHandler AcApp.DocumentManager.DocumentToBeDeactivated, AddressOf Me.DocumentManager_DocumentToBeDeactivated
'check to see if paletteset is already created
If ps Is Nothing Then
'no so create it
ps = New Autodesk.AutoCAD.Windows.PaletteSet("Create Pipe Data")
'create new instance of user control
myPalette = New Container1()
'add it to the paletteset
ps.Add("Create Pipe Data", myPalette)
End If
'turn it on
ps.Visible = True
End Sub
Private Sub AddRegAppTableRecord(ByVal regAppName As String)
Dim db As Database = doc.Database
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Try
Using tr
Dim rat As RegAppTable = DirectCast(tr.GetObject(db.RegAppTableId, OpenMode.ForRead, False), RegAppTable)
If Not rat.Has(regAppName) Then
rat.UpgradeOpen()
Dim ratr As New RegAppTableRecord()
ratr.Name = regAppName
rat.Add(ratr)
tr.AddNewlyCreatedDBObject(ratr, True)
End If
tr.Commit()
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Container1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If m_DocData Is Nothing Then m_DocData = New MyDocData
doc = Application.DocumentManager.MdiActiveDocument
'doc.LockDocument(DocumentLockMode.Write, Nothing, Nothing, True)
' AddHandler doc.ImpliedSelectionChanged, AddressOf ObjectSelected
AddHandler AcApp.DocumentManager.DocumentActivated, AddressOf Me.DocumentManager_DocumentActivated
AddHandler AcApp.DocumentManager.DocumentToBeDeactivated, AddressOf Me.DocumentManager_DocumentToBeDeactivated
'AddHandler doc.ImpliedSelectionChanged, AddressOf ObjectSelected
End Sub
Private Sub DocumentManager_DocumentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
'display the current active document
Try
If Not m_DocData Is Nothing Then
txtADwg.Text = m_DocData.Current.Stuff
doc = Application.DocumentManager.MdiActiveDocument
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub DocumentManager_DocumentToBeDeactivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
'store the current contents
Try
If Not m_DocData Is Nothing Then
m_DocData.Current.Stuff = txtADwg.Text
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ObjectSelectEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles doc.ImpliedSelectionChanged
ObjectSelected()
End Sub
Private Sub ObjectSelected()
'Dim myDB As Database = HostApplicationServices.WorkingDatabase
Dim myEditor As Editor = Application.DocumentManager.MdiActiveDocument.Edit or
Dim PossibleSelectionSet As PromptSelectionResult = myEditor.SelectImplied
Dim mySelectionSet As SelectionSet = Nothing
Dim myObjectIDs As New List(Of ObjectId)
Dim oSelectedObj As DBObject
If PossibleSelectionSet.Status = PromptStatus.OK Then
Using tr As Transaction = doc.TransactionManager.StartTransaction
mySelectionSet = PossibleSelectionSet.Value
For Each mySelObj As SelectedObject In mySelectionSet
myObjectIDs.Add(mySelObj.ObjectId)
Next
End Using
End If
'SET TO LAST OBJECT SELECTED
If myObjectIDs.Count <> 0 Then
Try
Using oLock As DocumentLock = doc.LockDocument() '(DocumentLockMode.Write, Nothing, Nothing, True)
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
oSelectedObj = tr.GetObject(myObjectIDs.Item(myObjectIDs.Count - 1), OpenMode.ForRead, False)
oSelectedObjID = oSelectedObj.ObjectId
'AFTER SELECT OBJECT, POPULATE FORM
PopulateXdataToForm(oSelectedObjID)
End Using
End Using
GroupBox1.Enabled = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
GroupBox1.Enabled = False
End If
End Sub
Private Sub txtType_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtType.MouseLeave
PopulateFormDataToObjectXdata(oSelectedObjID)
End Sub
Private Sub txtMaterial_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMaterial.MouseLeave, TextBox6.MouseLeave, TextBox5.MouseLeave, TextBox4.MouseLeave, TextBox3.MouseLeave, TextBox2.MouseLeave, TextBox1.MouseLeave
PopulateFormDataToObjectXdata(oSelectedObjID)
End Sub
Private Sub txtLength_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLength.MouseLeave
PopulateFormDataToObjectXdata(oSelectedObjID)
End Sub
Private Sub txtInvOut_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtInvOut.MouseLeave
PopulateFormDataToObjectXdata(oSelectedObjID)
End Sub
Private Sub txtInvIn_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtInvIn.MouseLeave
PopulateFormDataToObjectXdata(oSelectedObjID)
End Sub
Private Sub txtGrade_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtGrade.MouseLeave
PopulateFormDataToObjectXdata(oSelectedObjID)
End Sub
Private Sub TxtDiameter_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDiameter.MouseLeave
PopulateFormDataToObjectXdata(oSelectedObjID)
End Sub
Private Sub cmbPipeOrStructure_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPipeOrStructure.SelectionChangeCommitted
PipeStructureChanged()
End Sub
Private Sub PipeStructureChanged()
If cmbPipeOrStructure.Text = "Pipe" Then
gpbPipe.Enabled = True
gpbStructure.Enabled = False
Using oLock As DocumentLock = doc.LockDocument()
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
'Dim oSelectedObj As DBObject = tr.GetObject(oSelectedObjID, OpenMode.ForWrite, False)
'If oSelectedObj.XData <> Nothing Then
' Dim rb As ResultBuffer = oSelectedObj.XData
' rb.Dispose()
'End If
'tr.Commit()
PopulateFormDataToObjectXdata(oSelectedObjID)
End Using
End Using
ElseIf cmbPipeOrStructure.Text = "Structure" Then
gpbStructure.Enabled = True
gpbPipe.Enabled = False
Using oLock As DocumentLock = doc.LockDocument()
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
'Dim oSelectedObj As DBObject = tr.GetObject(oSelectedObjID, OpenMode.ForWrite, False)
'If oSelectedObj.XData <> Nothing Then
' Dim rb As ResultBuffer = oSelectedObj.XData
' rb.Dispose()
'End If
'tr.Commit()
PopulateFormDataToObjectXdata(oSelectedObjID)
End Using
End Using
ElseIf cmbPipeOrStructure.Text = "" Then
ClearTextbox()
gpbStructure.Enabled = False
gpbPipe.Enabled = False
Using oLock As DocumentLock = doc.LockDocument()
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
'Dim oSelectedObj As DBObject = tr.GetObject(oSelectedObjID, OpenMode.ForWrite, False)
'If oSelectedObj.XData <> Nothing Then
' Dim rb As ResultBuffer = oSelectedObj.XData
' rb.Dispose()
'End If
'tr.Commit()
PopulateFormDataToObjectXdata(oSelectedObjID)
End Using
End Using
End If
End Sub
Private Sub ClearTextbox()
txtGrade.Text = ""
txtInvIn.Text = ""
txtInvOut.Text = ""
txtDiameter.Text = ""
txtLength.Text = ""
txtMaterial.Text = ""
txtType.Text = ""
End Sub
'ADD PROPERTY FROM RESULTBUFFER TO TEXTBOX
Private Sub PopulateXdataToForm(ByVal oSelectedObjID As ObjectId)
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
Dim oSelectedObj As DBObject = tr.GetObject(oSelectedObjID, OpenMode.ForWrite, False)
If oSelectedObj.XData = Nothing Then
'IF FRESH OBJECT, CLEAR FORM
ClearTextbox()
Else
'check to see if created by same application
Dim oTypeValueApp As TypedValue = oSelectedObj.XData.AsArray(0)
If oTypeValueApp.Value = AppName Then
For Each oTypedValue In oSelectedObj.XData.AsArray
If oTypedValue.Value <> AppName Then
Dim arSplitPipeData() As String = Split(oTypedValue.Value, ",")
Select Case arSplitPipeData(0).ToString
Case "pipe-structure"
Select Case arSplitPipeData(1).ToString
Case ""
cmbPipeOrStructure.Text = cmbPipeOrStructure.Items(0)
gpbStructure.Enabled = False
gpbPipe.Enabled = False
Case "Pipe"
cmbPipeOrStructure.Text = cmbPipeOrStructure.Items(1)
gpbStructure.Enabled = False
gpbPipe.Enabled = True
Case "Structure"
cmbPipeOrStructure.Text = cmbPipeOrStructure.Items(2)
gpbStructure.Enabled = True
gpbPipe.Enabled = False
End Select
Case "type"
txtType.Text = arSplitPipeData(1).ToString
Case "material"
txtMaterial.Text = arSplitPipeData(1).ToString
Case "diameter"
txtDiameter.Text = arSplitPipeData(1).ToString
Case "invertin"
txtInvIn.Text = arSplitPipeData(1).ToString
Case "invertout"
txtInvOut.Text = arSplitPipeData(1).ToString
Case "length"
txtLength.Text = arSplitPipeData(1).ToString
Case "grade"
txtGrade.Text = arSplitPipeData(1).ToString
End Select
End If
Next
End If
End If
' doc.LockDocument.Dispose()
End Using
End Sub
Private Sub PopulateFormDataToObjectXdata(ByVal oSelectedObjID As ObjectId)
Try
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using oLock As DocumentLock = doc.LockDocument()
Using tr
'doc.LockDocument() '(DocumentLockMode.Write, Nothing, Nothing, True)
Dim oSelectedObj As DBObject = tr.GetObject(oSelectedObjID, OpenMode.ForWrite, False)
'clear xdata
If cmbPipeOrStructure.Text = "" Then
'clear info
oSelectedObj.XData.Dispose()
Exit Sub
ElseIf oSelectedObj.XData <> Nothing Then
oSelectedObj.XData.Dispose()
End If
AddRegAppTableRecord(AppName)
Dim rb As New ResultBuffer
rb.Add(New TypedValue(1001, AppName))
rb.Add(New TypedValue(1000, "pipe-structure," & cmbPipeOrStructure.Text))
rb.Add(New TypedValue(1000, "type," & txtType.Text))
rb.Add(New TypedValue(1000, "material," & txtMaterial.Text))
rb.Add(New TypedValue(1000, "diameter," & txtDiameter.Text))
rb.Add(New TypedValue(1000, "invertin," & txtInvIn.Text))
rb.Add(New TypedValue(1000, "invertout," & txtInvOut.Text))
rb.Add(New TypedValue(1000, "length," & txtLength.Text))
rb.Add(New TypedValue(1000, "grade," & txtGrade.Text))
oSelectedObj.XData = rb
rb.Dispose()
tr.Commit()
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Work: Xeon W3503, 12GB, Quadro 2000, Dell 19' x 2
Home: 3930k, 16GB, GTX 590, Dell U3011
Solved! Go to Solution.
Re: can't dispose xdata
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> but when trying to dispose it won't dispose
does that mean that you try to clean (to delete) the EED from the entity? If so you have to assign new XData containing just one RB-item containing only the App-Code but nothing else, so it get's removed from the entity.
If you do search for anything else, please describe what you mean by "to dispose XDATA" (as I think you don't mean .Dispose really),
PLUS an additional, important tip: please use the icon/function in the message-editor for placing code within the message:
otherwise (you see it in your thread-item) this code is
a) not readable
b) not useable (can't be copied&pasted to an editor as there are line-feeds and spaces lost).
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: can't dispose xdata
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
thanks for showing me that button to paste code. that's where it is. i'll go fix it up
yeah i was trying to run the dispose first then add a new one in or leave it empty. so you are saying just repopulate resultbuffer with empty one. i was trying to get it to the original state before populating xdata. is that doable?
if no xdata part of my code runs fast just populate a blank palette.
Work: Xeon W3503, 12GB, Quadro 2000, Dell 19' x 2
Home: 3930k, 16GB, GTX 590, Dell U3011
Re: can't dispose xdata
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Try
obj.xdata = New ResultBuffer()
to clear it
C6309D9E0751D165D0934D0621DFF27919
Re: can't dispose xdata
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
ha, still doesn't work. the set to new resultbuffer doesn't clear it. maybe a bug?
i changed a little bit here but this is the code that is key to dispose this xdata
Private Sub PopulateFormDataToObjectXdata(ByVal oSelectedObjID As ObjectId)
Try
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using oLock As DocumentLock = doc.LockDocument()
Using tr
'doc.LockDocument() '(DocumentLockMode.Write, Nothing, Nothing, True)
Dim oSelectedObj As DBObject = tr.GetObject(oSelectedObjID, OpenMode.ForWrite, False)
'clear xdata
If cmbPipeOrStructure.Text = "" Then
'clear info
oSelectedObj.XData.Dispose()
ElseIf oSelectedObj.XData <> Nothing Then
oSelectedObj.XData.Dispose()
AddRegAppTableRecord(AppName)
Dim rb As New ResultBuffer
rb.Add(New TypedValue(1001, AppName))
rb.Add(New TypedValue(1000, "pipe-structure," & cmbPipeOrStructure.Text))
rb.Add(New TypedValue(1000, "type," & txtType.Text))
rb.Add(New TypedValue(1000, "material," & txtMaterial.Text))
rb.Add(New TypedValue(1000, "diameter," & txtDiameter.Text))
rb.Add(New TypedValue(1000, "invertin," & txtInvIn.Text))
rb.Add(New TypedValue(1000, "invertout," & txtInvOut.Text))
rb.Add(New TypedValue(1000, "length," & txtLength.Text))
rb.Add(New TypedValue(1000, "grade," & txtGrade.Text))
oSelectedObj.XData = rb
rb.Dispose()
End If
tr.Commit()
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Work: Xeon W3503, 12GB, Quadro 2000, Dell 19' x 2
Home: 3930k, 16GB, GTX 590, Dell U3011
Re: can't dispose xdata
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
As Alfred said, you need a single typed value with the Registered Application name to clear it.
If cmbPipeOrStructure.Text = "" Then
'clear info
Dim rb As New ResultBuffer
rb.Add(New TypedValue(1001, AppName))
oSelectedObj.XData = rb
rb.Dispose()
ElseIf.....

Re: can't dispose xdata
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
yeah that worked. i also read this thread just now and they said you have to specify the app because other people can populate xdata with other app names as well. makes sense. but no way i can find this out on my own without this.
thanks you guys
http://forums.autodesk.com/t5/NET/Delete-XData/td-
Work: Xeon W3503, 12GB, Quadro 2000, Dell 19' x 2
Home: 3930k, 16GB, GTX 590, Dell U3011

