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
  • 相关阅读:
    Mysql复制表格
    MySql的导入与导出
    jQuery语法
    JavaScript中的test()方法
    Android解决java.lang.OutOfMemoryError: bitmap size exceeds VM budget(转)
    Android图片压缩方法总结
    Android实现app长时间未操作时自动退出app
    银行卡号的检测
    Android大图片裁剪终极解决方案(上:原理分析)
    Windows环境下Android Studio v1.0安装教程
  • 原文地址:https://www.cnblogs.com/swtool/p/SWTOOL_00007.html
Copyright © 2011-2022 走看看