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.
Rounding Measured Values in a Custom Table
Rhett_Robinson
Member Posts: 168 PRO
I have a basic table code here:
FeatureScript 2543;
import(path : "onshape/std/table.fs", version : "2543.0");
annotation { "Table Type Name" : "Measured Values Rhett Test" }
export const variableTable = defineTable(function(context is Context, definition is map) returns Table
precondition
{
}
{
var columns = [];
columns = append(columns, tableColumnDefinition("name", "Name"));
columns = append(columns, tableColumnDefinition("value", "Value"));
columns = append(columns, tableColumnDefinition("description", "Description"));
columns = append(columns, tableColumnDefinition("measure type", "Measure Type"));
var rows = [];
var allVars = getAllVariables(context);
for (var key in keys(allVars))
{
if(match(key, "^rhett_(\\S+)").hasMatch) //I honestly have no idea how this works, but it filters only values that contain this prefix!
rows = append(rows, tableRow({ "name" : key, "value" : allVars[key]}));
}
return table("Measured Values", columns, rows);
});
I need any values that fit the key to be rounded to precision. I have not been able to get the rounding to work. I have tried roundToPrecision in various places but it hasn't made a difference.
Is there another way to go about this?
Comments
for (var key in keys(allVars)) { var cellValue = allVars[key]; if (match(key, "^rhett_(\\S+)").hasMatch) cellValue = round(allVars[key], 0.001 * millimeter); rows = append(rows, tableRow({ "name" : key, "value" : cellValue })); }