Selection box control in SOLIDWORKS Property Page with xCAD framework
Selection box will be generated for the public properties of IXSelObject
public class SelectionBoxDataModel { public ISwBody Body { get; set; } [SelectionBoxOptions(new Type[] { typeof(IXEdge), typeof(IXNote), typeof(IXCoordinateSystem) })] public ISwSelObject Dispatch { get; set; } }
Multiple Selection
This attribute is also applicable to lists. In this case multiple selections will be enabled for the selection box:
public class SelectionBoxListDataModel { public List<ISwBody> Bodies { get; set; } = new List<ISwBody>(); [SelectionBoxOptions(new Type[] { typeof(IXEdge), typeof(IXNote), typeof(IXCoordinateSystem) })] public List<ISwSelObject> Dispatches { get; set; } = new List<ISwSelObject>(); }
Additional selection box options can be specified via SelectionBoxOptionsAttribute
Selection Marks
Selection marks are used to differentiate the selection in the selection boxes. In most cases it is required for each selection to come into the specific selection box. In this case it is required to use different selection mark for every selection box. Selection marks are bitmasks, which means that they should be incremented with a power of two (i.e. 1, 2, 4, 8, 16 etc.) in order to be unique. By default xCAD framework will take care of assigning the correct selection marks. However it is possible to manually assign the marks using the corresponding overload of SelectionBoxOptionsAttribute constructors.
Custom selection filters
To provide custom filtering logic for selection box it is required to implement the filter by inheriting the ISelectionCustomFilter interface and assign the filter via overloaded constructor of SelectionBoxAttribute attribute
public class SelectionBoxCustomSelectionFilterDataModel { public class DataGroup { [SelectionBoxOptions(new Type[] { typeof(PlanarFaceFilter), typeof(IXFace) })] //setting the standard filter to faces and custom filter to only filter planar faces public ISwFace PlanarFace { get; set; } } public class PlanarFaceFilter : ISelectionCustomFilter { public void Filter(IControl selBox, IXSelObject selection, SelectionCustomFilterArguments args) { args.Filter = (selection as ISwFace).Face.IGetSurface().IsPlane(); //validating the selection and only allowing planar face if (args.Filter) { args.ItemText = "Planar Face"; } else { args.Reason = "Only planar faces can be selected"; } } } }