XCAD.NET
XCAD.NET
Framework for .NET (C# and VB.NET) to create modern application for CAD systems (SOLIDWORKS)
Get technical support Access source code Explore code and application examples

Selection box control in SOLIDWORKS Property Page with xCAD framework


Selection box control
Selection box control

Selection box will be generated for the public properties of IXSelObject

public class SelectionBoxDataModel
{
    public SwBody Body { get; set; }

    [SelectionBoxOptions(SelectType_e.Edges, SelectType_e.Notes, SelectType_e.CoordinateSystems)]
    public SwSelObject Dispatch { get; set; }
}

Multiple Selection

This attribute is also applicable to lists. In this case multiple selections will be enabled for the selection box:

Multiple entities selected in the selection box
Multiple entities selected in the selection box

public class SelectionBoxListDataModel
{
    public List<SwBody> Bodies { get; set; } = new List<SwBody>();

    [SelectionBoxOptions(SelectType_e.Edges, SelectType_e.Notes, SelectType_e.CoordinateSystems)]
    public List<SwSelObject> Dispatches { get; set; } = new List<SwSelObject>();
}

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(typeof(PlanarFaceFilter), SelectType_e.Faces)] //setting the standard filter to faces and custom filter to only filter planar faces
        public SwFace PlanarFace { get; set; }
    }

    public class PlanarFaceFilter : ISelectionCustomFilter
    {
        public bool Filter(IControl selBox, IXSelObject selection, SelectType_e selType, ref string itemText)
        {
            itemText = "Planar Face";

            return (selection as SwFace).Face.IGetSurface().IsPlane(); //validating the selection and only allowing planar face
        }
    }
}


Powered by Docify