/// <summary> /// Creates a new CurtainSystem with transaction. /// </summary> /// <param name="doc"></param> /// <param name="app"></param> /// <param name="profile"></param> /// <param name="curtainParm"></param> /// <param name="normal"></param> /// <returns></returns> public static CurtainSystem CreateCurtainSystem(this Document doc, App app, CurveArrArray profile, CurtainParm curtainParm, XYZ normal) { if (doc is null) { throw new ArgumentNullException(nameof(doc)); } if (app is null) { throw new NullReferenceException(nameof(app)); } if (profile is null) { throw new NullReferenceException(nameof(profile)); } if (normal is null) { throw new NullReferenceException(nameof(normal)); } var plane = normal.CreatePlane(XYZ.Zero); var symbolParm = new SymbolParm(curtainParm.TemplateFileName, profile, plane, 1.0); var symbol = doc.CreateExtrusionSymbol(app, symbolParm); var location = profile.ToCurveList().GetDistinctPointList().GetMinPoint(); var instParm = new InstParm(location, symbol, curtainParm.Room.Level, NonStructural); return(doc.CreateCurtainSystem(curtainParm, instParm, normal)); }
/// <summary> /// Draws a new ModelCurve. /// </summary> /// <param name="doc"></param> /// <param name="curve"></param> /// <param name="eps"></param> /// <returns></returns> public static ElementId Draw(this Curve curve, Document doc, double eps = 1e-6) { if (doc is null) { return(null); } if (curve is null) { return(null); } XYZ normal = null; XYZ endPt = null; if (curve is Arc arc) { normal = arc.Normal; endPt = arc.Center; } else if (curve is Ellipse ellipse) { normal = ellipse.Normal; endPt = ellipse.Center; } else if (curve is Line line) { var refAsix = XYZ.BasisZ; if (Math.Abs(line.Direction.AngleTo(XYZ.BasisZ)) < eps) { refAsix = XYZ.BasisX; } else if (Math.Abs(line.Direction.AngleTo(-XYZ.BasisZ)) < eps) { refAsix = XYZ.BasisX; } normal = line.Direction.CrossProduct(refAsix).Normalize(); endPt = line.Origin; } if (normal == null) { throw new NullReferenceException(nameof(normal)); } var plane = normal.CreatePlane(endPt); var sketchPlane = SketchPlane.Create(doc, plane); return(doc.NewModelCurve(curve, sketchPlane).Id); }
/// <summary> /// Creates a new sketch plane. /// </summary> /// <param name="doc"></param> /// <param name="pt"></param> /// <returns></returns> public static SketchPlane CreateSketchPlane(this Document doc, XYZ pt) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } if (pt == null) { throw new ArgumentNullException(nameof(pt)); } return(SketchPlane.Create(doc, pt.CreatePlane())); }
/// <summary> /// Creates a new CurtainSystem. /// </summary> /// <param name="doc"></param> /// <param name="profile"></param> /// <param name="lvl"></param> /// <param name="normal"></param> /// <param name="typeName"></param> /// <returns></returns> public static CurtainSystem CreateCurtainSystem(this Document doc, CurveArrArray profile, Level lvl, XYZ normal, string typeName = null) { if (normal is null) { throw new NullReferenceException(nameof(normal)); } var pts = profile.ToCurveList().Select(s => s.GetEndPoint(0)); pts = pts.OrderBy(o => o.Z).ThenBy(o => o.Y).ThenBy(o => o.X); var fdoc = doc.CreateExtrusion(profile, normal.CreatePlane(XYZ.Zero), 100); var symbol = doc.NewLoadFamily(fdoc); var location = pts.FirstOrDefault(); var instance = doc.Create.NewFamilyInstance(location, symbol, lvl, NonStructural); doc.Regenerate(); // The instance has thickness. var faces = instance.GetFaceList(6, -normal).ToFaceArray(); var result = doc.CreateCurtainSystem(faces, typeName); doc.Delete(instance.Id); doc.Delete(symbol.Family.Id); var pnlTypeId = result.CurtainSystemType.get_Parameter(AUTO_PANEL).AsElementId(); if (!(doc.GetElement(pnlTypeId) is PanelType pnlType)) { return(result); } var thickness = pnlType.get_Parameter(CURTAIN_WALL_SYSPANEL_THICKNESS).AsDouble(); ElementTransformUtils.MoveElement(doc, result.Id, normal * thickness / 2); return(result); }