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.
Finding feature ID from Featurelist?
EvanReese
Member, Mentor Posts: 2,135 ✭✭✭✭✭
I'm working on a feature with a feature query field that gives me a FeatureList. From that, how do I find a feature ID that I can use in qCapEntity, for example?
Evan Reese
1
Answers
If you use
valuesSortedById
[1], and then take the first entry of that, that will give a correct first id (actually, value. See below). If you usekeys(featureList)
, that will give you the first id alphabetically, not actually the first feature.[1]:
valuesSortedById(context is Context, idToValue is map) returns array
E.g:
const first = valuesSortedById(context, featureList)[0];<br>
EDIT: I just realised that this is values, not keys. See my comment below
IR for AS/NZS 1100
So if Evan is going to deal with featurelist of several instances I would reccomend to try this:
id_i = featurelist[i].key;
If it is something other than qCapEntity that takes a Query, qCreatedBy(FeatureList) [1] could be used to turn it into a Query then.
[1]:
qCreatedBy(features is FeatureList) returns Query
IR for AS/NZS 1100
You might also be able to use query modifiers like qDependency() to get more complex subFeatureIds, although I can't speculate to much since I haven't personally used FeatureLists for any projects (yet).
Lastly, if you're using the FeatureList to choose functions which you've made through FeatureScript, then you can use setAttributes and getAttributes to retrieve the information attached to them, including things like specific feature ids. That's probably the most robust way to handle this, but it obviously requires you to be selecting non-std FeatureScripts.