zoukankan      html  css  js  c++  java
  • C# CAD 参照块或者xref 外部参照块范围 画矩形

     

    C#  CAD 参照块范围 画矩形

    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.DatabaseServices.Filters;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.Runtime;
    using Beaver.Core.Cad;
    
    namespace SpatialFiltering
    {
        public class Commands : CadBase
        {
            private const string filterDictName = "ACAD_FILTER";
    
            private const string spatialName = "SPATIAL";
    
            [CommandMethod("DXC")]
            public void DetectXClip()
            {
                var doc = Application.DocumentManager.MdiActiveDocument;
    
                var ed = doc.Editor;
    
                // Ask for an xclipped xref to be selected
    
                var peo =
    
                  new PromptEntityOptions(
    
                    "
    Select xclipped block or xref"
    
                  );
    
                peo.SetRejectMessage("Must be a block or xref.");
    
                peo.AddAllowedClass(typeof(BlockReference), false);
    
                var per = ed.GetEntity(peo);
    
                if (per.Status != PromptStatus.OK)
    
                    return;
                Point3d maxPoint;
                Point3d minPoint;
                var tr = doc.TransactionManager.StartTransaction();
    
                using (tr)
                {
                    // Open the selected BlockReference
                    var br = tr.GetObject(per.ObjectId, OpenMode.ForRead) as BlockReference;
                    // To save multiple codepaths with the same message
                    // ("No clipping information found"), we'll use a flag to
                    // see whether we've found anything
                    bool found = false;
                    // It should always be a block reference, but it might
                    // not have an extension dictionary
    
                    if (
                      br != null && br.ExtensionDictionary != ObjectId.Null)
                    {
                        // The extension dictionary needs to contain a nested
                        // dictionary called ACAD_FILTER
                        var extdict =
                          tr.GetObject(br.ExtensionDictionary, OpenMode.ForRead)
                          as DBDictionary;
    
                        if (extdict != null && extdict.Contains(filterDictName))
                        {
                            var fildict =
                              tr.GetObject(
                                extdict.GetAt(filterDictName), OpenMode.ForRead
                              ) as DBDictionary;
    
                            if (fildict != null)
                            {
                                // The nested dictionary should contain a
    
                                // SpatialFilter object called SPATIAL
    
                                if (fildict.Contains(spatialName))
                                {
                                    var fil =
                                      tr.GetObject(
                                        fildict.GetAt(spatialName), OpenMode.ForRead
                                      ) as SpatialFilter;
    
                                    if (fil != null)
                                    {
                                        // We have a SpatialFilter: print its bounds
                                        var ext = fil.GetQueryBounds();
                                        ed.WriteMessage(
                                          "
    Found clip from {0} to {1}.",
                                          ext.MinPoint, ext.MaxPoint
                                        );
                                        maxPoint = ext.MaxPoint;
                                        minPoint = ext.MinPoint;
                                        var pts = fil.Definition.GetPoints();
                                        foreach (var pt in pts)
                                        {
                                            ed.WriteMessage("
    Boundary point at {0}", pt);
                                        }
    
                                        found = true;
                                    }
                                }
                            }
                        }
                    }
    
                    if (!found)
                    {
                        ed.WriteMessage("
    No clipping information found.");
                    }
                    else
                    {
                       var polyline  =AddEntityEx.Rect(minPoint.ToPoint2d(), maxPoint.ToPoint2d());
                        var objids = Database.AddEntityToModelSpace(new Entity[] { polyline });
                    }
    
                    tr.Commit();
                }
            }
        }
    }
    

      

  • 相关阅读:
    ↗☻【高性能网站建设进阶指南 #BOOK#】第3章 拆分初始化负载
    ↗☻【高性能网站建设进阶指南 #BOOK#】第7章 编写高效的JavaScript
    【JavaScript】text
    ↗☻【高性能网站建设进阶指南 #BOOK#】第5章 整合异步脚本
    ↗☻【高性能网站建设进阶指南 #BOOK#】第10章 图像优化
    利用十大最佳游戏开发工具开发游戏
    传奇服务器端/客户端 完整源代码
    order by union 应用实例 mssql
    Nine Digits Expression
    Ninedigit Fractions
  • 原文地址:https://www.cnblogs.com/shangdishijiao/p/15165231.html
Copyright © 2011-2022 走看看