revit二次開發 內建模型之放樣
阿新 • • 發佈:2018-11-19
/// <summary> /// 內建模型(放樣) /// </summary> private static void CreateSphereDirectShape(double MaxHeight, double MinHeight, double Width, CurveLoop cl) { var doc = RvtExternalData.Current.Doc; var cv = cl.GetByIndexT<Curve>(0); if (cv == null) return; XYZ vec; if (cv is Arc) { Arc ac = cv as Arc; vec = ac.StartPoint().Subtract(ac.Center).Normalize(); } else { vec = cv.UnitVector().VectorRotate(-Math.PI / 2); } //建立放樣時用到得引數pathAttachmentParam double param = cv.GetEndParameter(0); //輪廓線 CurveArray curveArray = new CurveArray(); XYZ xYZ = cv.StartPoint(); XYZ xYZ2 = xYZ.OffsetPoint(vec, Width); XYZ xYZ3 = xYZ2.OffsetPoint(XYZ.BasisZ, MaxHeight); XYZ xYZ4 = xYZ.OffsetPoint(XYZ.BasisZ, MinHeight); curveArray.Append(Line.CreateBound(xYZ, xYZ2)); curveArray.Append(Line.CreateBound(xYZ2, xYZ3)); curveArray.Append(Line.CreateBound(xYZ3, xYZ4)); curveArray.Append(Line.CreateBound(xYZ4, xYZ)); List<CurveLoop> profileloops = new List<CurveLoop>(); profileloops.Add(curveArray.ToCurveLoop()); Transaction tran = wrapper.NewTransaction; tran.Start(); try { Solid solid = GeometryCreationUtilities.CreateSweptGeometry(cl, 0, param, profileloops/*, option*/); DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); if (ds != null) { ds.AppendShape(new List<GeometryObject>() { solid }); } tran.Commit(); } catch (Autodesk.Revit.Exceptions.ArgumentException ex) { string msg = ex.Message; tran.RollBack(); } catch (Exception ex) { string msg = ex.Message; tran.RollBack(); } }