I am creating a VBA macro where there are a number of objects and features selected simulatenously.
After using a command such as FeatureManager.InsertMoveCopyBody2, all of the previous selections are removed.
How can I store or save the current selections into memory and then bring them back on command?
I am new to all of this, so any help you can offer is appreciated; thanks.
SolidworksApi macros
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.
____________________________________________________
Regards,
Artem Taturevych, Application Engineer at Intercad (Australia)
translationXpert – add-in to translate SolidWorks models
myIntercad – an integrated tool for SolidWorks Professionals
LinkedIn SolidWorks API Education Group
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.
thanks for the suggestions, i'll try and see how i get on
Edit:
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.
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:
3rd party store: 2016 SOLIDWORKS API Help - IGet3rdPartyStorageStore Method (IModelDocExtension) or 2016 SOLIDWORKS API Help - IGet3rdPartyStorage Method (IModelDoc2)
Persistent ids: 2016 SOLIDWORKS API Help - Persistent Reference IDs
Thanks for the hints anyway.