欢迎来到我的博客
Civil 3D开发与应用,欢迎加入QQ群:484124761
AutoCAD开发,欢迎加入QQ群:193522571

AutoCAD中创建分列的多行文本

创建多列的多行文本,

开始使用注释掉的几行代码设置MText的属性,

均会抛出异常,

后来发现使用SetStaticColumns()方法才行。

 

[CommandMethod( "test20240717")]
public void MyCommand_test20240717() // This method can have any name
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    using (Transaction tr = doc.TransactionManager.StartTransaction())
    {
        BlockTableRecord  btr= tr.GetObject(doc.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
        try
        {
            MText mt = new MText();
            mt.SetDatabaseDefaults();
            mt.Contents = "Global web icon\r\nTutorial AutoCAD\r\nhttps://www.tutorial-autocad.com/introduction-to...\r\nHow to use Multiline MTEXT Objects | Tutorial AutoCAD\r\nWEB9- Right-click in the drawing area to invoke a shortcut and select Pan. Drag the view so the new MTEXT object is near the center of your screen. Then right-click in the drawing area again and select Zoom from the shortcut. 10- Drag your cursor upwards to Zoom in for a closer view of the new MTEXT.\r\n\r\nGlobal web icon\r\nAutodesk Help\r\nhttps://help.autodesk.com/view/OARX/2023/ENU\r\nAutoCAD 2023 Developer and ObjectARX Help | Autodesk\r\nWEBGeneral Resources. CAD Management. Customization. Deploy Custom Programs with Plug-in Bundles. Digitally Sign Custom Program Files. DXF Reference.";
            mt.Location = new Point3d(0, 0, 0);
            // 文字高度
            mt.TextHeight = 2.5;
            // 设置静态列宽、列间距、列数
            mt.SetStaticColumns(100, 10, 3);
            // 设置高度
            mt.Height = 25;
            // 下面的几个属性用不成
            // mt.ColumnType = ColumnType.StaticColumns;
            // mt.ColumnCount = 3;
            // mt.ColumnWidth = 100;
            // mt.ColumnGutterWidth = 10;
 

            btr.AppendEntity(mt);
            tr.AddNewlyCreatedDBObject(mt, true);
          }
        catch (System.Exception ex)
        {
            ;
        }
        tr.Commit();
    }
}

 

 


    

  

posted @ 2024-07-17 17:30  david96007  阅读(28)  评论(0编辑  收藏  举报