[CommandMethod("SEB", CommandFlags.Modal)]
public void SebCommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
ObjectId curSpaceId = doc.Database.CurrentSpaceId;
PromptEntityOptions prEnt = new PromptEntityOptions("\nВыберите твердое тело: ");
prEnt.SetRejectMessage("Это не твердое тело");
prEnt.AddAllowedClass(typeof(Solid3d), false);
PromptEntityResult rsEnt = ed.GetEntity(prEnt);
if (rsEnt.Status != PromptStatus.OK) return;
using (Solid3d sol = rsEnt.ObjectId.Open(OpenMode.ForRead) as Solid3d)
{
AcBr.Brep brep = new AcBr.Brep(sol);
int iFaces = 0;
foreach (AcBr.Face face in brep.Faces)
{
ed.WriteMessage("\nГрань №{0}.", iFaces++);
AcGe.Surface ebs = face.Surface;
if (ebs != null && ebs is ExternalBoundedSurface)
{
ExternalBoundedSurface eebs = ebs as ExternalBoundedSurface;
if (eebs.IsPlane)
{
Interval[] iv = ebs.GetEnvelope();
double d1 = iv[0].LowerBound;
double d2 = iv[1].LowerBound;
Point2d ptParams = new Point2d(d1, d2);
PointOnSurface pos = new PointOnSurface(ebs, ptParams);
Vector3d normal = pos.GetNormal(ptParams);
Point3d pt = pos.GetPoint(ptParams);
using (Plane plane = new Plane(pt, normal))
{
ed.WriteMessage(" Точка = {0}, Нормаль={1}", pt, normal);
}
}
else
{
ed.WriteMessage(" Грань не плоская.");
}
}
}
}
}