Lock violation

Lock violation

miguelmachadoecosta
Advocate Advocate
2,679 Views
4 Replies
Message 1 of 5

Lock violation

miguelmachadoecosta
Advocate
Advocate

I have a project which causes a run-time error '-2145386306 (802000be)'

Capturar.PNG

 

I reduced the code causing the error to the following:

 

Events in ThisDrawing module:

 

Public entObj As Object

Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    If Object.ObjectName = "AcDbPolyline" Then Set entObj = Object
End Sub

Sub AcadDocument_EndCommand(ByVal CommandName As String)
    If CommandName = "COPY" Then
        Dim explodedObjects As Variant
        Dim DataType(1) As Integer, Data(1) As Variant
        DataType(0) = 1001: Data(0) = "Test_Application"
        DataType(1) = 1000: Data(1) = "This is a test for xdata"
        
        entObj.SetXData DataType, Data
        
        explodedObjects = entObj.Explode
    End If
End Sub

 

 

Procedure in a regular module:

 

Sub lockViolation()
    Dim i As Integer
    Dim entObj2 As AcadEntity
    Dim DataType(1) As Integer, Data(1) As Variant
    DataType(0) = 1001: Data(0) = "Test_Application"
    DataType(1) = 1000: Data(1) = "This is a test for xdata"
    
    For i = 0 To ThisDrawing.ModelSpace.Count - 1
        Set entObj2 = ThisDrawing.ModelSpace.Item(i)
        If entObj2.ObjectName = "AcDbPolyline" Then entObj2.SetXData DataType, Data
    Next i
End Sub

 

 

I attached a drawing with a single polyline. The error occurs if after copying the polyline twice (the copy mode must be set to "single") I run the "lockViolation" procedure. The error pops in: "entObj2.SetXData DataType, Data", even if entObj2 isn't one of the exploded polylines.

 

What should I do to prevent this lock violation error?

 

Thanks in advance.

0 Likes
2,680 Views
4 Replies
Replies (4)
Message 2 of 5

Ed__Jobe
Mentor
Mentor

Its hard to say since this appears to be only partial code. It seems that you have entObj declared as a global variable. It may still be set to an entity from a previous time you ran the command. I suggest you add a line to release the reference somewhere. I would put it after the line to explode the entity.

 

explodedObjects = entObj.Explode
Set entObect = Nothing

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 5

miguelmachadoecosta
Advocate
Advocate

@Ed__Jobe wrote:

Its hard to say since this appears to be only partial code. It seems that you have entObj declared as a global variable. It may still be set to an entity from a previous time you ran the command. I suggest you add a line to release the reference somewhere. I would put it after the line to explode the entity.

 

explodedObjects = entObj.Explode
Set entObect = Nothing

Thanks for your suggestion.

 

The code I posted is fully independent and I am testing it all by itself.

 

The suggestion didn't solve the problem. Even if I change the variable name to one I never used before and release it after the line to explode I get the lock violation error the first time I run the "lockViolation" method (after the EndCommand event runs twice).

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor

Which version of AutoCAD are you using?

 

I have run your test code lockViolation() without issue with my AutoCAD2017, either use your drawing (only one LwPolyline in it), or a new drawing with a few LwPolylines drawn. I can run the code multiple times. With Express Tool's XData List command  I can see the XData attached correctly.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

miguelmachadoecosta
Advocate
Advocate

@norman.yuan wrote:

Which version of AutoCAD are you using?

 

I have run your test code lockViolation() without issue with my AutoCAD2017, either use your drawing (only one LwPolyline in it), or a new drawing with a few LwPolylines drawn. I can run the code multiple times. With Express Tool's XData List command  I can see the XData attached correctly.


Thanks for your reply.

 

Today I tested with multiple computers with different versions of AutoCAD.

 

All three computers with AutoCAD 2016 produced the lock violation error.

 

These AutoCAD versions didn't produce the error, in addition to your AutoCAD 2017:

- AutoCAD 2014 Architecture

- AutoCAD 2016 Architecture

- AutoCAD 2018

 

Any ideas on how to avoid this error in AutoCAD 2016?

0 Likes