Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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.

Changing lookup table reference from an ENUM

Nath_McCNath_McC Member Posts: 129 PRO
edited January 20 in FeatureScript

Hi All,

I am creating a "simple" feature script which swaps the lookup table for a different size table (Metric / Imperial set sizes).

I'm getting two issues which I hope are simple fixes but I can't seem to figure them out. Any help would be appreciated.

  1. I am getting a duplication error on the definition.sSize precondition. I understand this but I dont know how to make the definition.sSize either the metricTable or imperialTable
  2. getLookupTable; I was expecting a simple if statement and variable would switch the tables for the "sizeTable", "definition.sSize",

Thank you in advance.

export const metricTable = {
"name" : "metricTable",
"displayName" : "Wire Size",
"entries" : {
"2mm" : { "wireSize" : 2, "drillSize" : 3, "drillDepth" : 5, "outsideDiameter" : 4 },
"2.5mm" : { "wireSize" : 2.5, "drillSize" : 3.5, "drillDepth" : 10, "outsideDiameter" : 5 },
"3mm" : { "wireSize" : 3, "drillSize" :4, "drillDepth" : 12, "outsideDiameter" : 6 },
}
};

export const imperialTable = {
"name" : "imperialTable",
"displayName" : "Wire Size",
"entries" : {
"1/8" : { "wireSize" : 3.17, "drillSize" : 4, "drillDepth" : 10, "outsideDiameter" : 6 },
"1/4" : { "wireSize" : 6, "drillSize" : 7, "drillDepth" : 18, "outsideDiameter" : 12 },
}
};

export enum measurementSystem
{
annotation { "Name" : "Metric" }
METRIC,
annotation { "Name" : "Imeprial" }
IMPERIAL
}
annotation { "Feature Type Name" : "Sizes" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Select Point", "Filter" : EntityType.VERTEX && SketchObject.YES, "MaxNumberOfPick" : 1 }
definition.point is Query;

annotation { "Name" : "Wire", "UIHint" : "SHOW_LABEL" }
definition.measurementSystem is measurementSystem;

if (definition.measurementSystem == measurementSystem.METRIC)
{
annotation { "Name" : "Wire Size", "Lookup Table" : metricTable }
definition.sSize is LookupTablePath;
}

if (definition.measurementSystem == measurementSystem.IMPERIAL)
{
annotation { "Name" : "Wire Size", "Lookup Table" : imperialTable }
definition.sSize is LookupTablePath;
}
}
{

var sizeTable;


if (definition.measurement == measurementSystem.METRIC)
{
sizesTable = "metricTable";
}

if (definition.measurement == measurementSystem.IMPERIAL)
{
sizesTable = "imperialTable";
}


var wireSize = getLookupTable(sizeTable, definition.sSize).wireSize;
var drillSize = getLookupTable(sizeTable, definition.sSize).drillSize;
var drillDepth = getLookupTable(sizeTable, definition.sSize).drillDepth;
var outsideDiameter = getLookupTable(sizeTable, definition.sSize).outsideDiameter;

setVariable(context, "wireSize", wireSize);
setVariable(context, "drillSize", drillSize);
setVariable(context, "drillDepth", drillDepth);
setVariable(context, "outsideDiameter", outsideDiameter);

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,750

    In any precondition, you cannot use the same variable even if it is in a different scope. Rename them different, then use logic in the main code to use the correct variable depending upon the user selection.

    Senior Director, Technical Services, EMEA
Sign In or Register to comment.