<?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: Why does this give a runtime error on the 2nd run after you undo? in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647488#M1393</link>
    <description>Yeah, it seems to work fine if you run it in global scope, but as soon as you wrap it inside its own scope, it fails.</description>
    <pubDate>Mon, 18 Mar 2024 09:32:21 GMT</pubDate>
    <dc:creator>KasperFilipsen</dc:creator>
    <dc:date>2024-03-18T09:32:21Z</dc:date>
    <item>
      <title>Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647196#M1391</link>
      <description>&lt;P&gt;I'm working on a script where I select the nodes in layers and process them.&lt;/P&gt;&lt;P&gt;I noticed that if I run this script, it works fine, but if I then Undo and try to run it again. I now get a &lt;EM&gt;Runtime error: Attempt to access deleted scene object&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(
	(LayerManager.current).nodes &amp;amp;theNodes
	maxOps.cloneNodes theNodes cloneType:#instance actualNodeList:&amp;amp;currentObjs newNodes:&amp;amp;newObjs
	select newObjs
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does the LayerManager not update after you undo?&lt;BR /&gt;Can you force it to update somehow?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current workaround is to basically make a new array where I check for isValidNode on each node.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 09:38:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647196#M1391</guid>
      <dc:creator>KasperFilipsen</dc:creator>
      <dc:date>2024-03-18T09:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647475#M1392</link>
      <description>&lt;P&gt;don't get any issue with....&lt;/P&gt;&lt;LI-CODE lang="general"&gt;theNodes = #();
newObjs = #();
currentObjs = #();
(LayerManager.current).nodes &amp;amp;theNodes
maxOps.cloneNodes theNodes cloneType:#instance actualNodeList:&amp;amp;currentObjs newNodes:&amp;amp;newObjs
select newObjs&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 09:27:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647475#M1392</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2024-03-18T09:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647488#M1393</link>
      <description>Yeah, it seems to work fine if you run it in global scope, but as soon as you wrap it inside its own scope, it fails.</description>
      <pubDate>Mon, 18 Mar 2024 09:32:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647488#M1393</guid>
      <dc:creator>KasperFilipsen</dc:creator>
      <dc:date>2024-03-18T09:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647502#M1394</link>
      <description>&lt;P&gt;nice not only do we have to solve the issue we have to second guess your code.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 09:36:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647502#M1394</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2024-03-18T09:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647512#M1395</link>
      <description>Yeah I apologize, I'm so used to running everything inside it's own scope I didn't think to wrap the example here. Edited.</description>
      <pubDate>Mon, 18 Mar 2024 09:42:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647512#M1395</guid>
      <dc:creator>KasperFilipsen</dc:creator>
      <dc:date>2024-03-18T09:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647526#M1396</link>
      <description>&lt;P&gt;no probs grumpy monday morning &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; adding a gc() before initializing the arrays seems to work btw,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;though will cause issues if you do it twice in a row &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think going with&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;local temp = for n in theNodes where isValidNode n collect n;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after grabbing the layer nodes is still your best bet :?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 11:49:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647526#M1396</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2024-03-18T11:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647676#M1397</link>
      <description>&lt;P&gt;the reason it works like this is, layers do not maintain a list of nodes they contain as such, instead each node in the scene maintains an reference to an *ILayer (the layer it's in). so&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(LayerManager.current).nodes&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is initialized by iterating over the whole scene and collecting nodes in the current layer even deleted ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the mxs interface to layers has the following in its header description&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;This interface is a facade over disparate property sets on layers:&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can do the same in mxs (but with out the deleted objects) with&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;for i in objects where (refs.dependsOn i)[3] == LayerManager.current.layerAsRefTarg collect i;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;though I wouldn't trust the hard [3] (it's actually 6 in the sdk so should be 7&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_tears_of_joy:"&gt;😂&lt;/span&gt; )&amp;nbsp;for all objects &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 12:17:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12647676#M1397</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2024-03-18T12:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12648804#M1398</link>
      <description>&lt;P&gt;agree with Klvnk...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for n in theNodes where isvalidnode n collect n&lt;/STRONG&gt; is the solution&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 18:44:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12648804#M1398</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2024-03-18T18:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12649103#M1399</link>
      <description>&lt;P&gt;Great find by the way. I tweaked some of my methods because of this problem.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 20:43:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12649103#M1399</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2024-03-18T20:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12650033#M1400</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1794911"&gt;@klvnk&lt;/a&gt;&amp;nbsp;wrote:&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;for i in objects where (refs.dependsOn i)[3] == LayerManager.current.layerAsRefTarg collect i;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Probably faster and more reliable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;layer_ref = layermanager.current.layerasreftarg
for obj in objects where refs.DependencyLoopTest obj layer_ref collect obj&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="general"&gt;layer = layermanager.current
for obj in objects where obj.layer == layer collect obj&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 19 Mar 2024 07:44:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12650033#M1400</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2024-03-19T07:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12650100#M1401</link>
      <description>&lt;P&gt;it was more illustrative than serious &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; it's odd the&lt;STRONG&gt; .layer&lt;/STRONG&gt; property isn't listed in the mxs help I use &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit found it under INodeLayerProperties, weird that they list all the other properties of the INodeLayerProperties interface in the General Node Properties, displayByLayer, motionBylayer etc but not .layer !&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 08:30:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12650100#M1401</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2024-03-19T08:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why does this give a runtime error on the 2nd run after you undo?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12650141#M1402</link>
      <description>&lt;P&gt;After adding "nested" layers, things became more complicated and non-obvious. So I added my own MXS methods to get layer nodes with the optional "nested" argument.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 08:40:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/why-does-this-give-a-runtime-error-on-the-2nd-run-after-you-undo/m-p/12650141#M1402</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2024-03-19T08:40:27Z</dc:date>
    </item>
  </channel>
</rss>

