<?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 fileDialog2 always errors if cancel button is pressed, how do I prevent this? in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/filedialog2-always-errors-if-cancel-button-is-pressed-how-do-i/m-p/10296121#M4255</link>
    <description>&lt;P&gt;So I'm doing a simple export using fileDialog2, if the user cancels or closes the window I get this error Error: Use syntax: FBXExport -f "filename" [-s] and my script exits abruptly.&lt;/P&gt;&lt;P&gt;How do I cleanly cancel out of this, I see you can use -optionsUICancel to run a script after cancel to clean up the nodes left in the scene, but I still get the error, here's my code to test.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;global proc m341_tbExporter_UICancel()
{
    polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
}

string $tbSaveLocation[] = `fileDialog2 -ff "*.fbx" -optionsUICancel m341_tbExporter_UICancel`;
FBXProperty Export|AdvOptGrp|Fbx|AsciiFbx -v "Binary";
FBXExport -f $tbSaveLocation -s;&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 06 May 2021 20:20:33 GMT</pubDate>
    <dc:creator>malcolm_341</dc:creator>
    <dc:date>2021-05-06T20:20:33Z</dc:date>
    <item>
      <title>fileDialog2 always errors if cancel button is pressed, how do I prevent this?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/filedialog2-always-errors-if-cancel-button-is-pressed-how-do-i/m-p/10296121#M4255</link>
      <description>&lt;P&gt;So I'm doing a simple export using fileDialog2, if the user cancels or closes the window I get this error Error: Use syntax: FBXExport -f "filename" [-s] and my script exits abruptly.&lt;/P&gt;&lt;P&gt;How do I cleanly cancel out of this, I see you can use -optionsUICancel to run a script after cancel to clean up the nodes left in the scene, but I still get the error, here's my code to test.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;global proc m341_tbExporter_UICancel()
{
    polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
}

string $tbSaveLocation[] = `fileDialog2 -ff "*.fbx" -optionsUICancel m341_tbExporter_UICancel`;
FBXProperty Export|AdvOptGrp|Fbx|AsciiFbx -v "Binary";
FBXExport -f $tbSaveLocation -s;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 06 May 2021 20:20:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/filedialog2-always-errors-if-cancel-button-is-pressed-how-do-i/m-p/10296121#M4255</guid>
      <dc:creator>malcolm_341</dc:creator>
      <dc:date>2021-05-06T20:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: fileDialog2 always errors if cancel button is pressed, how do I prevent this?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/filedialog2-always-errors-if-cancel-button-is-pressed-how-do-i/m-p/10296602#M4256</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understand your problem correctly,&lt;/P&gt;&lt;P&gt;when you cancel the FileDialog2, your&amp;nbsp;$tbSaveLocation becomes an empty string array.&lt;/P&gt;&lt;P&gt;Passing this empty array to FBXExport, an error will raise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A code like below would do the trick. It won't call FBXExort when user pressed cancel.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;if (size($tbSaveLocation) == 1){
    FBXExport -f $tbSaveLocation -s;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 02:21:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/filedialog2-always-errors-if-cancel-button-is-pressed-how-do-i/m-p/10296602#M4256</guid>
      <dc:creator>e_honda</dc:creator>
      <dc:date>2021-05-07T02:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: fileDialog2 always errors if cancel button is pressed, how do I prevent this?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/filedialog2-always-errors-if-cancel-button-is-pressed-how-do-i/m-p/10296679#M4257</link>
      <description>&lt;P&gt;Yes that's perfect, thanks so much.&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 03:54:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/filedialog2-always-errors-if-cancel-button-is-pressed-how-do-i/m-p/10296679#M4257</guid>
      <dc:creator>malcolm_341</dc:creator>
      <dc:date>2021-05-07T03:54:34Z</dc:date>
    </item>
  </channel>
</rss>

