<?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: Laser cutting workflow - Automating taking a picture to use as canvas - Python script in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887419#M1174</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To solve the "&lt;SPAN&gt;Access is denied" error you're missing the "/python.exe" at the end of line #12.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It worked in my end:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jorge_Jaramillo_0-1720551191130.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1384881i379C7B0DE0F6E15A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jorge_Jaramillo_0-1720551191130.png" alt="Jorge_Jaramillo_0-1720551191130.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regarding the way I exposed the solution to import other modules, it was done that way because at that moment Fusion 360 was using Python version 3.9.x while the current was above 3.11.x (a year ago).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now that Fusion 360 uses Python's 3.11.x it is almost compatible with current standard external modules and could be imported from the standard location using the PATH explained in my post.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'll suggest to transform and run your script as a module instead of a external spawn process, inside Fusion 360's python executable.&amp;nbsp; It'll run faster and safer with the current Python version.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I hope this could help out.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jorge Jaramillo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jul 2024 18:55:45 GMT</pubDate>
    <dc:creator>Jorge_Jaramillo</dc:creator>
    <dc:date>2024-07-09T18:55:45Z</dc:date>
    <item>
      <title>Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12886780#M1170</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are often asked to laser cut foam to accommodate items like in the example below.&lt;/P&gt;&lt;P&gt;So far I managed to write a script that imports an image and places it as a canvas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd love to get some feedback on my proposed workflow:&lt;/P&gt;&lt;P&gt;- Mount a USB camera to a (3m high) ceiling, pointed straight down at a static surface.&lt;/P&gt;&lt;P&gt;- Write a Python script that takes a picture, scales it and places it as a canvas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Since it's a static surface I can calibrate the script to scale the canvas)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then we could:&lt;/P&gt;&lt;P&gt;- Arrange all items on the surface&lt;/P&gt;&lt;P&gt;- Have the script take a picture and place it as a canvas&lt;/P&gt;&lt;P&gt;- Sketch the contours&lt;/P&gt;&lt;P&gt;- Export the DXF for laser cutting&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Searching as I post I find that Fusion has it's own version of Python located in:&lt;/P&gt;&lt;P&gt;C:\Users\...\AppData\Local\Autodesk\webdeploy\production\57........6d\Python\&lt;/P&gt;&lt;P&gt;And this changes with every update. Since I will probably need a Python library to take/process a picture, how do I handle this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your feedback.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jordy_keller_0-1720534876947.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1384743i72A8ACD93CA15E91/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jordy_keller_0-1720534876947.png" alt="jordy_keller_0-1720534876947.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 14:21:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12886780#M1170</guid>
      <dc:creator>jordy_keller</dc:creator>
      <dc:date>2024-07-09T14:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887198#M1171</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the following thread&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/fusion-api-and-scripts/import-data-from-excel-type-xlsx/m-p/11249210#M16720" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-api-and-scripts/import-data-from-excel-type-xlsx/m-p/11249210#M16720&lt;/A&gt;&amp;nbsp;I posted a solution on how to deal with python modules without installing them in the Fusion 360 production environment which is updated with every new release.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this could help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jorge Jaramillo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 17:09:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887198#M1171</guid>
      <dc:creator>Jorge_Jaramillo</dc:creator>
      <dc:date>2024-07-09T17:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887317#M1172</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this seems rather complicated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are my thoughts, correct me if I'm wrong ok?&lt;/P&gt;&lt;P&gt;And I sure would like to know if this is possible and if so, how.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Fusion uses it's own virtual Python environment right?&lt;/P&gt;&lt;P&gt;- Say I install the external libraries I need, onto the systems 'main Python'&lt;/P&gt;&lt;P&gt;- In Fusion I write a script A that calls script B:&lt;/P&gt;&lt;P&gt;- Script B will be on my system and uses the systems 'main Python' (that can use the external libraries)&lt;/P&gt;&lt;P&gt;- From my Fusion script I call script B to run in the systems environment (having access to imaging libraries)&lt;/P&gt;&lt;P&gt;- Script B runs, takes a picture and stores it in a known location&lt;/P&gt;&lt;P&gt;- The Fusion script (A) should be able to retrieve the jpg when script B has been run successfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To test this I have the Fusion script below.&lt;/P&gt;&lt;P&gt;But this gives me this error:&amp;nbsp;PermissionError: [WinError 5] Access is denied&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my question at the moment is how to prevent that error and run (system) script B from the Fusion script?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The complete error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Failed:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;File "C:/Users/......./AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/run_main_script/run_main_script.py", line 17, in run&lt;/P&gt;&lt;P&gt;result = subprocess.run([python_path, script_path], capture_output=True, text=True)&lt;/P&gt;&lt;P&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;File "C:\Users\.......\AppData\Local\Autodesk\webdeploy\production\b7...6d\Python\lib\subprocess.py", line 548, in run&lt;/P&gt;&lt;P&gt;with Popen(*popenargs, **kwargs) as process:&lt;/P&gt;&lt;P&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;File "C:\Users\.......\AppData\Local\Autodesk\webdeploy\production\b7...d\Python\lib\subprocess.py", line 1024, in __init__&lt;/P&gt;&lt;P&gt;self._execute_child(args, executable, preexec_fn, close_fds,&lt;/P&gt;&lt;P&gt;File "C:\Users\.......\AppData\Local\Autodesk\webdeploy\production\b7...6d\Python\lib\subprocess.py", line 1493, in _execute_child&lt;/P&gt;&lt;P&gt;hp, ht, pid, tid = _winapi.CreateProcess(executable, args,&lt;/P&gt;&lt;P&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;return getattr(_subprocess, original_name)(app_name, cmd_line, *args)&lt;/P&gt;&lt;P&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;PermissionError: [WinError 5] Access is denied&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 18:07:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887317#M1172</guid>
      <dc:creator>jordy_keller</dc:creator>
      <dc:date>2024-07-09T18:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887344#M1173</link>
      <description>&lt;P&gt;Additional info:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My 'script B' that is called by Fusion creates a text file with the name that show current date and time:&lt;/P&gt;&lt;P&gt;"2024-07-09_20.13.42.txt"&lt;/P&gt;&lt;P&gt;This script runs ok and works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from datetime import datetime
