zoukankan      html  css  js  c++  java
  • How to get AutoCAD Mtext content

    #region 提取一个图层上的各类元素
            [CommandMethod("BlockInLayerCAD")]
            public void BlockInLayerCAD()
            {
                Document ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Database db = HostApplicationServices.WorkingDatabase;
    
                //PromptStringOptions pStringOption = new PromptStringOptions("
     输入一个图层名");
                //PromptResult layerName = pDocument.Editor.GetString(pStringOption);
                List<string> layerNames = new List<string>();
                using (Transaction tran = db.TransactionManager.StartTransaction())
                {
                    #region 获取图层名字
                    LayerTable pLayerTable = tran.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                    foreach (ObjectId pObjectId in pLayerTable)
                    {
                        LayerTableRecord pLayerTableRecord = tran.GetObject(pObjectId, OpenMode.ForRead) as LayerTableRecord;
                        layerNames.Add(pLayerTableRecord.Name);
                    }
                    #endregion
                    string layerName = layerNames[0];
                    string typeResult ="文字";
     
                    TypedValue[] pTypedValue = new TypedValue[] { new TypedValue((int)DxfCode.LayerName, layerName) };
                    SelectionFilter pSelectFilter = new SelectionFilter(pTypedValue);
                    PromptSelectionResult pSelectionResult = ed.Editor.SelectAll(pSelectFilter);
                    SelectionSet pSelectionSet = pSelectionResult.Value;
                    Point3d startPoint = new Point3d();
                    Point3d endPoint = new Point3d();
                    if (typeResult != "全部")
                    {
                        PromptPointOptions txtPoint = new PromptPointOptions("
     选择两个点作为文字取值范围");
                        txtPoint.Message = "
     选择第一个点:";
                        PromptPointResult txtStartPoint = ed.Editor.GetPoint(txtPoint);
                        startPoint = txtStartPoint.Value;
                        txtPoint.Message = "
     选择第二个点:";
                        PromptPointResult txtEndPoint = ed.Editor.GetPoint(txtPoint);
                        endPoint = txtEndPoint.Value;
                    }
                    foreach (ObjectId selectedId in pSelectionSet.GetObjectIds())
                    {
                        Entity pEntity = tran.GetObject(selectedId, OpenMode.ForRead) as Entity;
                        switch (typeResult)
                        {
                            case "文字":
                                if ((pEntity as MText) != null)
                                {
                                    MText mText = pEntity as MText;
                                    if (mText.Location.X > startPoint.X && mText.Location.Y < startPoint.Y && mText.Location.X < endPoint.X && mText.Location.Y > endPoint.Y)
                                    {
                                        Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog((pEntity as MText).Text);
                                    }
                                }
                                break;
                        }
                    }
                    tran.Commit();
                }
            }
    #endregion


     

    作者:Joe.Fan
             
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    According to TLD or attribute directive in tag file, attribute end does not accept any expressions
    Several ports (8080, 8009) required by Tomcat v6.0 Server at localhost are already in use.
    sql注入漏洞
    Servlet—简单的管理系统
    ServletContext与网站计数器
    VS2010+ICE3.5运行官方demo报错----std::bad_alloc
    java 使用相对路径读取文件
    shell编程 if 注意事项
    Ubuntu12.04下eclipse提示框黑色背景色的修改方法
    解决Ubuntu环境变量错误导致无法正常登录
  • 原文地址:https://www.cnblogs.com/fanxingthink/p/4176164.html
Copyright © 2011-2022 走看看