.NET

Reply
Valued Contributor
yaqiz
Posts: 86
Registered: ‎07-14-2010
Message 1 of 6 (1,467 Views)
Accepted Solution

From Handle to Object

1467 Views, 5 Replies
08-11-2010 09:12 AM

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

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

 

Valued Mentor
caddzone
Posts: 305
Registered: ‎01-26-2005
Message 2 of 6 (1,461 Views)

Re: From Handle to Object

08-11-2010 10:00 AM in reply to: yaqiz

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



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Valued Contributor
yaqiz
Posts: 86
Registered: ‎07-14-2010
Message 3 of 6 (1,431 Views)

Re: From Handle to Object

08-12-2010 02:43 AM 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

Valued Contributor
yaqiz
Posts: 86
Registered: ‎07-14-2010
Message 4 of 6 (1,430 Views)

Re: From Handle to Object

08-12-2010 03:00 AM 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

Valued Contributor
AlexanderRivilis
Posts: 71
Registered: ‎08-31-2007
Message 5 of 6 (1,425 Views)

Re: From Handle to Object

08-12-2010 03:45 AM in reply to: yaqiz
Valued Mentor
caddzone
Posts: 305
Registered: ‎01-26-2005
Message 6 of 6 (1,407 Views)

Re: From Handle to Object

08-12-2010 02:24 PM 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


Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.