.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete Application xData

13 REPLIES 13
Reply
Message 1 of 14
Anonymous
413 Views, 13 Replies

Delete Application xData

Hi again,

how can I delete the objects xData for a registered application. As I do not want to delete alle xData from the object I need a solution just to delete the xdata for a registered application.

Regards, Jan
13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: Anonymous



ent.XData = new ResultBuffer(new TypedValue(1001,
"RegAppName"));


Hi again,

how can I delete
the objects xData for a registered application. As I do not want to delete alle
xData from the object I need a solution just to delete the xdata for a
registered application.

Regards, Jan
Message 3 of 14
Anonymous
in reply to: Anonymous

It is not as simple as with the ActiveX API you need to read the ResultBuffer from the entity then remove the relevent data and pass the ResultBuffer back.

Regards - Nathan
Message 4 of 14
Anonymous
in reply to: Anonymous

Oops sorry. I did a test before I posted and thought it worked - guess I
should
have checked better.
Thanks!

wrote in message news:5467689@discussion.autodesk.com...
It is not as simple as with the ActiveX API you need to read the
ResultBuffer from the entity then remove the relevent data and pass the
ResultBuffer back.

Regards - Nathan
Message 5 of 14
Anonymous
in reply to: Anonymous

Here is the code I use.

Private Sub RemoveXData(ByVal objEntId As ObjectId, ByVal strAppName As String)
Dim objDB As Database = objEntId.Database
Dim objTrans As Transaction = objDB.TransactionManager.StartTransaction
Dim objEnt As Entity = CType(objTrans.GetObject(objEntId, OpenMode.ForWrite, False), Entity)
If objEnt.XData <> Nothing Then
Dim blnRecord As Boolean = True
Dim objResBuf As ResultBuffer = objEnt.XData
Dim objNewResBuf As ResultBuffer = New ResultBuffer
Dim objTypedVal As TypedValue
For Each objTypedVal In objResBuf
If objTypedVal.TypeCode = 1001 Then
If CType(objTypedVal.Value, String) = strAppName Then
blnRecord = False
Else
blnRecord = True
End If
End If
If blnRecord = True Then objNewResBuf.Add(objTypedVal)
Next objTypedVal
objEnt.XData = objNewResBuf
End If
objTrans.Commit()
objTrans.Dispose()
End Sub
Message 6 of 14
Anonymous
in reply to: Anonymous

Thanks Nathan, Just looked again - I was being a bonehead!@@
"Paul Richardson" wrote in message
news:5467739@discussion.autodesk.com...
Oops sorry. I did a test before I posted and thought it worked - guess I
should
have checked better.
Thanks!

wrote in message news:5467689@discussion.autodesk.com...
It is not as simple as with the ActiveX API you need to read the
ResultBuffer from the entity then remove the relevent data and pass the
ResultBuffer back.

Regards - Nathan
Message 7 of 14
Anonymous
in reply to: Anonymous

Thanks again Nathan.
Regards, Jan
Message 8 of 14
Anonymous
in reply to: Anonymous

Hello Nathan,

the code does not work in all cases.
If the objects has only xData from one registered app and I want to delete that xData with your code nothing happens. If the ResultBuffer is empty and I assign it to the object with:
objEnt.XData = objNewResBuf
... the object will not take the new ResultBuffer as xData. The object will keep the old xData instead.
So the resulting question is: How can I delete all xData from an object?

Regards, Jan
Message 9 of 14
Anonymous
in reply to: Anonymous

I think I found the solution. Please tell me if I am wrong:

