📜 ⬆️ ⬇️

Selecting and editing custom primitives in MultiCAD.NET



In one of the previous articles, we talked about how you can create custom primitives using the MultiCAD.NET API, taking the example of CustomObjects from the SDK as a basis. In this article, we will pay attention to the procedure for searching and selecting user objects and expand the existing example by adding the ability to select one or several primitives using the MultiCAD.NET toolkit for further editing. Details - under the cut.

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


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

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 hint 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 SelectObjects() method:

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

The first option is used to select drawing objects based on a given filter, the second one displays a hint to the console and allows the user to select objects himself.

The filter is an object of class ObjectFilter , which defines the criteria for selecting objects: documents, layers, sheets, on which objects of a given type will be searched. For example, in the following example, using the SelectCircles command, SelectCircles will get a list of objects of the "circle" type, which are located 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<McObjectId> 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 command TextInBoxEdit and add the ability to custom select objects. Then, from the entire set of selected objects, we select only user primitives of the TextInBox type:

 [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 has been selected, for each of them we will set the new value to the Text property:

 if (idSelectedTextinBox == null || idSelectedTextinBox.Length == 0) { MessageBox.Show("No TextInBox primitives selected!"); return; } 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: forum.nanocad.ru/index.php?showtopic=6514 .

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

Source: https://habr.com/ru/post/200366/


All Articles