明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3325|回复: 1

[图元] 扩展函数之图元操作

[复制链接]
发表于 2010-11-2 10:31 | 显示全部楼层 |阅读模式
VS2008提供的扩展方法可以让我们简单的给Autodesk补漏(汗)
下面是些简单的例子,注释有时间再加哈
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.Geometry;
  5. namespace TlsCad.ExtendMethods
  6. {
  7.     public static class EntityEx
  8.     {
  9.         public static IEnumerable<Vertex> GetVertexs<T>(this T ent, Transaction tr) where T : Entity, IEnumerable
  10.         {
  11.             
  12.             foreach (ObjectId id in ent)
  13.             {
  14.                 yield return (Vertex)tr.GetObject(id, OpenMode.ForRead);
  15.             }
  16.         }
  17.         public static IEnumerable<Vertex> GetVertexs<T>(this T ent, Transaction tr, OpenMode mode) where T : Entity, IEnumerable
  18.         {
  19.             foreach (ObjectId id in ent)
  20.             {
  21.                 yield return (Vertex)tr.GetObject(id, mode);
  22.             }
  23.         }
  24.         public static Extents3d GetExtents(this IEnumerable<Entity> ents)
  25.         {
  26.             Extents3d ext = new Extents3d();
  27.             foreach (Entity ent in ents)
  28.             {
  29.                 ext.AddExtents(ent.GeometricExtents);
  30.             }
  31.             return ext;
  32.         }
  33.         public static void Move(this Entity ent, Point3d from, Point3d to)
  34.         {
  35.             ent.TransformBy(Matrix3d.Displacement(to - from));
  36.         }
  37.         public static void Rotation(this Entity ent, Point3d center, double angle, Vector3d normal)
  38.         {
  39.             ent.TransformBy(Matrix3d.Rotation(angle, normal, center));
  40.         }
  41.         public static void Rotation(this Entity ent, Point3d center, double angle)
  42.         {
  43.             ent.TransformBy(Matrix3d.Rotation(angle, Vector3d.ZAxis.TransformBy(ent.Ecs) , center));
  44.         }
  45.         public static void Mirror(this Entity ent, Point3d pt1, Point3d pt2)
  46.         {
  47.             ent.TransformBy(Matrix3d.Mirroring(new Line3d(pt1, pt2)));
  48.         }
  49.         public static void Mirror(this Entity ent, Plane plane)
  50.         {
  51.             ent.TransformBy(Matrix3d.Mirroring(plane));
  52.         }
  53.         public static void Mirror(this Entity ent, Point3d ptBase)
  54.         {
  55.             ent.TransformBy(Matrix3d.Mirroring(ptBase));
  56.         }
  57.         public static void ValidateMirror(this DBText txt)
  58.         {
  59.             if (!txt.Database.Mirrtext)
  60.             {
  61.                 txt.IsMirroredInX = false;
  62.                 txt.IsMirroredInY = false;
  63.             }
  64.         }
  65.     }
  66. }

发表于 2015-7-28 10:07 | 显示全部楼层
赞..     学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 05:55 , Processed in 0.384422 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表