using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.BoundaryRepresentation;
using AcBr = Autodesk.AutoCAD.BoundaryRepresentation;
#pragma warning disable 0618
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(Rivilis.RegionExtBoundary))]
namespace Rivilis
{
public class RegionExtBoundary
{
[CommandMethod("REB", CommandFlags.Modal)]
public void MyCommand()
{
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(Region), false);
PromptEntityResult rsEnt = ed.GetEntity(prEnt);
if (rsEnt.Status != PromptStatus.OK) return;
using (Region reg = rsEnt.ObjectId.Open(OpenMode.ForRead) as Region)
{
AcBr.Brep brep = new AcBr.Brep(reg);
int iFaces = 0;
foreach (AcBr.Face face in brep.Faces)
{
iFaces++;
int iLoop = 0;
foreach (AcBr.BoundaryLoop loop in face.Loops)
{
Point3dCollection pts = new Point3dCollection();
ed.WriteMessage("\nКонтур №{0} Тип контура = {1}", iLoop,
(loop.LoopType == LoopType.LoopExterior) ? "Внешний" : "Внутренний");
int iVertex = 0;
foreach (AcBr.Vertex vert in loop.Vertices)
{
ed.WriteMessage("\n\tВершина №{0} CoorLoopType = {1}", iVertex, vert.Point);
if (loop.LoopType == LoopType.LoopExterior) {
pts.Add(vert.Point);
}
iVertex++;
}
using (BlockTableRecord btr = curSpaceId.Open(OpenMode.ForWrite) as BlockTableRecord)
{
using (Polyline3d p3d = new Polyline3d(Poly3dType.SimplePoly, pts, true))
{
btr.AppendEntity(p3d);
}
}
iLoop++;
}
}
}
}
}
}