public static void FindLinePairs()
{
Root z = GetIsometryFromJson(@"G:\DevProjects\Iso3DRepo\a62488f5-29fe-4525-b6e2-eb8ac404e237.json");
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PolylineBlockAligner.ImportAndInsertBlocksFromDwg();
if (z.Pipes.Count > 0)
{
List<List<ObjectId>> vpList = new List<List<ObjectId>>();
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
int color = 10;
foreach (Pipe pipe in z.Pipes)
{
foreach (Branch branch in pipe.Branches)
{
List<ObjectId> ids = new List<ObjectId>();
Point3dCollection points = new Point3dCollection();
foreach (BranchObject item in branch.BranchObjects)
{
ObjectId layer = Debugger.CreateLayer(branch.Name.Replace('/', '-') + " " + item.ElementType + " --- " + item.Name.Replace('/', '-').Replace('=', ' '));
Point3d arrive = new Point3d(item.ArriveXPosition, item.ArriveYPosition, item.ArriveZPosition);
Point3d leave = new Point3d(item.LeaveXPosition, item.LeaveYPosition, item.LeaveZPosition);
Point3d pointA = new Point3d(item.ElementXPosition, item.ElementYPosition, item.ElementZPosition);
points.Add(arrive);
points.Add(pointA);
points.Add(leave);
using (MText mtext = new MText())
{
mtext.TextHeight = 5;
mtext.Attachment = AttachmentPoint.MiddleLeft;
mtext.Contents = item.ToString();
// mtext.Contents = item.ElementType;
mtext.ColorIndex = color;
mtext.Location = pointA;
mtext.Normal = new Vector3d(-0.5774, -0.5774, 0.5774);
mtext.Direction = new Vector3d(0.7071, -0.7071, 0);
btr.AppendEntity(mtext);
trans.AddNewlyCreatedDBObject(mtext, true);
mtext.LayerId = layer;
}
Polyline3d polyline3D;
if (item.ElementType.Contains("BEND"))
{
polyline3D = new Polyline3d(Poly3dType.QuadSplinePoly, points, false);
}
else if (item.ElementType.Contains("ELBOW"))
{
polyline3D = new Polyline3d(Poly3dType.CubicSplinePoly, points, false);
}
else
{
polyline3D = new Polyline3d(Poly3dType.SimplePoly, points, false);
}
polyline3D.LineWeight = LineWeight.LineWeight080;
polyline3D.ColorIndex = color;
polyline3D.LayerId = layer;
btr.AppendEntity(polyline3D);
trans.AddNewlyCreatedDBObject(polyline3D, true);
XDataUtilities.AddJsonXDataToObject(polyline3D.ObjectId, item);
ids.Add(polyline3D.ObjectId);
points.Clear();
if (item.ElementType.Contains("VALVE"))
{
BlockUtilities.InsertAndAlignValveBlock(pointA, polyline3D.ObjectId);
}
if (item.ElementType.Contains("FLANGE"))
{
BlockUtilities.InsertAndAlignFlangeBlock(pointA, polyline3D.ObjectId);
}
}
// Создаем 3D полилинию
color += 5;
vpList.Add(ids);
//ids.Clear();
}
}
trans.Commit();
}
}
else
{
ed.WriteMessage("\nПары линий с общей точкой не найдены.");
}
ViewSetter viewSetter = new ViewSetter();
viewSetter.SetSouthWestIsometricViewInModelSpace();
ed.Regen();
}