tbh not a 'better' solution but a diffrent one:
//check if anything is selected
if not entity_exists(entity('featureset','')) or number_selected(entity('featureset','')) <= 0 {
return
}
//stores the current featureset
entity $currentFs = entity('featureset','')
//copy and the selected features into a new fs then activate the new one
copy featureset ; selected
activate featureset #
//extract the names into a string list
string list $selectedFSNames = extract(components(entity('featureset','')),'Name')
//remove the temp featureset
purge featureset ; yes
//activate the original featureset
activate featureset ${currentFs.Name}
//loop throgh the fs names and activate the features to restore original state
foreach $f in $selectedFSNames {
edit featureset ; select ${f}
}
this is probably slow with large featuresets, maby you should consider to remove the foreach loop at the end
if you don't need to restore the original state.
A Property like (BOOL)IsSelected would be gold here....