public void iterateObjects( List <string> b)
{
Database db = HostApplicationServices.WorkingDatabase;
Document acDoc = acad.DocumentManager.MdiActiveDocument;
Editor ed = acDoc.Editor;
using (DocumentLock docLock = acDoc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord ms = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
Polyline3d c1 = new Polyline3d();
Polyline c2 = new Polyline();
List<Polyline> ListOfPolyline = new List<Polyline>();
List<Polyline> ListOfAllPolyline = new List<Polyline>();
PromptSelectionResult selectionRes = ed.SelectImplied();
if (selectionRes.Status == PromptStatus.Error)
{
PromptSelectionOptions selectionOpts = new PromptSelectionOptions();
selectionOpts.SingleOnly = true;
selectionRes = ed.GetSelection(selectionOpts);
ed.WriteMessage(selectionRes.ToString());
}
else
{
ed.SetImpliedSelection(new ObjectId[0]);
}
if (selectionRes.Status == PromptStatus.OK)
{
try
{
objIds = selectionRes.Value.GetObjectIds();
foreach (ObjectId objId in objIds)
{
DBObject targetobj = (DBObject)tr.GetObject(objId, OpenMode.ForWrite);
c1 = targetobj as Polyline3d;
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(ex.Message);
tr.Abort();
}
}
if(c1.Id != ObjectId.Null)
{
// "пробегаем" по всем объектам в пространстве модели
foreach (ObjectId id in ms)
{
Entity entity = (Entity)tr.GetObject(id, OpenMode.ForRead);
foreach (string a in b)
{
if (entity.Layer == a) //ИИ_Горизонтали_М
{
if (entity.GetType() == typeof(Polyline))
{
acad.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayer:{0}; Type:{1}; Color: {2},{3},{4}\n",
entity.Layer, entity.GetType().ToString(), entity.Color.Red.ToString(), entity.Color.Green.ToString(), entity.Color.Blue.ToString()));
c2 = entity as Polyline;
ListOfAllPolyline.Add(c2);
}
}
}
}
Plane planeXoy = new Plane(
Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Origin,
Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis
);
Point3dCollection intersectionPoints = new Point3dCollection();
for (int i = 0; i < ListOfAllPolyline.Count; i++)
{
Point3dCollection points = new Point3dCollection();
c1.IntersectWith(ListOfAllPolyline[i], Intersect.OnBothOperands, planeXoy, points, IntPtr.Zero, IntPtr.Zero);
if (points.Count != 0)
{
ListOfPolyline.Add(ListOfAllPolyline[i]);
foreach (Point3d Point_ in points)
{
var xline = new Xline();
xline.BasePoint = Point_;
xline.UnitDir = Vector3d.ZAxis;
c1.IntersectWith(xline, Intersect.OnBothOperands, planeXoy, intersectionPoints, IntPtr.Zero, IntPtr.Zero);
}
}
}
List<double> intersectionDistances = new List<double>();
foreach (Point3d intersectionPoint in intersectionPoints)
{
try
{
intersectionDistances.Add(c1.GetParameterAtPoint(intersectionPoint));
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
continue;
}
}
intersectionDistances.Insert(0, c1.StartParam);
intersectionDistances.Add(c1.EndParam);
intersectionDistances.Sort();
DBObjectCollection splitCurves = c1.GetSplitCurves(new DoubleCollection(intersectionDistances.ToArray()));
IList<Entity> splitEntities = splitCurves.OfType<Entity>().ToList();
Polyline3d poly = new Polyline3d();
if (splitEntities.Count > 0)
{
using (BlockTable blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead))
{
using (BlockTableRecord blockTableRecord = (BlockTableRecord)tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite))
{
Entity polyline = splitEntities[0];
polyline.SetDatabaseDefaults();
splitEntities.RemoveAt(0);
if (splitEntities.Count > 0)
{
polyline.JoinEntities(splitEntities.ToArray());
}
blockTableRecord.AppendEntity(polyline);
tr.AddNewlyCreatedDBObject(polyline, true);
poly = polyline as Polyline3d;
}
}
}
Entity entity2 = (Entity)tr.GetObject(c1.Id, OpenMode.ForWrite, false, true);
entity2.Erase();
tr.Commit();
}
}
}
}