now = datetime.now()
filename = f'{now.year}-{now.month:02d}-{now.day:02d}_{now.hour:02d}.{now.minute:02d}.{now.second:02d}'
with open(f'{filename}.txt', 'w') as file: pass&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 09 Jul 2024 18:15:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887344#M1173</guid>
      <dc:creator>jordy_keller</dc:creator>
      <dc:date>2024-07-09T18:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887419#M1174</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To solve the "&lt;SPAN&gt;Access is denied" error you're missing the "/python.exe" at the end of line #12.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It worked in my end:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jorge_Jaramillo_0-1720551191130.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1384881i379C7B0DE0F6E15A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jorge_Jaramillo_0-1720551191130.png" alt="Jorge_Jaramillo_0-1720551191130.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regarding the way I exposed the solution to import other modules, it was done that way because at that moment Fusion 360 was using Python version 3.9.x while the current was above 3.11.x (a year ago).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now that Fusion 360 uses Python's 3.11.x it is almost compatible with current standard external modules and could be imported from the standard location using the PATH explained in my post.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'll suggest to transform and run your script as a module instead of a external spawn process, inside Fusion 360's python executable.&amp;nbsp; It'll run faster and safer with the current Python version.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I hope this could help out.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jorge Jaramillo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 18:55:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12887419#M1174</guid>
      <dc:creator>Jorge_Jaramillo</dc:creator>
      <dc:date>2024-07-09T18:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12889840#M1175</link>
      <description>&lt;P&gt;Thanks for mentioning the missing '/python.exe'&lt;/P&gt;&lt;P&gt;I can now run the script without the permission error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess the key point in your post is '&lt;SPAN&gt;transform and run your script as a module&lt;/SPAN&gt;'.&lt;/P&gt;&lt;P&gt;So far I've written only stand-alone scripts in Python so this is something I would have to read up on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have little time the next few days but I will try to works on this and I will post back here with the result, in a few days that is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 18:48:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12889840#M1175</guid>
      <dc:creator>jordy_keller</dc:creator>
      <dc:date>2024-07-10T18:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12895345#M1176</link>
      <description>&lt;P&gt;Ok,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At this point I have an external script that captures an image with my webcam.&lt;/P&gt;&lt;P&gt;The capture is saved as a jpg and I would like fusion to retrieve it and place it as a canvas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I get an error when trying to retrieve the picture tp put it on the canvas, my full code is below but this diagram shows the problem:&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-inline-image-display-wrapper lia-image-align-inline" image-alt="jordy_keller_0-1720860286076.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1386292i314AA4E42A2ADCDC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jordy_keller_0-1720860286076.png" alt="jordy_keller_0-1720860286076.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;1: Start remote script to do a capture. The script runs fine and saves a jpg.&lt;/P&gt;&lt;P&gt;2: Pass the image location back to Fusion as result.stdout&lt;/P&gt;&lt;P&gt;3: The messagebox show the filepath is received&amp;nbsp;&lt;/P&gt;&lt;P&gt;4: Filepath is stored in variable 'imagePath'&lt;/P&gt;&lt;P&gt;5: Error when trying to retrieve the image and placing it as a canvas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I change the filepath to an image that already exists:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="works.jpg" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1386293iABE7CB8380B10A8B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="works.jpg" alt="works.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The image is placed as a canvas without any error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot figure out what is wrong here...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&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;</description>
      <pubDate>Sat, 13 Jul 2024 09:04:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12895345#M1176</guid>
      <dc:creator>jordy_keller</dc:creator>
      <dc:date>2024-07-13T09:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12895349#M1177</link>
      <description>&lt;P&gt;My scripts:&lt;/P&gt;&lt;P&gt;1: Fusion&lt;/P&gt;&lt;P&gt;2: Remote&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import adsk.core, adsk.fusion, adsk.cam, traceback
