Hi All,
I saved a object handle in listview item tag
lvItem.tag=objFixture.Handle.ToString
later on I pass this handle to another function
Private Sub func(ByVal strHandle As String, ByVal strError As String) Dim ed As Editor = acApp.DocumentManager.MdiActiveDocument.Editor Dim trans As Transaction = acApp.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction Dim db As Database = acApp.DocumentManager.MdiActiveDocument.Database Try Dim objID As ObjectId = db.GetObjectId(False, New Handle(Convert.ToInt64(strHandle, 16)), 0) Dim objFixture As BlockReference = trans.GetObject(objID, OpenMode.ForWrite) ' Here will throw error Dim rbOld As ResultBuffer = objFixture.GetXDataForApplication(STR_XDATA_FIXTURE) Dim tvOld() As TypedValue = rbOld.AsArray .... ..... Dim rbNew As New ResultBuffer(tvOld) objFixture.XData = rbNew rbNew.Dispose() trans.Commit() Catch ex As Exception ' strError = ex.Message.ToString trans.Abort() Finally trans.Dispose() End Try End Sub
Calling part is
Func(lvItem.Tag.ToString, strError)
Basically I would like to get a blockreference based on the handle then get/set its xdata
Any ideas?
This question may obvious to you guys, as I am new to .Net AutoCAD
Thanks
Solved! Go to Solution.
I have changed to
Dim objID As ObjectId = db.GetObjectId(False, New Handle(Int64.Parse(strHandle, Globalization.NumberStyles.AllowHexSpecifier)), 0) Dim objFixture As BlockReference = trans.GetObject(objID, OpenMode.ForWrite)
but still can not create object.
In my catch
ex.message.tostring is
"eLockViolation"
Any idea?
Thanks
I found the problem
If I try to getObject for Read it works fine, but if for write it doesn't work.
How can that happen?
ex.message.tostring is
"eLockViolation"
thanks
You must use the Document's LockDocument() method to lock the
document before you can open objects for write.
In C# the basic usage is:
using( DocumentLock mylock = myDocument.LockDocument() ) { // here you modify the database. }