solidworks-api icon indicating copy to clipboard operation
solidworks-api copied to clipboard

Add selection methods

Open brinkdinges opened this issue 3 years ago • 2 comments

We need these building blocks:

  • [x] Selection type enum/union. Combine the magic strings and swSelectType_e enum.
  • [ ] GetSelected
    • [ ] Object
    • [ ] Object type
    • [ ] Feature/component/face?
  • [ ] Select.X.
    • [ ] Component
    • [ ] Feature
    • [ ] Entity
  • [ ] Selection marks. Can we have static items for marks you use often, like 1 for mates?
  • [x] Appending an existing selection, replace boolean parameter

brinkdinges avatar Dec 24 '22 12:12 brinkdinges

@GeKtvi made a good start with the selection type. They combined the magic strings and integers/enums that solidworks APIs return or require. I always hate that we have to look up that data in the docs, no more!

Since the changes got buried in another PR, I'd like to start here from scratch: https://github.com/CAD-Booster/solidworks-api/tree/selections

Considerations:

  1. I'd like to use swSelectType_e instead of magic integers where possible. ~~Maybe add our own enum with the same values as swSelectType_e.~~ Edit: no we don't need a new enum, we have SelectionType now.
  2. Do we keep the underlying enum and string private (because you should no longer need them) or expose them as public properties (because you will eventually need them anyway)?
  3. How do we determine the type of a selected object? Where do we convert the selection type enum to a SelectionType?
  4. Do we create our own SelectionData object? Does it need to wrap ISelectData? Can we avoid adding this object altogether?
    • I don't understand why it contains a point, mark, callout (what even is the callout?), nearly everything you need for SelectByID2, but not the object's name.
    • In my own code, I have the methods Select.ByName and Select.ByPosition, with optional mark and append arguments. They both call SelectById2. We could add those methods to Model?
Image
  1. Can we, and should we, combine GetSelected and Select in SelectionManager? Right now, the selection manager only handles existing selections. Selecting objects is done via the ModelDocExtension. It's simpler to keep that distinction.

brinkdinges avatar Jul 14 '25 19:07 brinkdinges

Document with all selection types that I checked: Selection types.ods

I found a bunch of issues with the docs, plus one duplicate enum in code and one enum that has a different value in code than in the docs. I reported them all.

brinkdinges avatar Jul 14 '25 21:07 brinkdinges

I added methods to work with the selected objects to the SelectionManager: getting them as a list or enumerable. I want to release a SW2026 compatible version of SolidDNA asap so I'll probably do that soon.

After that, I'd like to add methods to create selections. That is normally done from the ModelExtension but it would be great if we could do that from the SelectionManager.

I don't understand most of the selection PR mentioned above so I can't include that. But I'm copying in the parts that I find useful and understandable.

brinkdinges avatar Dec 01 '25 17:12 brinkdinges

I've added Select methods.

I've skipped SelectionData for now. It's only used for selecting an object when you already have a reference to that object. And from my experience, the solidworks API only uses the Mark property. So I'm not sure if we should wrap the SelectData object and if we need it at all.

brinkdinges avatar Dec 02 '25 10:12 brinkdinges