[CommandMethod("func_lest_draw")]
public void func_lest_draw()
{
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acDocBase = acDoc.Database;
Editor acDocEd = acDoc.Editor;
PromptSelectionResult sel_res;
PromptSelectionOptions sel_opts = new PromptSelectionOptions();
sel_opts.MessageForAdding = "Выберете линию пола и потолка : ";
sel_res = acDocEd.GetSelection(sel_opts);
ObjectId[] ids_lest = sel_res.Value.GetObjectIds();
PromptSelectionResult sel_res2;
PromptSelectionOptions sel_opts2 = new PromptSelectionOptions();
sel_opts2.MessageForAdding = "выберите линии ступенек : ";
sel_res2 = acDocEd.GetSelection(sel_opts2);
ObjectId[] ids_lest2 = sel_res2.Value.GetObjectIds();
Double razn = new Double();
Point3d ps1 = new Point3d();
Point3d ps2 = new Point3d();
Point3d pe1 = new Point3d();
Point3d pe2 = new Point3d();
using (DocumentLock acDockLock = acDoc.LockDocument())
{
using (Transaction acDocTr = acDoc.TransactionManager.StartTransaction())
{
for (int i = 0; i < 2; i++)
{
DBObject get_object = acDocTr.GetObject(ids_lest[i], OpenMode.ForWrite, true);
Line line_le_h = (Line)get_object;
if (i == 0) {
ps1 = line_le_h.StartPoint;
pe1 = line_le_h.EndPoint;
}
else
{
ps2 = line_le_h.StartPoint;
pe2 = line_le_h.EndPoint;
}
}
acDocTr.Commit();
}
}
int niz = 0;
int pravo = 0;
Point3d start_le = new Point3d();
Point3d end_le = new Point3d();
if (ps1.Y > ps2.Y)
{
niz = 2;
if (ps1.X > ps2.X)
{
pravo = 2;
}
else
{
pravo = 1;
}
}
else
{
niz = 1;
if (ps1.X > ps2.X)
{
pravo = 1;
}
else
{
pravo = 2;
}
}
if (niz == 1)
{
start_le = func_ptk(ps1, pe1, pravo);
if (pravo == 2)
{
end_le = func_ptk(ps2, pe2, 1);
}
else
{
end_le = func_ptk(ps2, pe2, 2);
}
}
if (niz == 2)
{
start_le = func_ptk(ps2, pe2, pravo);
if (pravo == 2)
{
end_le = func_ptk(ps1, pe1, 1);
}
else
{
end_le = func_ptk(ps1, pe1, 2);
}
}
razn = (end_le.Y - start_le.Y)/ids_lest2.Length;
Double[] p3d = new Double[ids_lest2.Length];
for (int i = 0; i < ids_lest2.Length; i++)
{
using (DocumentLock acDockLock = acDoc.LockDocument())
{
using (Transaction acDocTr = acDoc.TransactionManager.StartTransaction())
{
DBObject get_object = acDocTr.GetObject(ids_lest2[i], OpenMode.ForWrite, true);
Line line_le_h = (Line)get_object;
p3d[i] = line_le_h.StartPoint.X;
acDocTr.Commit();
}
}
}
Array.Sort(p3d);
Point3d temp1;
temp1 = new Point3d(start_le.X, start_le.Y, start_le.Z);
Point3d temp2;
bool k = false;
if (pravo == 2)
{
for (int i = 1; i < p3d.Length; i++)
{
if (k == false)
{
temp1 = new Point3d(p3d[0],start_le.Y,start_le.Z);
k = true;
}
using (DocumentLock acDocLock = acDoc.LockDocument())
{
using (Transaction acDocTr = acDocBase.TransactionManager.StartTransaction())
{
BlockTable TrTable = acDocTr.GetObject(acDocBase.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord TrTableRec = acDocTr.GetObject(TrTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
temp2 = new Point3d(temp1.X, temp1.Y + razn, 0);
Line acline = new Line(temp1,temp2);
acline.SetDatabaseDefaults();
TrTableRec.AppendEntity(acline);
acDocTr.AddNewlyCreatedDBObject(acline, true);
temp1 = new Point3d(p3d[i], temp2.Y, 0);
Line acline2 = new Line(temp2, temp1);
acline2.SetDatabaseDefaults();
TrTableRec.AppendEntity(acline2);
acDocTr.AddNewlyCreatedDBObject(acline2, true);
// потдверждаем измениния, сохраняем транзакцию
acDocTr.Commit();
}
}
}
using (DocumentLock acDocLock = acDoc.LockDocument())
{
using (Transaction acDocTr = acDocBase.TransactionManager.StartTransaction())
{
BlockTable TrTable = acDocTr.GetObject(acDocBase.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord TrTableRec = acDocTr.GetObject(TrTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
temp2 = new Point3d(temp1.X, temp1.Y + razn, 0);
Line acline = new Line(temp1, temp2);
acline.SetDatabaseDefaults();
TrTableRec.AppendEntity(acline);
acDocTr.AddNewlyCreatedDBObject(acline, true);
// потдверждаем измениния, сохраняем транзакцию
acDocTr.Commit();
}
}
}
else
{
for (int i = p3d.Length-2; i > -1; i--)
{
if (k == false)
{
temp1 = new Point3d(p3d[p3d.Length - 1], start_le.Y, start_le.Z);
k = true;
}
using (DocumentLock acDocLock = acDoc.LockDocument())
{
using (Transaction acDocTr = acDocBase.TransactionManager.StartTransaction())
{
BlockTable TrTable = acDocTr.GetObject(acDocBase.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord TrTableRec = acDocTr.GetObject(TrTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
temp2 = new Point3d(temp1.X, temp1.Y + razn, 0);
Line acline = new Line(temp1, temp2);
acline.SetDatabaseDefaults();
TrTableRec.AppendEntity(acline);
acDocTr.AddNewlyCreatedDBObject(acline, true);
temp1 = new Point3d(p3d[i], temp2.Y, 0);
Line acline2 = new Line(temp2, temp1);
acline2.SetDatabaseDefaults();
TrTableRec.AppendEntity(acline2);
acDocTr.AddNewlyCreatedDBObject(acline2, true);
// потдверждаем измениния, сохраняем транзакцию
acDocTr.Commit();
}
}
}
using (DocumentLock acDocLock = acDoc.LockDocument())
{
using (Transaction acDocTr = acDocBase.TransactionManager.StartTransaction())
{
BlockTable TrTable = acDocTr.GetObject(acDocBase.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord TrTableRec = acDocTr.GetObject(TrTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
temp2 = new Point3d(temp1.X, temp1.Y + razn, 0);
Line acline = new Line(temp1, temp2);
acline.SetDatabaseDefaults();
TrTableRec.AppendEntity(acline);
acDocTr.AddNewlyCreatedDBObject(acline, true);
// потдверждаем измениния, сохраняем транзакцию
acDocTr.Commit();
}
}
}
}
public Point3d func_ptk(Point3d x1, Point3d x2, int x3)
{
if (x3 == 2)
{
if (x1.X > x2.X)
{
return new Point3d(x1.X, x1.Y, 0);
}
else
{
return new Point3d(x2.X, x2.Y, 0);
}
}
else if (x3 == 1)
{
if (x1.X < x2.X)
{
return new Point3d(x1.X, x1.Y, 0);
}
else
{
return new Point3d(x2.X, x2.Y, 0);
}
}
return new Point3d(0, 0, 0);
}