Setup Program Comment Expression, Number to String?

Setup Program Comment Expression, Number to String?

long.chang2
Contributor Contributor
1,322 Views
5 Replies
Message 1 of 6

Setup Program Comment Expression, Number to String?

long.chang2
Contributor
Contributor

I'm trying to write an expression for my setup comment for example:

toString(LatheJawBoringDiameter)+' inch OD, '+toString(LatheJawBoringDepth)+' inch Deep '+'Lathe Jaw Boring',

where toString() is a function/expression I hope to find to convert number(with or with out unit) to string, LatheJawBoringDiameter and LatheJawBoringDepth are user parameters. 

So that if I put LatheJawBoringDiameter = 1.5, LatheJawBoringDepth = 0.75, I can get a setup comment as '1.5 inch OD, 0.75 inch Deep Lathe Jaw Boring'. 

What function/expression I should use for toString()?

0 Likes
Accepted solutions (1)
1,323 Views
5 Replies
Replies (5)
Message 2 of 6

KrisKaplan
Autodesk
Autodesk

I believe you would be looking for Python's string formatting.

https://docs.python.org/3.4/library/string.html#string-formatting

This would look something like:

'{:.2} inch OD, {:.2} inch Deep Lathe Jaw Boring'.format(LatheJawBoringDiameter, LatheJawBoringDepth)

Kris



Kris Kaplan
0 Likes
Message 3 of 6

long.chang2
Contributor
Contributor

Thank you for the response. For some reason, it didn't work. Expression like 'Hello'+' World' will be printed out as 'Hello World', but other python expression such as str() or format will leave a blank comment. 

0 Likes
Message 4 of 6

KrisKaplan
Autodesk
Autodesk

I'm not sure what you mean exactly by '"it didn't work". This should just be standard Python. The str() and str.format() functions just return a string, so they should behave the same as any other string.

 

Can you paste a simplified line or two of standalone Python that demonstrates your problem? You could use any Python shell (e.g. https://www.python.org/shell/). For example, the following line demonstrates what I was suggesting. 

print('{:.2} val1, {:.2} val2'.format(1.234, 5.678))

And running this outputs the string "1.2 val1, 5.7 val2".

 

Kris



Kris Kaplan
0 Likes
Message 5 of 6

long.chang2
Contributor
Contributor

Thank you for continue helping me. 

Here, the "Program Comment" is what I want to change. I used edit expression to insert your code in, but no output is generated when I post the program. If I simply put str(12) there, it will output a '-1'. I feel Fusion is using another language in this "Program Comment" area, and there are some predefined variables such as "stockXLow", but it will not read my "user parameters". 

Screen Shot 2020-10-21 at 9.59.05 AM.pngScreen Shot 2020-10-21 at 10.00.47 AM.png

0 Likes
Message 6 of 6

KrisKaplan
Autodesk
Autodesk
Accepted solution

Sorry. Yes. We definitely had a communication problem here. I was assuming you were talking about API scripting as you posted this to the "Fusion 360 API and Scripts" forum. I believe you want to post this question to the Fusion 360 Manufacture forum.

 

This setup postprocess comment expression is not python. The variables you can use in these expressions (like 'stockXLow') are defined in the setup. You can edit the setup.xml for your selected setup to add any variables you might need in this expression. But my knowledge of this area is definitely a bit light, so I would recommend directing further questions to the experts in the Manufacture forum.

 

Kris



Kris Kaplan