Finding feature ID from Featurelist?
EvanReese
Member, Mentor Posts: 3,100 PRO
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?
1
Answers
-
featurelist is map with structure {id: function, ...}. so to get the id of the first entry you can like this: id0 = keys(featureList)[0];
0 -
@Evan_Reese
If you usevaluesSortedById[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
0 -
@MBartlett21 Doesn't valuesSortedById() return the array of values of featurelist itself, meaning it is not an array of separate maps [{id_i: function_i},...], but an array of functions sorted in historical order [function_i, ...]?According to it's usage in applyPattern() it only returns array of feature functions:

So if Evan is going to deal with featurelist of several instances I would reccomend to try this:
id_i = featurelist[i].key;
0 -
Ok. Just realised that

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 Query0 -
Thanks to both of you. keys(featurelist)[0] worked for me. Feature order doesn't matter for what I'm doing. I was headed in the right direction by checking out the featurelist content with println, and trying to get the keys of the map, but hadn't used the keys function before and wasn't aware of it.0
-
You can use an overload of qCreatedBy to get a query for all of the things created by your selected features. Depending on the complexity of the features, you might then be able to use lastModifyingOperationId to get the id of the feature which last operated on your query. This code worked for me:
var solids = qCreatedBy(definition.featureList, EntityType.BODY); var solidId = lastModifyingOperationId(context, qNthElement(solids, 0)); debug(context, qNonCapEntity(solidId, EntityType.FACE));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.Software Developer at Epic SystemsFRC Design Mentor - Team 10553 Orange Overdrive1


