Exception thrown setting CAM output folder

Exception thrown setting CAM output folder

TimPaterson
Enthusiast Enthusiast
126 Views
4 Replies
Message 1 of 5

Exception thrown setting CAM output folder

TimPaterson
Enthusiast
Enthusiast
My add-in assigns the output folder in an NC Program, like this: 
parameters.itemByName("nc_program_output_folder").value.value = outputFolder

However, if the value being assigned is Fusion's default output folder, or a network share, this assignment throws an exception and the output folder is set to <UNSPECIFIED>.  This happens even when the assignment is just to the current value.

0 Likes
127 Views
4 Replies
Replies (4)
Message 2 of 5

boopathi.sivakumar
Autodesk
Autodesk

Hi @TimPaterson 

Could you try changing the path separator to forward slash (unix like). 

"C:/Users/userName/Documents/Fusion 360/NC Programs"

But I do agree that its wired though to do so for this I bring this up to the team. thanks

Boopathi Sivakumar
Senior Technology Consultant

0 Likes
Message 3 of 5

TimPaterson
Enthusiast
Enthusiast

So using forward slash worked for the local file system.  However, a file share still needs two backslashes.  When I kept that ("\\285k/C/Users...), the assignment statement above converted the double backslash to a single backslash ("\\285k/C/Users..." -> "\285k/C/Users..."), so it didn't work.  It could have been treating the the backslash as an escape character, and I got it to work by putting 4 backslashes in front ("\\\\285k/C/Users..."), which after the assignment became the needed two leading backslashes.

 

Which now makes me think that's why single backslashes don't work in the assignment -- they're escape characters.

0 Likes
Message 4 of 5

TimPaterson
Enthusiast
Enthusiast

My solution is to assign the output folder with this  function:

def AssignOutputFolder(parameters, folder):
    parameters.itemByName("nc_program_output_folder").value.value = folder
    result = parameters.itemByName("nc_program_output_folder").value.value
    if result != folder and folder[0:2] == "\\\\":
        parameters.itemByName("nc_program_output_folder").value.value = "\\\\" + folder    # double up leading "\"
    return None
0 Likes
Message 5 of 5

Jorge_Jaramillo
Collaborator
Collaborator

Hi @TimPaterson ,

 

I'd suggest using raw-strings (r'some text') to specify server name like in the below example:

C:\>python
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep  6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> p1 = Path(r"\\server","c")
>>> p1
WindowsPath('//server/c/')
>>> p2 = Path(r"\\server") / "c" / "docs"
>>> p2
WindowsPath('//server/c/docs')
>>> str(p2)
'\\\\server\\c\\docs'

This way you don't have to care about the number of backslashes.

Also I'd suggest using pathlib to deal with the path constructions, and them to use str() method to convert it to a regular text which you can assign to any string-type variable.

 

Regards,

Jorge Jaramillo

 

0 Likes