<?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: subprocess.run unable to run external script in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8030973#M16111</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can reproduce the issue in MAC and but it worked&amp;nbsp;well in Windows. I logged it as UP-39001 in our internal system to track the issue. I cannot find workaround for you in MAC. Instead you could run your script in Windows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Marshal&lt;/P&gt;</description>
    <pubDate>Tue, 29 May 2018 01:29:32 GMT</pubDate>
    <dc:creator>marshaltu</dc:creator>
    <dc:date>2018-05-29T01:29:32Z</dc:date>
    <item>
      <title>subprocess.run unable to run external script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8003032#M16108</link>
      <description>&lt;P&gt;Dear Fusion-community&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are currently trying to run a custom external python 3.5 script from a Fusion script. For that we use subprocess.run method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In a normal python environment the command works perfectly fine and produce the following output:&lt;/P&gt;&lt;PRE&gt;&amp;gt;&amp;gt;&amp;gt; import subprocess
&amp;gt;&amp;gt;&amp;gt; subprocess.run(['/Users/Dani/Development/ALPA_Ordering/localpy_3.5/bin/python', '/Users/Dani/Development/ALPA_Ordering/smartsheet_import.py'], stdout=subprocess.PIPE)

CompletedProcess(args=['/Users/Dani/Development/ALPA_Ordering/localpy_3.5/bin/python', '/Users/Dani/Development/ALPA_Ordering/smartsheet_import.py'], returncode=0, stdout=b"{'_orderName': '15_05_2018_OleOle', '_Prozess': 'Formiga 100\xc2\xb5m', '_export': '', '_filepathPNG': '/Users/Dani/Desktop/STL_Export/2018_05_15_15_05_2018_OleOle', '_Lieferant': '', '_Kommentar': '', '_KTI': False, '_Oberflaeche': 'unbehandelt', '_Typ': 'AM Prototyp', '_boundingBox': 17.999999999999993, '_SelectionVolume': 4.075783958277259, '_filepathSTL': '/Users/Dani/Desktop/STL_Export/15_05_2018_OleOle.stl', '_Versanddatum': '11-12-2018', '_Farbe': 'unbehandelt', '_filepathSTP': '/Users/Dani/Desktop/STL_Export/2018_05_15_15_05_2018_OleOle.stp', '_Selection': 'K\xc3\xb6rper', '_Projekt': '1.1 Platon', '_Material': 'PA 2200', '_Quotation': 5.91, '_Anzahl': 1, '_Ausrichtung': 'Eingabe der Orientierung im Bauraum'}\nReached End\n")&lt;/PRE&gt;&lt;P&gt;By running the exact same command in the Fusion script, the script does not do what it is supposed to do and the following output appears:&lt;/P&gt;&lt;PRE&gt;&amp;gt;&amp;gt;&amp;gt; import subprocess
&amp;gt;&amp;gt;&amp;gt; subprocess.run(['/Users/Dani/Development/ALPA_Ordering/localpy_3.5/bin/python', '/Users/Dani/Development/ALPA_Ordering/smartsheet_import.py'], stdout=subprocess.PIPE)

CompletedProcess(args=['/Users/Dani/Development/ALPA_Ordering/localpy_3.5/bin/python', '/Users/Dani/Development/ALPA_Ordering/smartsheet_import.py'], returncode=1, stdout=b'')&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can we execute this external script from a Fusion script?&amp;nbsp; Does have an idea what could have gone wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: We use absolut path to call the script and the directly has 777 permissions. We are on Mac.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We tried also os.sys method, subprocess.check_output method, but they are not running either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance for your support. We're really running out of ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 13:27:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8003032#M16108</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-15T13:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: subprocess.run unable to run external script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8017680#M16109</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did a quick testing with simple Python script (print "Hello World" message). It worked well. I am not sure if you were calling Fusion API in your script which is launched by sub process? It would be good if you can post your test script here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Marshal&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, traceback
import subprocess

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()   
        ui = app.userInterface
        
        subprocess.run(['C:/Python35/python', 'C:/test.py'])
        
        ui.messageBox('Ok')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 May 2018 10:33:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8017680#M16109</guid>
      <dc:creator>marshaltu</dc:creator>
      <dc:date>2018-05-22T10:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: subprocess.run unable to run external script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8018227#M16110</link>
      <description>&lt;P&gt;Dear Marshal,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your answer. Actually, I want to launch a non-Fusion-API script within my Fusion script, which is not working on my computer. I have prepared a little test script to demonstrate what is not working as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fusion Script:&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, adsk.cam, traceback
import subprocess
import os

def find_curr_path():
    """
    Finds the path where the python script is stored
    """
    return os.path.dirname(os.path.realpath(__file__))

def run(context):
    ui = None
    try:
        
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # for my machine
        # /usr/local/bin/python3.5      works
        # /usr/local/bin/python3.6      python crashes
        absolute_python_exec_path = "/usr/local/bin/python3.5"
        a = subprocess.run([absolute_python_exec_path, os.path.join(find_curr_path(), "called.py")])

        print(a.args)
        print(a.stdout)
        print(a.stderr)
        print(a.returncode)

        ui.messageBox('Finished')


    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
        print('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Called.py in the same directory as the Fusion script above:&lt;/P&gt;&lt;PRE&gt;import os&lt;BR /&gt;import time&lt;BR /&gt;&lt;BR /&gt;def find_curr_path():&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Finds the path where the python script is stored&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return os.path.dirname(os.path.realpath(__file__))&lt;BR /&gt;&lt;BR /&gt;"""File to call from the fusion-script, if it works creates a directory"""&lt;BR /&gt;&lt;BR /&gt;print("What")&lt;BR /&gt;# time.sleep(10)&lt;BR /&gt;print("What")&lt;BR /&gt;&lt;BR /&gt;path = os.path.join(find_curr_path(), 'testing')&lt;BR /&gt;&lt;BR /&gt;# attempts to create a directory&lt;BR /&gt;if not os.path.exists(path):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(path)&lt;BR /&gt;
&lt;/PRE&gt;&lt;P&gt;After running this script, the following error code occurs in the spyder console:&lt;/P&gt;&lt;PRE&gt;&amp;gt;&amp;gt;&amp;gt; ['/usr/local/bin/python3.5', '/Users/Dani/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Scripts/Subprocess_Run_Test_Script/called.py']
None
None
1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The exact same command works in another python environment.&lt;/P&gt;&lt;PRE&gt;subprocess.run([absolute_python_exec_path, os.path.join(find_curr_path(), "called.py")])&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I am really running out of ideas what the error could be, I am really looking forward to hearing from you - thanks in advance.&lt;/P&gt;&lt;P&gt;Best wishes,&lt;/P&gt;&lt;P&gt;Danny&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 13:51:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8018227#M16110</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-22T13:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: subprocess.run unable to run external script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8030973#M16111</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can reproduce the issue in MAC and but it worked&amp;nbsp;well in Windows. I logged it as UP-39001 in our internal system to track the issue. I cannot find workaround for you in MAC. Instead you could run your script in Windows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Marshal&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 01:29:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8030973#M16111</guid>
      <dc:creator>marshaltu</dc:creator>
      <dc:date>2018-05-29T01:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: subprocess.run unable to run external script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8050116#M16112</link>
      <description>&lt;P&gt;Thanks a lot Marshal - I really appreciate your support!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The automated ordering tool for AM parts works now on Windows computers in our company. For Mac we found a solution with an external button to run the second script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 11:13:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/subprocess-run-unable-to-run-external-script/m-p/8050116#M16112</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-06T11:13:17Z</dc:date>
    </item>
  </channel>
</rss>

