.NET

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

From Handle to Object

1391 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

Valued Mentor
caddzone
Posts: 305
Registered: ‎01-26-2005
Message 2 of 6 (1,385 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,355 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,354 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: 70
Registered: ‎08-31-2007
Message 5 of 6 (1,349 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,331 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


You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community