import subprocess

def run(context):
	
	app = adsk.core.Application.get()
	ui  = app.userInterface

	imagePath = ''
	   
	try:
		
		# Path to main python install that has cv2 installed
		python_path = "C:/Users/xxxxxxx/AppData/Local/Programs/Python/Python312/python.exe"
		# Path to remote script
		script_path = "D:/remote_script/capture.py"

		result = subprocess.run([python_path, script_path], capture_output=True, text=True)

		ui.messageBox(f'returncode: {result.returncode} \r\nstdout from remote script:\r\n {result.stdout}')

		# Check if the script ran successfully
		if result.returncode == 0:
			imagePath = result.stdout
		else:
			ui.messageBox(f'ERROR: {result.returncode}  {result.stderr}')

	except:
		if ui:
			ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

	try:

		des: adsk.fusion.Design = app.activeProduct
		root = des.rootComponent

		# Define the origin and X and Y direction vectors and
		# use Matrix2D.setWithCoordinateSystem to set the matrix.
		origin = adsk.core.Point2D.create(0,0)

		xDir = adsk.core.Vector2D.create(90, 0)										# Width  of canvas in centimeters
		yDir = adsk.core.Vector2D.create(0, 60)										# Height of canvas in centimeters
		matrix = adsk.core.Matrix2D.create()
		matrix.setWithCoordinateSystem(origin, xDir, yDir)

		# Select placement p:

		p = 3
		
		if p == 1: x, y = -90,   0
		if p == 2: x, y =   0,   0
		if p == 3: x, y = -90, -60
		if p == 4: x, y =   0, -60

		matrix.setCell(0,2, x)
		matrix.setCell(1,2, y)

		canvasInput = root.canvases.createInput(imagePath, root.xYConstructionPlane)
		canvasInput.transform = matrix
		canvas = root.canvases.add(canvasInput)

		# Create a new sketch on the XY plane
		sketches = root.sketches
		xyPlane = root.xYConstructionPlane
		sketch = sketches.add(xyPlane)

		sketch.name = 'Contours'

	except:
		if ui:
			ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remote:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import cv2
from datetime import datetime


if __name__ == '__main__':

    now = datetime.now()
    filename = f'capture{now.hour:02d}{now.minute:02d}{now.second:02d}'

    cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)		# Webcam capture
    _, img = cap.read()								# Get image
    
    dest = 'd:/remote_script/'						# Destination folder
    
    cv2.imwrite(f'{dest}{filename}.jpg', img)		# Save as jpg
    print(f'{dest}{filename}.jpg')					# stdout string to Fusion script 
    cap.release()&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 13 Jul 2024 09:08:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12895349#M1177</guid>
      <dc:creator>jordy_keller</dc:creator>
      <dc:date>2024-07-13T09:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Laser cutting workflow - Automating taking a picture to use as canvas - Python script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12895529#M1178</link>
      <description>&lt;P&gt;I have a workaround. Instead of passing the file path I pass the directory that the image is saved in.&lt;/P&gt;&lt;P&gt;The fusion script searches that directory and selects the file with the latest timestamp:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;		jpg_files = [f for f in os.listdir(img_dir.rstrip()) if f.endswith('.jpg')]
		jpg_files.sort(reverse=True)
		imagePath = f'{img_dir.rstrip()}/{jpg_files[0]}'

		try:
			canvasInput = root.canvases.createInput(imagePath, root.xYConstructionPlane)
			canvasInput.transform = matrix
			canvas = root.canvases.add(canvasInput)
		except:
			ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason I have to use rstrip() or I get an error saying there's an extra '\n' in img_dir.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still I do not understand why passing the full path from my remote script doesn't work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jul 2024 13:02:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/laser-cutting-workflow-automating-taking-a-picture-to-use-as/m-p/12895529#M1178</guid>
      <dc:creator>jordy_keller</dc:creator>
      <dc:date>2024-07-13T13:02:44Z</dc:date>
    </item>
  </channel>
</rss>

