Entity.GetPlane()的注意點
這個方法并不能擷取到所有實體類型的plane,有些是擷取到了平面,但是平面并不是正确的,如Line類型,假如line類型被使用者更改了結點的z軸,這個時候擷取他的平面仍是原先的平面,這個平面是錯誤的。
還有一些3D類型的實體調用GetPlane時會彈出錯誤,如BlockReference、螺旋、Mline。
改善方法:自己封裝GetPlane方法
上一段line類型的GetPlane封裝
public static Plane MyGetPlane(this Line line)
{
Curve3d curve3d = line.GetGeCurve();//擷取到line的Ge對象
Plane retPlane = null;
bool isPlanar = curve3d.IsPlanar(out retPlane);//通過ge對象去擷取平面
return retPlane;
}
但這種方法也不是萬能的,有些類型是沒有GetGeCurve接口的;
下面是我測試時的統計結果:
type | Entity.GetPlane | Ge.IsPlanar |
---|---|---|
Line | × | √ |
Hatch | √ | × |
Solid | × | × |
XLine | √ | × |
Ray | √ | × |
Region | × | × |
MLine | × | × |
Line、XLine、Ray同派生自Curve類型,他們三個是特例,是以我單獨将他們拿出來測試,其餘派生自Curve的類型,基本GetPlane都是可以的。
再來一波兩種方式都不行的類型的封裝:
public static Plane MyGetPlane(this Solid solid)
{
Point3d pot0 = solid.GetPointAt(0);
Point3d pot1 = solid.GetPointAt(1);
Point3d pot2 = solid.GetPointAt(2);
Plane retPlane = new Plane(pot0, pot1, pot2);
return retPlane;
}
public static Plane MyGetPlane(this Region region)
{
DBObjectCollection subObjCol = new DBObjectCollection();
region.Explode(subObjCol);
Entity entity = subObjCol[0] as Entity;
return entity.GetPlane();
}
public static Plane MyGetPlane(this Mline mline)
{
Point3d pot = mline.VertexAt(0);
Vector3d normal = mline.Normal;
return new Plane(pot, normal);
}