Thanks for the reply.
But this seems rather complicated.
Here are my thoughts, correct me if I'm wrong ok?
And I sure would like to know if this is possible and if so, how.
- Fusion uses it's own virtual Python environment right?
- Say I install the external libraries I need, onto the systems 'main Python'
- In Fusion I write a script A that calls script B:
- Script B will be on my system and uses the systems 'main Python' (that can use the external libraries)
- From my Fusion script I call script B to run in the systems environment (having access to imaging libraries)
- Script B runs, takes a picture and stores it in a known location
- The Fusion script (A) should be able to retrieve the jpg when script B has been run successfully.
To test this I have the Fusion script below.
But this gives me this error: PermissionError: [WinError 5] Access is denied
So my question at the moment is how to prevent that error and run (system) script B from the Fusion script?
import adsk.core, adsk.fusion, adsk.cam, traceback
import subprocess
def run(context):
app = adsk.core.Application.get()
ui = app.userInterface
try:
# Run the script and wait for it to complete
python_path = "C:/Users/......./AppData/Local/Programs/Python/Python312"
script_path = "D:/Python_testscript/remote_script.py"
result = subprocess.run([python_path, script_path], capture_output=True, text=True)
# Check if the script ran successfully
if result.returncode == 0:
print("Script ran successfully")
print("Output:", result.stdout)
else:
print("Script encountered an error")
print("Error:", result.stderr)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
The complete error message:
Failed:
Traceback (most recent call last):
File "C:/Users/......./AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/run_main_script/run_main_script.py", line 17, in run
result = subprocess.run([python_path, script_path], capture_output=True, text=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\.......\AppData\Local\Autodesk\webdeploy\production\b7...6d\Python\lib\subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\.......\AppData\Local\Autodesk\webdeploy\production\b7...d\Python\lib\subprocess.py", line 1024, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\.......\AppData\Local\Autodesk\webdeploy\production\b7...6d\Python\lib\subprocess.py", line 1493, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\.......\.vscode\extensions\ms-python.debugpy-2024.6.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydev_bundle\pydev_monkey.py", line 901, in new_CreateProcess
return getattr(_subprocess, original_name)(app_name, cmd_line, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [WinError 5] Access is denied