<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Lock violation in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7350721#M7720</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14801"&gt;@Ed__Jobe&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;explodedObjects = entObj.Explode&lt;BR /&gt;Set entObect = Nothing&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thanks for your suggestion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I posted is fully independent and I am testing it all by itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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).&lt;/P&gt;</description>
    <pubDate>Sun, 03 Sep 2017 14:16:06 GMT</pubDate>
    <dc:creator>miguelmachadoecosta</dc:creator>
    <dc:date>2017-09-03T14:16:06Z</dc:date>
    <item>
      <title>Lock violation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7330644#M7718</link>
      <description>&lt;P&gt;I have a project which causes a run-time error '-2145386306 (802000be)'&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capturar.PNG" style="width: 424px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/394479i826CF7FDA95ADEBF/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capturar.PNG" alt="Capturar.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I reduced the code causing the error to the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Events in ThisDrawing module:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Procedure in a regular module:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attached a drawing with a single polyline. The error occurs if after copying the polyline&amp;nbsp;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What should I do to prevent this lock violation error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Aug 2017 13:08:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7330644#M7718</guid>
      <dc:creator>miguelmachadoecosta</dc:creator>
      <dc:date>2017-08-26T13:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Lock violation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7336253#M7719</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;explodedObjects = entObj.Explode&lt;BR /&gt;Set entObect = Nothing&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:02:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7336253#M7719</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2017-08-29T15:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Lock violation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7350721#M7720</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14801"&gt;@Ed__Jobe&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;explodedObjects = entObj.Explode&lt;BR /&gt;Set entObect = Nothing&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thanks for your suggestion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I posted is fully independent and I am testing it all by itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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).&lt;/P&gt;</description>
      <pubDate>Sun, 03 Sep 2017 14:16:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7350721#M7720</guid>
      <dc:creator>miguelmachadoecosta</dc:creator>
      <dc:date>2017-09-03T14:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Lock violation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7352451#M7721</link>
      <description>&lt;P&gt;Which version of AutoCAD are you using?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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 &amp;nbsp;I can see the XData attached correctly.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 13:39:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7352451#M7721</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2017-09-04T13:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Lock violation</title>
      <link>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7352844#M7722</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Which version of AutoCAD are you using?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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 &amp;nbsp;I can see the XData attached correctly.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today I tested with multiple computers with different versions of AutoCAD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All three computers with AutoCAD 2016 produced the lock violation error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These AutoCAD versions didn't produce the error, in addition to your AutoCAD 2017:&lt;/P&gt;&lt;P&gt;- AutoCAD 2014 Architecture&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- AutoCAD 2016 Architecture&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- AutoCAD 2018&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any ideas on how to avoid this error in AutoCAD 2016?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 18:09:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/lock-violation/m-p/7352844#M7722</guid>
      <dc:creator>miguelmachadoecosta</dc:creator>
      <dc:date>2017-09-04T18:09:27Z</dc:date>
    </item>
  </channel>
</rss>

