<?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: Events Not Triggering After First Command in AutoCAD .NET API in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13323664#M813</link>
    <description>&lt;P&gt;In my experience when the event handlers for autocad stop working it is almost always because there was an exception in my code that was not caught and handled correctly.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Feb 2025 16:13:52 GMT</pubDate>
    <dc:creator>Keith.Brown</dc:creator>
    <dc:date>2025-02-17T16:13:52Z</dc:date>
    <item>
      <title>Events Not Triggering After First Command in AutoCAD .NET API</title>
      <link>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13322948#M811</link>
      <description>&lt;P&gt;&lt;FONT color="#000000"&gt;Hi everyone,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I’m using the AutoCAD .NET API to update block attributes when a block is rotated. The issue is that after the &lt;STRONG&gt;first&lt;/STRONG&gt; rotation command, the CommandStarted and CommandEnded events do not trigger again for subsequent rotations.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I’ve attached event handlers to detect the ROTATE command, but they only fire for the first rotation.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Has anyone encountered a similar issue or found a way to ensure events fire after every rotation?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thanks!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 09:23:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13322948#M811</guid>
      <dc:creator>Melis_YagmurQSH4P</dc:creator>
      <dc:date>2025-02-17T09:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Events Not Triggering After First Command in AutoCAD .NET API</title>
      <link>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13323333#M812</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;If you don't post your code, you won't get any answers, only guesses.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 13:49:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13323333#M812</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-02-17T13:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Events Not Triggering After First Command in AutoCAD .NET API</title>
      <link>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13323664#M813</link>
      <description>&lt;P&gt;In my experience when the event handlers for autocad stop working it is almost always because there was an exception in my code that was not caught and handled correctly.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 16:13:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13323664#M813</guid>
      <dc:creator>Keith.Brown</dc:creator>
      <dc:date>2025-02-17T16:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Events Not Triggering After First Command in AutoCAD .NET API</title>
      <link>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13324868#M814</link>
      <description>&lt;P&gt;public void Initialize()&lt;BR /&gt;{&lt;BR /&gt;Application.DocumentManager.MdiActiveDocument.CommandEnded += OnCommandEnded;&lt;BR /&gt;Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nRotation Sync Loaded.");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public void Terminate()&lt;BR /&gt;{&lt;BR /&gt;Application.DocumentManager.MdiActiveDocument.CommandEnded -= OnCommandEnded;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void OnCommandEnded(object sender, CommandEventArgs e)&lt;BR /&gt;{&lt;BR /&gt;if (e.GlobalCommandName.Equals("ROTATE", StringComparison.OrdinalIgnoreCase))&lt;BR /&gt;{&lt;BR /&gt;Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database db = doc.Database;&lt;BR /&gt;Editor ed = doc.Editor;&lt;/P&gt;&lt;P&gt;using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);&lt;BR /&gt;BlockTableRecord modelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);&lt;/P&gt;&lt;P&gt;TypedValue[] filter = { new TypedValue((int)DxfCode.Start, "INSERT") };&lt;BR /&gt;SelectionFilter selectionFilter = new SelectionFilter(filter);&lt;BR /&gt;PromptSelectionResult selRes = ed.SelectAll(selectionFilter);&lt;/P&gt;&lt;P&gt;if (selRes.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet sset = selRes.Value;&lt;BR /&gt;var filteredBlocks = sset.Cast&amp;lt;SelectedObject&amp;gt;()&lt;BR /&gt;.Select(selObj =&amp;gt; tr.GetObject(selObj.ObjectId, OpenMode.ForRead) as BlockReference)&lt;BR /&gt;.Where(blkRef =&amp;gt; blkRef != null &amp;amp;&amp;amp;&lt;BR /&gt;blkRef.Name == "profile")&lt;BR /&gt;.ToList();&lt;/P&gt;&lt;P&gt;foreach (var blkRef in filteredBlocks)&lt;BR /&gt;{&lt;BR /&gt;if (blkRef != null)&lt;BR /&gt;{&lt;BR /&gt;UpdateAngleAttribute(tr, blkRef);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;tr.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code and how I solved it. I was subscribing to CommandWillStart event too,&lt;/P&gt;&lt;P&gt;but when I delete is it worked only with&amp;nbsp;OnCommandEnded event. I don't know if this is a logical solution or not but it works.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 07:23:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13324868#M814</guid>
      <dc:creator>Melis_YagmurQSH4P</dc:creator>
      <dc:date>2025-02-18T07:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Events Not Triggering After First Command in AutoCAD .NET API</title>
      <link>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13324927#M815</link>
      <description>&lt;P&gt;While you may think that code works, it only reacts to the Rotate command, and because it doesn't know what objects were rotated, it forces you to find all of your objects-of-interest. Another issue is that you're using Transactions inside an event handler, which is a no-no. Doing that will corrupt UNDO/REDO, which you probably haven't tested. You should be using an OpenCloseTransaction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the clip below, regardless of how the blocks are rotated, or with what command, the attributes always maintain a rotation of 0 relative to the X-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="acad_4IeSDqmeOU.gif" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1468084i44303A1AA972574B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="acad_4IeSDqmeOU.gif" alt="acad_4IeSDqmeOU.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code that does what you see in the clip can be found in &lt;A href="https://github.com/ActivistInvestor/Overrules/tree/main/BlockAttributeOverrule" target="_blank" rel="noopener"&gt;this repository folder.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 07:58:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/events-not-triggering-after-first-command-in-autocad-net-api/m-p/13324927#M815</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2025-02-18T07:58:22Z</dc:date>
    </item>
  </channel>
</rss>

