//recursive method to check if points are required at the location or not in case of parallel and intersecting trays/ducts private void PlaceOnParallel(List <Element> interParallel, XYZ widthProject, double width, bool first, XYZ above, double aboveHeight) { try { Element highest = DuctsAndTrays.HighestElement(interParallel); XYZ highProject = Intersectors.Projectpoint(widthProject, ((LocationCurve)highest.Location).Curve as Line); double height = DuctsAndTrays.TrayDuctHeight(highest); bool required = true; if (Points.GetCreatedPoints(highest.Id) != null) { List <XYZ> sortedList = Points.SortPoints((((LocationCurve)highest.Location).Curve as Line).GetEndPoint(0), Points.GetCreatedPoints(highest.Id)); required = Points.CheckIfRequired(highProject, sortedList); } if (required) { if (first != true && above != null) { XYZ instancePoint = new XYZ(widthProject.X, widthProject.Y, highProject.Z); CreateAdjustElement(highest, instancePoint, highProject, width, false, above.Z - highProject.Z + height - aboveHeight); } else { XYZ instancePoint = new XYZ(widthProject.X, widthProject.Y, highProject.Z); CreateAdjustElement(highest, instancePoint, highProject, width, true, 0.0); } } else { if (first != true) { highProject = above; height = aboveHeight; } else { highProject = null; } } interParallel.Remove(highest); if (interParallel.Count != 0) { PlaceOnParallel(interParallel, widthProject, width, false, highProject, height); } else { return; } } catch { throw new Exception(); } }
//method to make choice based on availability of parallel trays with no intersection/ parallel with intersecting trays //or no parallel trays private void InterParallel(List <XYZ> placementPoints, Element leastWidth) { try { ICollection <ElementId> parallels = ducttray.ParallelElements(doc, leastWidth); List <Element> interParallel = new List <Element>(); foreach (XYZ point in placementPoints) { if (parallels == null || parallels.Count == 0) { AdjustInstance.height = Intersectors.StructureHeight(point, doc) + DuctsAndTrays.TrayDuctHeight(leastWidth); CreateAdjustElement(leastWidth, point, point, DuctsAndTrays.GetWidth(leastWidth), true, 0.0); continue; } else { interParallel = Intersectors.ParallelElements(point, doc, parallels); Element maxWidth = null, lowest = null; XYZ widthProject = null, lowestProject; if (interParallel.Count != 0) { interParallel.Add(leastWidth); maxWidth = DuctsAndTrays.MaxWidthElement(interParallel); lowest = DuctsAndTrays.LowestElement(interParallel); lowestProject = Intersectors.Projectpoint(point, ((LocationCurve)maxWidth.Location).Curve as Line); AdjustInstance.height = Intersectors.StructureHeight(lowestProject, doc) + DuctsAndTrays.TrayDuctHeight(lowest); widthProject = Intersectors.Projectpoint(point, ((LocationCurve)maxWidth.Location).Curve as Line); PlaceOnParallel(interParallel, widthProject, DuctsAndTrays.GetWidth(maxWidth), true, null, 0.0); } else { AdjustInstance.height = Intersectors.StructureHeight(point, doc) + DuctsAndTrays.TrayDuctHeight(leastWidth); CreateAdjustElement(leastWidth, point, point, DuctsAndTrays.GetWidth(leastWidth), true, 0.0); continue; } } } } catch { throw new Exception(); } }