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.
Pull selections from a previous feature into new feature
shawn_crocker
Member, OS Professional Posts: 869 PRO
I have modified the sheet metal model feature and adding an enum selection for selecting a material which sets the bend parameters to predetermined values. I now want to modify the finish sheet metal feature to set some custom properties of the finished parts. Does anyone know how I can pull in the previous enum material selection from the parent sheet metal model feature?
Tagged:
0
Best Answer
-
Alex_Kempen Member Posts: 248 EDUBoth my (Updated) Plate FeatureScript and my Variable Library FeatureScript use setAttribute and getAttribute to pull in information from other versions of said feature. Once a feature has set attributes on itself, the question of when you pull in said attributes is up to you; my plate FeatureScript does it in the editing logic, so that it can fill in the feature definition with an exact copy of the other plate's UI (so you don't have to manually recreate the entire plate just to make one or two changes), while the Variable Library FeatureScript does it in the feature body since only its output depends on what it reads off.
// in the sheet metal feature setAttribute(context, { "entities" : qCreatedBy(id + "sheetMetal", EntityType.BODY), "name" : "sheetMetalModel", "attribute" : definition }); // in the finish sheet metal model feature // use getAttributes to get attributes from multiple queries, otherwise use getAttribute for only one at a time const sheetMetalDef = getAttribute(context, { "entity" : definition.myQuery, "name" : "sheetMetalModel" }); if (sheetMetalDef != undefined) { // successful read; use sheetMetalDef to figure out output } else { // failed to read; finish sheet metal model as normal and optionally display error message }
CS Student at UT DallasAlex.Kempen@utdallas.eduCheck out my FeatureScripts here:0
Answers
Thanks for that clarity. I have been able to set and get attributes. I have been able to get an attribute and assign it to a variable (definition.thickness). I have been able to prinln the variable and see it printed but I seem to be unable to use the variable for calculation. It seems like getAttributes is pulling in the value as a string. When I try to use "as valueWithUnits" I get a message in the console "Array index must be number, value is string". I'm not sure how to bring in the attribute so that it is a number value. If I just bring it in without trying to assign it as a type, The whole feature fails as I'm guessing the functions using "definition.thickness" cannot use the type of value that is being assigned to it.
I think I found my problem. I need to drop the getAttribute into a variable. Then assign definition.thickness with the variable and the array reference "[0]" or "[0].somthing if the setAttribute was assigned a map. I didn't realize it was putting the map I was setting into the first location of an array.