Private Sub RemoveXData(ByVal objEntId As ObjectId, ByVal strAppName As String)
Dim objDB As Database = objEntId.Database
Dim objTrans As Transaction = objDB.TransactionManager.StartTransaction
Dim objEnt As Entity = CType(objTrans.GetObject(objEntId, OpenMode.ForWrite, False), Entity)
If objEnt.XData <> Nothing Then
Dim bRemove As Boolean = False
Dim objResBuf As ResultBuffer = objEnt.XData
Dim objNewResBuf As ResultBuffer = New ResultBuffer
Dim objTypedVal As TypedValue
For Each objTypedVal In objResBuf
If objTypedVal.TypeCode = 1001 Then
If CType(objTypedVal.Value, String) = strAppName Then
bRemove = True
objNewResBuf.Add(objTypedVal)
Else
bRemove = False
End If
End If
If bRemove = False Then objNewResBuf.Add(objTypedVal)
Next objTypedVal
objEnt.XData = objNewResBuf
End If
objTrans.Commit()
objTrans.Dispose()
End Sub
Message 10 of 14
Anonymous
in reply to: Anonymous

Thanks. I obviously hadn't spotted that the XData property does not accept an empty ResultBuffer and does not throw exception. Your solution looks fine.

Regards - Nathan
Message 11 of 14
Anonymous
in reply to: Anonymous

I have found that code can corrupt the xdata for the entity.

The following code seems ok.

Public Sub RemoveXData(ByVal objEntId As ObjectId, ByVal strAppName As String)
Dim objDB As Database = HostApplicationServices.WorkingDatabase
Dim objTrans As Transaction = objDB.TransactionManager.StartTransaction
Dim objEnt As Entity = CType(objTrans.GetObject(objEntId, DatabaseServices.OpenMode.ForWrite, False), Entity)
If objEnt.XData <> Nothing Then
Dim blnRecord As Boolean = True
Dim blnFound As Boolean = False
Dim objResBuf As ResultBuffer = objEnt.XData
Dim objNewResBuf As ResultBuffer = New ResultBuffer
Dim objTypedVal As TypedValue
For Each objTypedVal In objResBuf
If objTypedVal.TypeCode = 1001 Then
If CType(objTypedVal.Value, String) = strAppName Then
blnRecord = False
blnFound = True
Else
blnRecord = True
End If
End If
If blnRecord = True Then objNewResBuf.Add(objTypedVal)
Next objTypedVal
If blnFound = True Then objNewResBuf.Add(New TypedValue(1001, strAppName))
objEnt.XData = objNewResBuf
End If
objTrans.Commit()
objTrans.Dispose()
End Sub
Message 12 of 14
Anonymous
in reply to: Anonymous

Why not just use GetXDataForApplication() to avoid
having to deal with all xdata ?

Also, .XData = should not replace
any existing xdata for applications whose ids are
not in the resultbuffer list, you don't have to bother
mucking around with everyone's xdata.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5546639@discussion.autodesk.com...
I have found that code can corrupt the xdata for the entity.

The following code seems ok.

Public Sub RemoveXData(ByVal objEntId As ObjectId, ByVal strAppName As String)
Dim objDB As Database = HostApplicationServices.WorkingDatabase
Dim objTrans As Transaction = objDB.TransactionManager.StartTransaction
Dim objEnt As Entity = CType(objTrans.GetObject(objEntId, DatabaseServices.OpenMode.ForWrite, False), Entity)
If objEnt.XData <> Nothing Then
Dim blnRecord As Boolean = True
Dim blnFound As Boolean = False
Dim objResBuf As ResultBuffer = objEnt.XData
Dim objNewResBuf As ResultBuffer = New ResultBuffer
Dim objTypedVal As TypedValue
For Each objTypedVal In objResBuf
If objTypedVal.TypeCode = 1001 Then
If CType(objTypedVal.Value, String) = strAppName Then
blnRecord = False
blnFound = True
Else
blnRecord = True
End If
End If
If blnRecord = True Then objNewResBuf.Add(objTypedVal)
Next objTypedVal
If blnFound = True Then objNewResBuf.Add(New TypedValue(1001, strAppName))
objEnt.XData = objNewResBuf
End If
objTrans.Commit()
objTrans.Dispose()
End Sub
Message 13 of 14
Anonymous
in reply to: Anonymous

Thanks Tony,

I had been struggling with the XData property today. I think I understand how it should be used now.

Regards - Nathan
Message 14 of 14
Anonymous
in reply to: Anonymous

I stand corrected. I was wrongly making assumptions. The XData property can be used in the same fashion as the ActiveX SetXData method.

Regards - Nathan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost