- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
VS2008提供的扩展方法可以让我们简单的给Autodesk补漏(汗)
下面是些简单的例子,注释有时间再加哈-
- using System.Collections;
- using System.Collections.Generic;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- namespace TlsCad.ExtendMethods
- {
- public static class EntityEx
- {
- public static IEnumerable<Vertex> GetVertexs<T>(this T ent, Transaction tr) where T : Entity, IEnumerable
- {
-
- foreach (ObjectId id in ent)
- {
- yield return (Vertex)tr.GetObject(id, OpenMode.ForRead);
- }
- }
- public static IEnumerable<Vertex> GetVertexs<T>(this T ent, Transaction tr, OpenMode mode) where T : Entity, IEnumerable
- {
- foreach (ObjectId id in ent)
- {
- yield return (Vertex)tr.GetObject(id, mode);
- }
- }
- public static Extents3d GetExtents(this IEnumerable<Entity> ents)
- {
- Extents3d ext = new Extents3d();
- foreach (Entity ent in ents)
- {
- ext.AddExtents(ent.GeometricExtents);
- }
- return ext;
- }
- public static void Move(this Entity ent, Point3d from, Point3d to)
- {
- ent.TransformBy(Matrix3d.Displacement(to - from));
- }
- public static void Rotation(this Entity ent, Point3d center, double angle, Vector3d normal)
- {
- ent.TransformBy(Matrix3d.Rotation(angle, normal, center));
- }
- public static void Rotation(this Entity ent, Point3d center, double angle)
- {
- ent.TransformBy(Matrix3d.Rotation(angle, Vector3d.ZAxis.TransformBy(ent.Ecs) , center));
- }
- public static void Mirror(this Entity ent, Point3d pt1, Point3d pt2)
- {
- ent.TransformBy(Matrix3d.Mirroring(new Line3d(pt1, pt2)));
- }
- public static void Mirror(this Entity ent, Plane plane)
- {
- ent.TransformBy(Matrix3d.Mirroring(plane));
- }
- public static void Mirror(this Entity ent, Point3d ptBase)
- {
- ent.TransformBy(Matrix3d.Mirroring(ptBase));
- }
- public static void ValidateMirror(this DBText txt)
- {
- if (!txt.Database.Mirrtext)
- {
- txt.IsMirroredInX = false;
- txt.IsMirroredInY = false;
- }
- }
-
- }
- }
|
|