• autocad.net 利用linq获取矩形框内的块参照


    利用linq获取在两点确定的矩形内的块参照 

    Query syntax:

    private ObjectId[] FindBlockReferencesInRectangle(Point3d pt1, Point3d pt2, Database db)
            {
                using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
                using (Line line = new Line(pt1, pt2))
                {
                    Extents3d bound = line.GeometricExtents;
    
                    BlockTableRecord modelSpace = (BlockTableRecord)tr.GetObject(
                      SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
    
                    Func<ObjectId, bool> isBlockReference = (id =>
                        id.ObjectClass == RXClass.GetClass(typeof(BlockReference)));
    
                    Func<ObjectId, bool> isInside = (id =>
                    {
                        BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                        Extents3d exts = new Extents3d(bound.MinPoint, bound.MaxPoint);
                        exts.AddExtents(br.GeometricExtents);
                        return bound.IsEqualTo(exts);
                    }); ;
    
                    var blocks =
                        from ObjectId id in modelSpace
                        where isBlockReference(id) && isInside(id)
                        select id;
    
                    return blocks.ToArray();
                }
            }
    View Code

    Extension methods syntax:

            private ObjectId[] FindBlockReferencesInRectangle(Point3d pt1, Point3d pt2, Database db)
            {
                using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
                using (Line line = new Line(pt1, pt2))
                {
                    Extents3d bound = line.GeometricExtents;
    
                    BlockTableRecord modelSpace = (BlockTableRecord)tr.GetObject(
                        SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
    
                    Func<ObjectId, bool> isBlockReference = (id =>
                        id.ObjectClass == RXClass.GetClass(typeof(BlockReference)));
    
                    Func<ObjectId, bool> isInside = (id =>
                    {
                        BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                        Extents3d exts = new Extents3d(bound.MinPoint, bound.MaxPoint);
                        exts.AddExtents(br.GeometricExtents);
                        return bound.IsEqualTo(exts);
                    });
    
                    return modelSpace
                        .Cast<ObjectId>()
                        .Where(isBlockReference)
                        .Where(isInside)
                        .ToArray();
                }
            }
    View Code
  • 相关阅读:
    Educational Codeforces Round 51 (Rated for Div. 2)
    Kruskal重构树入门
    编译原理词法分析
    java.lang.String内部结构的变化
    android 世界各国英文简写代码 资源文件
    openCV python 安装
    解读30个提高Web程序执行效率的好经验
    从认知盈余说起,也谈分享精神
    STL set multiset map multimap unordered_set unordered_map example
    [置顶] 【Git入门之一】Git是神马?
  • 原文地址:https://www.cnblogs.com/swtool/p/SWTOOL_00007.html
Copyright © 2020-2023  润新知