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.
Struggling with feature script units...
dave_franchino
Member Posts: 52 ✭✭
Hey kind folks,
I'm trying to explore feature script and am really struggling to get units correct. It's worth saying that I don't really know javascript so I'm probably way over my head.
In the following feature script i'm trying to create a spline on a plane based on equations for x and y.
I'm getting an error...
https://cad.onshape.com/documents/58cd64645b11f7ce6f6724b0/w/f1e068070f1a512dbf46e2fb/e/efde6f957c03969e8312bbeb
Can anyone help me with how to define variables so that I can use the correctly?
Thanks!
I'm trying to explore feature script and am really struggling to get units correct. It's worth saying that I don't really know javascript so I'm probably way over my head.
In the following feature script i'm trying to create a spline on a plane based on equations for x and y.
I'm getting an error...
Can not subtract number and ValueWithUnits (map) |
https://cad.onshape.com/documents/58cd64645b11f7ce6f6724b0/w/f1e068070f1a512dbf46e2fb/e/efde6f957c03969e8312bbeb
Can anyone help me with how to define variables so that I can use the correctly?
Thanks!
0
Comments
Sounds like you have a variable somewhere that does not have a length assigned to it.
An equation like:
var b = 6*millimeter;
var a = 5 + b;
Doesn't work because b has a type of "value with units" where as "5" is just a number. In FeatureScript keeping track of what has units and what doesn't have units really matters. But the benefit is that FeatureScript does a lot of the heavy lifting when it comes to unit conversion.
Custom FeatureScript and Onshape Integrated Applications
a = 5*inch + b; would work.
in case you're not sure about b,
println(b);
When writing FS I change the document units to meters. If you think in inches, then you'll have to worry about values with units when writing scripts. The base units for FS are meters, anything else requires values with units.
If you printout what's returned, you'll see when things are value with unit's. To remove them just /meter then print the return again and they're gone. If you want to add them to something that doesn't have them, then *meter. Then print them again and you'll see they are back. I prefer to work without them, but I could be wrong.
When I'm writing FS my units are meters. If you're converting m^3/h to gpm in your feature script, then you might want to stick with values with units. Honestly, I don't think m^3/h is a type in FS, there's probably a way to add it though.
Thanks for your input - sorry about the private document - I'm new to onshape and didn't realize I needed to make the document private. I have hopefully fixed it here:
https://cad.onshape.com/documents/58cd64645b11f7ce6f6724b0/w/f1e068070f1a512dbf46e2fb/e/efde6f957c03969e8312bbeb
I'm trying to write an equation and use that to drive a spline on a plane.
The relevant section of code that's failing is as follows:
The line that is failing is var planePoint = worldToPlane(sketchPlane, point);
Can not subtract number and ValueWithUnits (map)
Do you see what I'm doing wrong?
Sorry about the naive questions - I'm a rookie here. Be gentle! THanks for the help!!
Dave
I think you're point is bugging. you're creating a vector with (x, y, 0).
x and y are both ValueWithUnits, 0 is not. Try "0*meter".
I tried it in a copy and I "got here 2" ;-)
https://cad.onshape.com/documents/88de244120ace6beb90dbd86/w/97eedd8f6159633b6f313277/e/7df1a69d29d51d884d8f2c63?renderMode=0&uiState=6679241dd33e3b19e075ccae
Tip: a println(point); or debug(context, point); provides more valuable insight than debug(context, got here);
try that and see if you can spot the difference between 0 and 0*meter there.
kind regards
Jelte
you might get away with only 'common.fs' which will make it slightly faster. not sure though. if that starts bugging, try 'geometry.fs' instead (rather than both)