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.


Import Value from variable into featurescript

joseph_higgins948joseph_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
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>&nbsp; &nbsp; var wholeNumber = floor((x + 1e-11 * meter) / inch);</div><div>&nbsp; &nbsp; var remainder = x / inch - wholeNumber;</div><div>&nbsp; &nbsp; var fraction = 1;</div><div>&nbsp; &nbsp; for (var i = 0; i < 8; i += 1)</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if (abs(remainder - round(remainder)) < 1e-11)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; remainder *= 2;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; fraction *= 2;</div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp; if (fraction == 1)</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return wholeNumber ~ "\"";</div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp; var fractionalPart = round(remainder) ~ "/" ~ fraction;</div><div>&nbsp; &nbsp; if (wholeNumber == 0)</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return fractionalPart ~ "\"";</div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp; 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>&nbsp; &nbsp; &nbsp; &nbsp; annotation { "Name" : "Selection", "Filter" : (EntityType.VERTEX || EntityType.EDGE || EntityType.FACE || EntityType.BODY) && AllowMeshGeometry.YES, "MaxNumberOfPicks" : 1 }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; definition.seedQueryFeature is FeatureList;</div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; const val = definition.seedQueryFeature;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; println(val);</div></div><div></div>
that println resolves to: "{ [ FQxAMHpPWDJSZl9_1 ] : <function 15> }" when an appropriate value is selected.
Sign In or Register to comment.