// Поиск линии пересечений
[CommandMethod("CrossLine", CommandFlags.UsePickSet)]
public static void CrossLine()
{
// Доступ к чертежу
AccessDoc ad = new AccessDoc();
Database db = ad.DBase;
Editor ae = ad.Ed;
//Список всех треугольников
List<Triangle> triangleList = TriangleList();
// границы зон исследования
FindBorder(out double x1, out double x2, out double y1, out double y2, out double z1, out double z2);
double dx = 0.5;
double dy = 0.5;
//
int n = 0;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Таблица записи текущего пространства
//BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord ms = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
// Перебираем поверхности
for (int i = (int)y1; i <= (int)y2; i++)
{
PromptSelectionResult selectionResult = ae.SelectCrossingWindow(new Point3d(x1 - dx, i - dy, 0), new Point3d(x2 + dx, i + dy, 0));
SelectionSet acSSet = selectionResult.Value;
if (selectionResult.Status == PromptStatus.OK && acSSet.Count > 0)
{
foreach (SelectedObject selobj in acSSet)
{
//MessageBox.Show((selobj.GetType()).ToString(), "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//if (selobj.GetType() == typeof(Autodesk.AutoCAD.DatabaseServices.Face))
{
//MessageBox.Show((1).ToString(), "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Face face = (Face)tr.GetObject(selobj.ObjectId, OpenMode.ForWrite);
Autodesk.AutoCAD.DatabaseServices.Surface surface = new Autodesk.AutoCAD.DatabaseServices.Surface();
surface = Autodesk.AutoCAD.DatabaseServices.Surface.CreateFrom(face);
ms.AppendEntity(surface);
tr.AddNewlyCreatedDBObject(surface, true);
for (int j = (int)x1; j <= (int)x2-1; j++)
{
Line line = new Line(new Point3d(i, j, 0), new Point3d(i+1, j, 0));
//line = new Line(new Point3d(8.7579, 9.2385, 0), new Point3d(17.1127, 9.2385, 0));
ms.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
Entity[] projectedEntities = surface.ProjectOnToSurface(line, Vector3d.ZAxis);
if (projectedEntities != null)
{
n++;
}
}
}
}
}
}
tr.Commit();
}
MessageBox.Show(n.ToString(), "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}