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
             
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    tps吞吐量映射的问题
    深浅拷贝
    webdriver驱动火狐浏览器报错:Unable to find a matching set of capabilities
    xpath元素定位方法
    linux监控系统性能命令
    测试质量评估
    测试策略模型设计
    需求评审
    安全测试的目的,发现哪些问题
    url组成
  • 原文地址:https://www.cnblogs.com/fanxingthink/p/4176164.html
Copyright © 2011-2022 走看看