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

elockviolation error

4 REPLIES 4
Reply
Message 1 of 5
a7v1n
458 Views, 4 Replies

elockviolation error




Pls help. I have a function under a form class and i am getting an elockviolation error everytime i execute the function. Does anyone know why this occurs?







Private Sub createP1()

Dim myTransMan As DatabaseServices.TransactionManager

Dim myTrans As DatabaseServices.Transaction

Dim myDwg As Document

Dim myBT As BlockTable

Dim myBTR As BlockTableRecord

Dim startPt As Geometry.Point3d

Dim endPt As Geometry.Point3d

Dim myBTE As SymbolTableEnumerator

myDwg = Application.DocumentManager.MdiActiveDocument

myTransMan = myDwg.TransactionManager

myTrans = myTransMan.StartTransaction

myBT = myDwg.Database.BlockTableId.GetObject(OpenMode.ForWrite) <------ here is where the error is (elockviolation)

Dim i As Integer = 0

Dim bfound As Boolean = False

myBTE = myBT.GetEnumerator

While (myBTE.MoveNext = True) And (Not bfound)

myBTR = myBTE.Current.GetObject(OpenMode.ForRead)

If myBTR.Name = "LineBlock" Then bfound = True

End While

If Not bfound Then

startPt = New Geometry.Point3d(0, 0, 0)

endPt = New Geometry.Point3d(2, 3, 0)

Dim line1 As New Line(startPt, endPt)

myBTR = New BlockTableRecord

myBTR.Name = "LineBlock"

myBTR.AppendEntity(line1)

myBT.Add(myBTR)

myTrans.AddNewlyCreatedDBObject(myBTR, True)

End If

myTrans.Commit()

myTrans.Dispose()

myTransMan.Dispose()

End Sub

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: a7v1n


The reason of this error is most likely caused by
the way you show your FORM: is it a modal form or modeless form? I'd bet it is
latter (or a Palette). You need to lock the document before making changes to
the drawing database.

 

Something like this (C# code):

 

 

using (DocumentLock lock =
myDwg.LockDocument())

{

    using (Transaction
tran=mDwg.Database.TransactionManager.StartTransaction())

    {

        //Do your
transaction here...

    }

}

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">




Pls help. I have a function under a form class and i am getting
an elockviolation error everytime i execute the function. Does anyone know why
this occurs?







Private Sub createP1()

Dim
myTransMan As DatabaseServices.TransactionManager

Dim myTrans As
DatabaseServices.Transaction

Dim myDwg As Document

Dim myBT As
BlockTable

Dim myBTR As BlockTableRecord

Dim startPt As
Geometry.Point3d

Dim endPt As Geometry.Point3d

Dim myBTE As
SymbolTableEnumerator

myDwg =
Application.DocumentManager.MdiActiveDocument

myTransMan =
myDwg.TransactionManager

myTrans =
myTransMan.StartTransaction

myBT =
myDwg.Database.BlockTableId.GetObject(OpenMode.ForWrite) <------ here is
where the error is (elockviolation)

Dim i As Integer = 0

Dim
bfound As Boolean = False

myBTE = myBT.GetEnumerator

While
(myBTE.MoveNext = True) And (Not bfound)

myBTR =
myBTE.Current.GetObject(OpenMode.ForRead)

If myBTR.Name = "LineBlock"
Then bfound = True

End While

If Not bfound Then

startPt =
New Geometry.Point3d(0, 0, 0)

endPt = New Geometry.Point3d(2, 3,
0)

Dim line1 As New Line(startPt, endPt)

myBTR = New
BlockTableRecord

myBTR.Name =
"LineBlock"

myBTR.AppendEntity(line1)

myBT.Add(myBTR)

myTrans.AddNewlyCreatedDBObject(myBTR,
True)

End
If

myTrans.Commit()

myTrans.Dispose()

myTransMan.Dispose()

End
Sub

Message 3 of 5
a7v1n
in reply to: a7v1n

hi. do i need to unlock the document after i lock it? if yes, how do you unlock a document?
Message 4 of 5
Anonymous
in reply to: a7v1n


Dispose the DocumentLock will unlock the document.
Notice that I use it with "using.....", which guarantees the Documentlock is
disposed.

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
hi.
do i need to unlock the document after i lock it? if yes, how do you unlock a
document?
Message 5 of 5
a7v1n
in reply to: a7v1n


Hi. Is this coding correct? This is done in vb.net and I'm not sure if the drawing is unlocked after the command finished executing. Thanks so much.



Dim lock As DocumentLock



myDwg = Application.DocumentManager.MdiActiveDocument



lock = myDwg.LockDocument



Using lock



....

End Using

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