Class PmpSelectionBox
- Namespace
- Hymma.Solidworks.Addins
- Assembly
- Hymma.Solidworks.Addins.dll
A selection box control for SolidWorks property manager pages that allows users to select entities (faces, edges, bodies, etc.) from the graphics area.
public class PmpSelectionBox : PmpControl<IPropertyManagerPageSelectionbox>, IWrapSolidworksObject<IPropertyManagerPageSelectionbox>, IReleaseSolidworksObject
- Inheritance
-
PmpControl<IPropertyManagerPageSelectionbox>PmpSelectionBox
- Implements
-
IWrapSolidworksObject<IPropertyManagerPageSelectionbox>
- Inherited Members
Examples
Creating a selection box for faces:
var faceSelector = new PmpSelectionBox(
filters: new[] { swSelectType_e.swSelFACES },
style: SelectionBoxStyles.Default,
singleItemOnly: false,
height: 60,
tip: "Select faces to process");
faceSelector.ListChanged += (sender, args) =>
{
Console.WriteLine($"Selection count: {args.Count}");
};
// Validate selections before accepting
faceSelector.SelectionSubmitted += (sender, args) =>
{
var face = args.Selection as IFace2;
return face != null && face.IGetArea() > 0.001;
};
Selection box with context menu:
var selector = new PmpSelectionBox(new[] { swSelectType_e.swSelDRAWINGVIEWS })
{
PopUpMenuItems = new List<PopUpMenuItem>
{
new PopUpMenuItem("Select All", "Select all views", swDocumentTypes_e.swDocDRAWING),
new PopUpMenuItem("Clear", "Clear selection", swDocumentTypes_e.swDocDRAWING)
}
};
Remarks
Selection boxes are the primary way to capture user selections in SolidWorks add-ins. They support filtering by entity type, single or multiple selection, and various display styles.
Key features:
- Filter selections by type (faces, edges, bodies, components, etc.)
- Support for single or multiple selections
- Right-click context menu items via PopUpMenuItems
- Callout support for displaying information near selections
- Events for selection changes, validation, and focus changes
Constructors
PmpSelectionBox(IEnumerable<swSelectType_e>, SelectionBoxStyles, bool, bool, short, string, bool)
constructor
public PmpSelectionBox(IEnumerable<swSelectType_e> filters, SelectionBoxStyles style = SelectionBoxStyles.Default, bool allowMultipleSelectOfSameEntity = true, bool singleItemOnly = false, short height = 50, string tip = "", bool allowSelectInMultipleBoxes = true)
Parameters
filtersIEnumerable<swSelectType_e>- ----- Face
If you want a body to appear in the selection box, then use swSelSOLIDBODIESFIRST. - ----- Component
If you want a face to appear in the selection box, then use swSELCOMPSDONTOVERRIDE. - ----- Component
If you want a body to appear in the selection box, then use swSelSOLIDBODIESFIRST. - ----- Component
If you want a face to appear in the selection box, then use swSelCOMPSDONTOVERRIDE.
If you want a body to appear in the selection box, then use swSelSOLIDBODIESFIRST.
- ----- Face
styleSelectionBoxStylesstyle of this selection box as defined by bitwise SelectionBoxStyles
allowMultipleSelectOfSameEntityboolTrue if the same entity can be selected multiple times in this selection box, false if not
singleItemOnlyboolGets or sets whether this selection box is for single or multiple items.
heightshortheight of selection-box in the pmp
tipstringtip for the selection-box
allowSelectInMultipleBoxesboolGets or sets whether the same entity can be selected multiple times in this selection box.
Properties
AllowSelectInMultipleBoxes
Gets or sets whether an entity can be selected in this selection box if the entity is selected elsewhere.
public bool AllowSelectInMultipleBoxes { get; set; }
Property Value
- bool
When an entity is selected while this selection box is active and that entity is selected in a different selection box, then the entity is added to this selection box. If the entity is already selected in this selection box then the entity is removed from the selection box. When an entity is selected while this selection box is active and that entity is already selected, then the entity is removed from the selection box. This is the default behavior of a selection box.
Callout
create a callout for this selection-box
public CalloutModel Callout { get; set; }
Property Value
Remarks
you should use this property in the context of a part or assembly or drawing environment i.e you cannot use it when SolidWORKS starts
CalloutLabel
a label for the callout, unless this property has a value the callout for this selection box will not be created
public string CalloutLabel { get; set; }
Property Value
CurrentSelection
Gets or sets the index number of the currently selected item in this selection box.
public int CurrentSelection { get; set; }
Property Value
Remarks
The return value Item is the item in the selection box that is selected. Only the active selection box can have a current selection. If you use this property with an inactive selection box, -1 is returned.IsFocused to determine if a selection box is active or not.
CursorStyle
PropertyManager page's cursor after a user makes a selection in the SolidWORKS graphics area.
public PmpCursorStyles CursorStyle { get; set; }
Property Value
Remarks
allows an interactive user to either:
move to the next selection box on the PropertyManager page or
okay and close a PropertyManager page
after making a selection in the SolidWORKS graphics area.
IsFocused
Gets whether this is the active selection box.
public bool IsFocused { get; }
Property Value
- bool
True if the selection box is active, false if not
ItemCount
Gets the number of items currently in this selection box.
public int ItemCount { get; }
Property Value
Mark
Gets the mark used on selected items in this selection box.
public int Mark { get; }
Property Value
- int
mark value for this selectin box
Remarks
Can only be set before selection box is displayed, otherwise will be set automatically. Can be retrieved only after selection box is displayed and if called before selection box is registered returns -1
PopUpMenuItems
Once user RMB on the selection box these items will be listed in the menu that appears
public List<PopUpMenuItem> PopUpMenuItems { get; set; }
Property Value
Methods
Append(object[])
adds the selections to a selectionBox
public void Append(object[] items)
Parameters
itemsobject[]array of selected objects to add to the selection box
Remarks
use this method to add items to the selection box when selection box is not focused. for example you can add all solid bodies of an assembly to a selection box once user clicked on a button.
GetItem(uint)
get the specified item in the selection box
follow instructions in the link below to get the actual object of the selected item
public KeyValuePair<object, swSelectType_e> GetItem(uint index)
Parameters
indexuint0-based index of the item in the selection manager
Returns
- KeyValuePair<object, swSelectType_e>
Selected object as defined in SolidWorks.Interop.swconst.swSelectType_e Nothing or null might be returned if the type is not supported or if nothing is selected
Remarks
- . . .THEN THIS METHOD RETURNS
- Reference surface faces instead of the entire reference surface feature.
- SolidWorks.Interop.sldworks.IDimXpertManager object.
- SolidWorks.Interop.sldworks.IFeature object.
- SolidWorks.Interop.sldworks.IDisplayDimension object instead of the SolidWorks.Interop.sldworks.IDimension object.
- Selected SolidWorks.Interop.sldworks.IDrawingComponent object.
- SolidWorks.Interop.sldworks.IComponent2 object.
GetItems()
gets a dictionary of items and their type in a selection box whether they are selected or not follow instructions in the link below to get the actual object of the selected item
public IEnumerable<KeyValuePair<object, swSelectType_e>> GetItems()
Returns
- IEnumerable<KeyValuePair<object, swSelectType_e>>
a dictionary of items and their type as defined in SolidWorks.Interop.swconst.swSelectType_e Nothing or null might be returned if the type is not supported or if nothing is selected
Remarks
- . . .THEN THIS METHOD RETURNS
- Reference surface faces instead of the entire reference surface feature.
- SolidWorks.Interop.sldworks.IDimXpertManager object.
- SolidWorks.Interop.sldworks.IFeature object.
- SolidWorks.Interop.sldworks.IDisplayDimension object instead of the SolidWorks.Interop.sldworks.IDimension object.
- Selected SolidWorks.Interop.sldworks.IDrawingComponent object.
- SolidWorks.Interop.sldworks.IComponent2 object.
UnsubscribeFromEvents()
Unsubscribes all event handlers from this selection box
public override void UnsubscribeFromEvents()
Events
CallOutCreated
SolidWORKS will invoke this once a call-out is created for this selection box
allows you to collect information such as the selection type from the last selection. Next, use the Callout property to get the Callout object.
Then, use that object's various properties to control the callout text and display characteristics based on that selection information.
public event EventHandler<EventArgs> CallOutCreated
Event Type
CallOutDestroyed
SolidWORKS will invoke this once a callout is destroyed
public event EventHandler<EventArgs> CallOutDestroyed
Event Type
Displaying
fired just a moment before the property manager page and its controls are displayed
public event EventHandler<PmpSelectionBoxDisplayingEventArgs> Displaying
Event Type
FocusChanged
SolidWORKS will invoke this once focus is changed from this selection box
public event EventHandler<EventArgs> FocusChanged
Event Type
ListChanged
Regardless of how many items the user selects, this event is called only once per interactive box selection. In other words, if the user selects six faces using a box selection, this method is called only once.
public event EventHandler<PmpSelectionBoxListChangedEventArgs> ListChanged
Event Type
SelectionSubmitted
Called when a selection is made, which allows the add-in to accept or reject the selection. it must return true for selections to occure
you should pass a delegate that accepts (object WhatIsSelected, int swSelectType_e, string tag)
public event PmpSelectionBoxSelectionSubmittedEventHandler SelectionSubmitted
Event Type
Remarks
This method is called by SolidWORKS when an add-in
has a PropertyManager page displayed and a selection is made that passes the selection
filter criteria set up for a selection list box. The add-in can then:
- Take the Dispatch pointer and the selection type.
- QueryInterface the Dispatch pointer to get the specific interface.
- Use methods or properties of that interface to determine if the selection should be allowed or not.If the selection is:
- accepted, return true, and processing continues normally.
- rejected, return false, and SolidWORKS does not accept the selection, just as if the selection did not pass the selection filter criteria of the selection list box.
The add-in should not release the Dispatch pointer. SolidWORKS will release the Dispatch pointer upon return from this method.
The method is called during the process of SolidWORKS selection.It is neither a pre-notification nor post-notification.
The add-in should not be taking any action that might affect the model or the selection list.The add-in should only be querying information and then returning true/VARIANT_TRUE or false/VARIANT_FALSE.