Selecting and editing custom primitives in MultiCAD.NET

    In a previous article, we talked about how you can create custom primitives using the MultiCAD.NET API, based on the example of CustomObjects from the SDK. In this article, we will pay attention to the procedure for searching and selecting custom objects and expand the existing example by adding the ability to select one or more primitives using MultiCAD.NET tools for subsequent editing. Details - under the cut.

    So, we have a custom primitive, which is a rectangular frame with a text string inside. Let's look at the task of selecting several objects in a drawing and change the text in each of the selected primitives.

    To select a single object in a drawing, MultiCAD.NET uses the SelectObject () object manager method:

    public static McObjectId SelectObject(string sPromt);
    public static McObjectId SelectObject(string sPromt, ref Point3d pnt);

    Both options allow the user to select an object, while displaying a prompt on the command line. The second method, in addition to the prompt line, also contains a parameter - the point at which the click was made.

    To select multiple objects, use the method SelectObjects():

    public static List SelectObjects(ObjectFilter filter);
    public static McObjectId[] SelectObjects(string sPromt);

    The first option is used to select drawing objects by a given filter, the second one displays a tooltip in the console and allows the user to select objects on his own.

    A class object acts as a filter ObjectFilter, which determines the criteria for selecting objects: documents, layers, sheets, on which objects of a given type will be searched. For example, in the following example, the command SelectCircleswill get a list of objects of the “circle” type that are on the current sheet and intersect the specified rectangular area:

    [CommandMethod("SelectCircles", CommandFlags.NoCheck | CommandFlags.NoPrefix)]
    static public void SelectCirclesCmd()
      ObjectFilter filter = ObjectFilter.Create(true).AddType(DbCircle.TypeID);
      filter.Bound = new BoundBlock(Point3d.Origin, 
                                    new Vector3d(10, 0, 0), 
                                    new Vector3d(0, 10, 0), 
                                    new Vector3d(0, 0, 10));
      List ids = filter.GetObjects();

    To select all the circles in the drawing (not only on the current sheet), add a drawing document as a search area:

    ObjectFilter filter = ObjectFilter.Create(false).SetCurentDocument().AddType(DbCircle.TypeID);

    Register a new team TextInBoxEditand add the ability to custom select objects. Then, from the entire set of selected objects, we select only user primitives of the type TextInBox:

    [CommandMethod("TextInBoxEdit", CommandFlags.NoCheck | CommandFlags.NoPrefix)]
    static public void TextInBoxEditCmd()
      McObjectId[] idSelecteds = McObjectManager.SelectObjects("Select TextInBox primitives to edit");
      McObjectId[] idSelectedTextinBox = Array.FindAll(idSelecteds, (s => (s.GetObject()) is TextInBox));

    If at least one of the primitives was selected, for each of them we will set a new value for the property Text:

    if (idSelectedTextinBox == null || idSelectedTextinBox.Length == 0)
      MessageBox.Show("No TextInBox primitives selected!");
    foreach (McObjectId currID in idSelectedTextinBox)
      (currID.GetObject() as TextInBox).Text = "Changed text";

    Thus, the text will be replaced in all selected primitives.

    Discussion of the article is also available on our forum: .

    English version of the article: Selecting and editing custom entities in MultiCAD.NET .

    Also popular now: