/// <summary> /// Create a column. /// </summary> /// <param name="curve">The curve which defines the center line of the column.</param> /// <param name="level">The level with which you'd like the column to be associated.</param> /// <param name="structuralColumnType">The structural column type representing the column.</param> /// <returns></returns> public static StructuralFraming ColumnByCurve( Autodesk.DesignScript.Geometry.Curve curve, Revit.Elements.Level level, Revit.Elements.FamilySymbol structuralColumnType) { if (curve == null) { throw new System.ArgumentNullException("curve"); } if (level == null) { throw new System.ArgumentNullException("level"); } if (structuralColumnType == null) { throw new System.ArgumentNullException("structuralColumnType"); } var start = curve.PointAtParameter(0); var end = curve.PointAtParameter(1); // Revit will throw an exception if you attempt to create a column whose // base is above its top. if (end.Z <= start.Z) { throw new Exception("The end of the curve for creating a column should be above the start of the curve."); } return new StructuralFraming(curve.ToRevitType(), level.InternalLevel, Autodesk.Revit.DB.Structure.StructuralType.Column, structuralColumnType.InternalFamilySymbol); }
/// <summary> /// Convert a generic Circle to a Revit Curve /// </summary> /// <param name="crvCurve"></param> /// <returns></returns> private static Autodesk.Revit.DB.Curve Convert(Autodesk.DesignScript.Geometry.Curve crvCurve) { Autodesk.DesignScript.Geometry.Curve[] curves = crvCurve.ApproximateWithArcAndLineSegments(); if (curves.Length == 1) { //line or arc? var point0 = crvCurve.PointAtParameter(0.0); var point1 = crvCurve.PointAtParameter(1.0); var pointMid = crvCurve.PointAtParameter(0.5); if (point0.DistanceTo(point1) > 1e-7) { var line = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(point0, point1); if (pointMid.DistanceTo(line) < 1e-7) return Convert(line); } //then arc if (point0.DistanceTo(point1) < 1e-7) point1 = crvCurve.PointAtParameter(0.9); var arc = Autodesk.DesignScript.Geometry.Arc.ByThreePoints(point0, pointMid, point1); return Convert(arc); } return Convert(crvCurve.ToNurbsCurve()); }
/// <summary> /// Convert a DS Arc to a Revit arc /// </summary> /// <param name="arc"></param> /// <returns></returns> private static Autodesk.Revit.DB.Arc Convert(Autodesk.DesignScript.Geometry.Arc arc) { // convert var center = arc.CenterPoint.ToXyz(); var sp = arc.StartPoint.ToXyz(); // get the xaxis of the arc base plane var x = (sp - center).Normalize(); // get a second vector in the plane var vecY = (arc.PointAtParameter(0.1).ToXyz() - center); // get the normal to the plane var n2 = x.CrossProduct(vecY).Normalize(); // obtain the y axis in the plane - perp to x and z var y = n2.CrossProduct(x); var plane = new Autodesk.Revit.DB.Plane(x, y, center); return Autodesk.Revit.DB.Arc.Create(plane, arc.Radius, 0, arc.SweepAngle.ToRadians()); }
private static Autodesk.Revit.DB.Arc Convert(Autodesk.DesignScript.Geometry.Circle circ) { // convert var center = circ.CenterPoint.ToXyz(false); var sp = circ.StartPoint.ToXyz(false); // get the xaxis of the arc base plane normalized var x = (sp - center).Normalize(); // get a second vector in the plane var vecY = (circ.PointAtParameter(0.1).ToXyz(false) - center); // get the normal to the plane var n2 = x.CrossProduct(vecY).Normalize(); // obtain the y axis in the plane - perp to x and z var y = n2.CrossProduct(x); var plane = new Autodesk.Revit.DB.Plane(x, y, center); return Autodesk.Revit.DB.Arc.Create(plane, circ.Radius, 0, 2 * System.Math.PI); }