I wrote a macro once to save selection sets... I will try to post it here when I can.
If you want to store the selections in the current session only you can just store the values in the array or collection. You can get the pointer to the selection using this method: SelectionMgr::GetSelectedObject6.
If you want to store the selection across the sessions you need to use persistent ids and 3rd party storage or macro features.
Artem Taturevych, Application Engineer at Intercad (Australia)
translationXpert – add-in to translate SolidWorks models
myIntercad – an integrated tool for SolidWorks Professionals
You have to use GetSafeEntity if you want to get a pointer to a model geometry entity that will still be valid after rebuild.
Here's my selection set saver macro.
When you run the macro, a form will appear. Select the things you want to select, then hit "New" under "Edit Set". The macro will save that selection set. If you want to add items to that saved set, just select them and hit "Add".
To re-select the saved selections, hit either "Add" or "New" under "Reselect". Hitting "New" will clear the currently selected items so that only saved entities are selected. Hitting "Add" will add the saved items to the currently selected items.
Currently it works only with entities (faces, edges, vertices, and planes) and ignores everything else. However, you should be able to tweak it to add features, components, dimensions, whatever you want.
SelSaver.swp.zip 20.1 KB
Can you elaborate on storing selections between sessions from non-macro-features? I know of 3rd party storage, but what do you mean by persistent ids? Is it the information I get from `ISelectionMgr.GetSelectionSpecification` (i.e. `selectByString` or `x`, `y`, `z` - I also need `mark`, right?)? How would I use this information then to restore the selection? Do you have an example? Thanks in advance.
OK, I finally got it. Some links to the API documentation:
Persistent ids: 2016 SOLIDWORKS API Help - Persistent Reference IDs
Thanks for the hints anyway.
thanks for the suggestions, i'll try and see how i get on
Thanks all for the advice, although I found an alternative method. ISelectionMgr::SuspendSelectionList() to save the selection list. ISelectionMgr::ResumeSelectionList() to bring the selection list back.
Message was edited by Sam Chung on 22/10/2013 17:08.