乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 54|回复: 1

扩展函数之图元操作

[复制链接]

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

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

回复

使用道具 举报

26

主题

281

帖子

8

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
385
发表于 2015-7-28 10:07:00 | 显示全部楼层
赞..     学习
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 10:24 , Processed in 0.843879 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表