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.
Import Value from variable into featurescript
joseph_higgins948
Member Posts: 4 ✭
I am making a configurable drill index that automatically labels the holes for each drill bit.
I have everything working but the auto labeling, I am trying to write either:
1: A function that is addressable in the part studio, that can pull a variable (length with units) from a parts studio and return that value as a string
or
2: A custom feature that basically does the same, but creates a new string variable with that string.
The problems I am running into are (per approach):
1: I can't address the function (which seems to function inside of a feature studio) inside of an expression inside of the relevant the part studio (snippet below)
I have everything working but the auto labeling, I am trying to write either:
1: A function that is addressable in the part studio, that can pull a variable (length with units) from a parts studio and return that value as a string
or
2: A custom feature that basically does the same, but creates a new string variable with that string.
The problems I am running into are (per approach):
1: I can't address the function (which seems to function inside of a feature studio) inside of an expression inside of the relevant the part studio (snippet below)
<div>export function dispAsFract(x)</div><div>{</div><div> var wholeNumber = floor((x + 1e-11 * meter) / inch);</div><div> var remainder = x / inch - wholeNumber;</div><div> var fraction = 1;</div><div> for (var i = 0; i < 8; i += 1)</div><div> {</div><div> if (abs(remainder - round(remainder)) < 1e-11)</div><div> {</div><div> break;</div><div> }</div><div> remainder *= 2;</div><div> fraction *= 2;</div><div> }</div><div> if (fraction == 1)</div><div> {</div><div> return wholeNumber ~ "\"";</div><div> }</div><div> var fractionalPart = round(remainder) ~ "/" ~ fraction;</div><div> if (wholeNumber == 0)</div><div> {</div><div> return fractionalPart ~ "\"";</div><div> }</div><div> return wholeNumber ~ " " ~ fractionalPart ~ "\"";</div><div>}</div>
2: I can't figure out how to query a part studio variable and read that as a ValueWithUnits in feature studio.
<div><br><div> annotation { "Name" : "Selection", "Filter" : (EntityType.VERTEX || EntityType.EDGE || EntityType.FACE || EntityType.BODY) && AllowMeshGeometry.YES, "MaxNumberOfPicks" : 1 }</div><div> definition.seedQueryFeature is FeatureList;</div><div> }</div><div> {</div><div> const val = definition.seedQueryFeature;</div><div> println(val);</div></div><div></div>
that println resolves to: "{ [ FQxAMHpPWDJSZl9_1 ] : <function 15> }" when an appropriate value is selected.
0