Skip to content

Instantly share code, notes, and snippets.

@GoodBoyNinja
Created June 7, 2021 20:51
Show Gist options
  • Save GoodBoyNinja/5c68422c6946f76362f4c001e6211804 to your computer and use it in GitHub Desktop.
Save GoodBoyNinja/5c68422c6946f76362f4c001e6211804 to your computer and use it in GitHub Desktop.
This function takes an array of properties and separates them into properties, groups and indexed groups. It returns an object, you you can later on access the array you are interested in. Example: var variableName = separateGroupsAndProperties([app.project.activeItem.selectedProperties]).groups;
function separateGroupsAndProperties (propsArray) {
// sorting an array of props to props an group... return an object
var resultObject = {
all: [],
props: [],
groups: [],
indexedGroups: [],
};
if (propsArray) {
for (var i = 0; i < propsArray.length; i++) {
var crntProp = propsArray[i];
if (!crntProp) {
continue;
}
switch (crntProp.propertyType) {
case PropertyType.PROPERTY:
resultObject.all.push(crntProp);
resultObject.props.push(crntProp);
break;
case PropertyType.INDEXED_GROUP:
resultObject.all.push(crntProp);
resultObject.indexedGroups.push(crntProp);
default:
resultObject.all.push(crntProp);
resultObject.groups.push(crntProp);
}
}
}
return resultObject;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment