📜 ⬆️ ⬇️

MultiCAD.NET API: insert block with attributes

In today's publication we will talk about inserting blocks using the MultiCAD.NET API, this is one of the most frequently asked questions in the programmer section of our forum.

So, there is a drawing file that already contains template blocks for the legend of drawing elements, for example, water supply schemes. Suppose the blocks for representing different types of cranes contain two attributes:
and have the following graphical representation:

image

In MultiCAD.NET, the McBlockRef class is used to represent the insertion of a block in a drawing. All you need to do is create an insert object and assign a block name as the BlockName field:
')
 McBlockRef refBlk = new McBlockRef(); refBlk.BlockName = "block_01"; refBlk.DbEntity.AddToCurrentDocument(); 

In MultiCAD.NET, block attributes are stored in the same way as ordinary properties of an object, therefore, to insert a block with specified attribute values, it is enough to access them through DbEntity.ObjectProperties :

 refBlk.DbEntity.ObjectProperties["NAME"] = “”; refBlk.DbEntity.ObjectProperties["LABEL"] = “1127()”; 

The McDocument class contains a method for displaying a dialog with a list of all the blocks present in the document, with which you can select the necessary block for insertion:

image

The following command inserts the selected block into the drawing with the given attribute values. To enter values, use the command line.

 [CommandMethod("smpl_insertBlock", CommandFlags.NoCheck | CommandFlags.Redraw)] static public void smpl_insertBlock() { //    McDocument doc = McDocumentsManager.GetActiveDoc(); if (doc == null) return; String selBlock = String.Empty; McObjectId currId; //     if (doc.ShowSelectBlockForm(ref selBlock, out currId, McContext.MainWindow().Handle)) { McBlockRef refBlk = new McBlockRef(); refBlk.BlockName = selBlock; refBlk.DbEntity.AddToCurrentDocument(); //   InputJig jig = new InputJig(); refBlk.DbEntity.ObjectProperties["NAME"] = jig.GetText("  :"); refBlk.DbEntity.ObjectProperties["LABEL"] = jig.GetText("  :"); } else { MessageBox.Show("  "); } } 

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


All Articles