- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
using System.Linq;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace TableSample
{
static class Extensions
{
// Retourne l'objet MText contenu dans la cellule (ou null s'il nexiste pas).
// Returns the MText object contained in the cell (or null if it don't exist).
public static MText GetMtext(this Cell cell)
{
Table table = cell.ParentTable;
Extents3d extents = cell.GetExtents().ToExtents3d();
extents.TransformBy(table.BlockTransform.Inverse());
BlockTableRecord btr = (BlockTableRecord)table.BlockTableRecord.GetObject(OpenMode.ForRead);
RXClass mtextClass = RXClass.GetClass(typeof(MText));
foreach (ObjectId id in btr)
{
if (id.ObjectClass == mtextClass)
{
MText mtext = (MText)id.GetObject(OpenMode.ForRead);
if (mtext.Location.IsInside(extents))
return mtext;
}
}
return null;
}
// Evalue si un point est à l'intérieur de la boite (BoundingBox).
// Evaluates if the point is within the extents (BoundingBox).
private static bool IsInside(this Point3d pt, Extents3d extents)
{
return
pt.X >= extents.MinPoint.X &&
pt.Y >= extents.MinPoint.Y &&
pt.Z >= extents.MinPoint.Z &&
pt.X <= extents.MaxPoint.X &&
pt.Y <= extents.MaxPoint.Y &&
pt.Z <= extents.MaxPoint.Z;
}
// Retourne la boite (BoundingBox) définie par la collection de points.
// Returns the extents (BoundingBox) defined by the points collection
private static Extents3d ToExtents3d(this Point3dCollection pts)
{
return pts.Cast<Point3d>()
.Aggregate(new Extents3d(pts[0], pts[0]), (ext, pt) =>
{ ext.AddPoint(pt); return ext; });
}
}
}
|
|