Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Standalone Functions
Sauer
Member Posts: 7 ✭
Hello,
Is it possible to write a standalone function that does not create new features but only returns a value to be used for other inputs in the UI? I'm creating a number of containers that will be 3D printed and want the thin walls to be an ideal thickness for printing. I know the formula used by my slicer to calculate recommended wall thicknesses and want to write a function that will take the layer height, extrusion width, and desired number of perimeters and return the required wall thickness for use in sketches and Shells.
Plugging the following formula into dimension fields in my sketches and other operations (with the placeholders filled with proper values) works just fine, but I'm copying this same formula all over the place and would rather have one function to maintain rather than dozens of separate dimensions fields scattered throughout my model.
number_of_perimeters * extrusion_width - layer_height * (1 - PI/4) * (number_of_perimeters - 1)
0
Best Answer
-
NeilCooke Moderator, Onshape Employees Posts: 5,683Hi, just create a variable with that formula in it and use the result of that in your dimensions.Senior Director, Technical Services, EMEAI4
Answers
The command line evaluation is powerful like @NeilCooke is suggesting, but, one step further, put that single line into a featurescript and it's easier to maintain. You can have a ternary operator on the command line, but why?
Featurescript is so easy to learn and that long expression will be easier to handle using the OS editing space vs. scrolling back & forth along the command line.
One of the things that is really great about OS and is overlooked is the featurescript CLI, it's really good. After you get the expression working on the command line don't stop there and take it into the featurescript environment, you be glad you did.