<?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: Script too fast for UI to keep up in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6638859#M19218</link>
    <description>Thanks.&lt;BR /&gt;&lt;BR /&gt;I'm finding the matrix a bit hard to understand &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Is there any good tutorials or code examples that could help me understand it?</description>
    <pubDate>Sat, 22 Oct 2016 08:17:14 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-10-22T08:17:14Z</dc:date>
    <item>
      <title>Script too fast for UI to keep up</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6625137#M19213</link>
      <description>&lt;P&gt;Programatically, I am selecting multiple pairs of faces to then align&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function shown below is called many times in rapid succession and appeared to show inconsistent / wrong results&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On my old slow laptop, it always worked correctly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In debug mode it always worked correctly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On my desktop machine it never worked&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I concluded that the UI is lagging behind the script so put a blocking pause in place and that fixes it&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better way to detremine if the UI has finished so it's safe to move on and get the next pair?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is commented to show the latest and best result so far but it's not a good solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function alignFaces01(face1,face2) {
  // This function is called many times in rapid succession after programatically determining a 
  // long series of faces to align.
  // 
  // Without the time wasting loop, it appears to have non deterministic behaviour 
  // and random faces will be aligned with each other
  //
  // It was confusing as in debug mode, it always worked correctly
  // and on my laptop (a much slower machine it also worked correctly)
  //
  // I concluded that the UI was not responding quick enough so put in the ui refresh 
  // That didn't work
  // 
  // The sleep function does force it to work but I can't consider that a good solution
  // Is there any good practise that will work reliably?
  
  var app = adsk.core.Application.get();
  var ui  = app.userInterface;

  // Add these faces to the active selection.
  var theseSelections = ui.activeSelections;
  
  // clear any selections pre existing
  theseSelections.clear;
  
  // add the 1st face to the selection  
  theseSelections.add(face1);
  
  // add the 2nd face to the selection
  theseSelections.add(face2);

  // Get the Align Component command and execute it.
  var alignCommand = ui.commandDefinitions.itemById('AlignComponentsCmd');
  alignCommand.execute();
  
  // make sure the viewport has caught up with all the edits
  // this does not work
  app.activeViewport.refresh(); 

  // create delay by pointlessly looping round
  // This works but is terrible practise!!
  // 100 milliseconds does the trick on my desktop machine
  // 50 milliseconds sometimes does it
  // 25 milliseconds does not do it
  sleepOMG(100);

}&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Oct 2016 08:32:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6625137#M19213</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-16T08:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Script too fast for UI to keep up</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6625341#M19214</link>
      <description>&lt;P&gt;Well a few hours away brought me a better solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still doesn't feel excellent but it's better than a fixed loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  // wait here until they are co planar
  var facesAreCoPlanar = false;
  while (facesAreCoPlanar == false) {
    var plane1 = face1.geometry;
    var plane2 = face2.geometry;
    facesAreCoPlanar = plane1.isCoPlanarTo(plane2);    
  }&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Oct 2016 14:26:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6625341#M19214</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-16T14:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Script too fast for UI to keep up</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6626111#M19215</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CommandDefinition.execute method defaults to execute command on application idle if there is no input passed to&amp;nbsp;the method, that means the commands is not executed immediately. You can&amp;nbsp;try to set 'executeImmediately' to true as below to execute the command immediately.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var alignCommand = ui.commandDefinitions.itemById('AlignComponentsCmd');
var nvs = adsk.core.NamedValues.create();
nvs.add('executeImmediately', adsk.core.ValueInput.createByString('true'));
alignCommand.execute(nvs);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jack&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 07:17:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6626111#M19215</guid>
      <dc:creator>liujac</dc:creator>
      <dc:date>2016-10-17T07:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Script too fast for UI to keep up</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6627443#M19216</link>
      <description>Thanks Jack&lt;BR /&gt;&lt;BR /&gt;Seems to work but I'm on my slow laptop so difficult to recreate the problem until I'm back in the UK.&lt;BR /&gt;&lt;BR /&gt;Does it block further execution until it's finished or just start it immediately and then continue anyway?&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;Peter</description>
      <pubDate>Mon, 17 Oct 2016 17:51:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6627443#M19216</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-17T17:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Script too fast for UI to keep up</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6628154#M19217</link>
      <description>&lt;P&gt;For your case above, you selected two faces that satisfied the inputs to execute the&amp;nbsp;&lt;SPAN&gt;AlignComponentsCommand, so it could&amp;nbsp;block&lt;SPAN&gt;&amp;nbsp;further execution until it's finished if set&amp;nbsp;'executeImmediately' to true. Executing internal command is not the formal solution. There are other formal solutions to align components:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;1. Use Occurrence.transform, in this way you have to calculate the matrix first.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;2. Use Joint APIs. This way would be more flexible.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Jack&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 02:31:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6628154#M19217</guid>
      <dc:creator>liujac</dc:creator>
      <dc:date>2016-10-18T02:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Script too fast for UI to keep up</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6638859#M19218</link>
      <description>Thanks.&lt;BR /&gt;&lt;BR /&gt;I'm finding the matrix a bit hard to understand &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Is there any good tutorials or code examples that could help me understand it?</description>
      <pubDate>Sat, 22 Oct 2016 08:17:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-too-fast-for-ui-to-keep-up/m-p/6638859#M19218</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-22T08:17:14Z</dc:date>
    </item>
  </channel>
</rss>

