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

From Handle to Object

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
yaqiz
5195 Views, 5 Replies

From Handle to Object

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

5 REPLIES 5
Message 2 of 6
caddzone
in reply to: yaqiz

Instead of using Convert(), use Int64.Parse() and specify the allowhex option.



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 3 of 6
yaqiz
in reply to: caddzone

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

Message 4 of 6
yaqiz
in reply to: yaqiz

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

Message 5 of 6
AlexanderRivilis
in reply to: yaqiz
Message 6 of 6
caddzone
in reply to: yaqiz

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.
   }

 



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


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