zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    POJ 3710 Christmas Game#经典图SG博弈
    POJ 2599 A funny game#树形SG(DFS实现)
    POJ 2425 A Chess Game#树形SG
    LeetCode Array Easy 122. Best Time to Buy and Sell Stock II
    LeetCode Array Easy121. Best Time to Buy and Sell Stock
    LeetCode Array Easy 119. Pascal's Triangle II
    LeetCode Array Easy 118. Pascal's Triangle
    LeetCode Array Easy 88. Merge Sorted Array
    ASP.NET MVC 学习笔记之 MVC + EF中的EO DTO ViewModel
    ASP.NET MVC 学习笔记之面向切面编程与过滤器
  • 原文地址:https://www.cnblogs.com/swtool/p/SWTOOL_00007.html
Copyright © 2011-2022 走看看