Beispiel #1
0
        private static FamilyInstanceCreationData GetCreationData(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
        {

            //calculate the desired rotation
            //we do this by finding the angle between the z axis
            //and vector between the start of the beam and the target point
            //both projected onto the start plane of the beam.
            var zAxis = new XYZ(0, 0, 1);
            var yAxis = new XYZ(0, 1, 0);

            //flatten the beam line onto the XZ plane
            //using the start's z coordinate
            var start = curve.GetEndPoint(0);
            var end = curve.GetEndPoint(1);
            var newEnd = new XYZ(end.X, end.Y, start.Z); //drop end point to plane

            //catch the case where the end is directly above
            //the start, creating a normal with zero length
            //in that case, use the Z axis
            XYZ planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize();

            double gamma = upVector.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal);

            return new FamilyInstanceCreationData(curve, symbol, level, structuralType)
            {
                RotateAngle = gamma
            };

        }
Beispiel #2
0
        /// <summary>
        /// Creates a new Sketch Plane from a Curve
        /// </summary>
        /// <param name="document">Active Document</param>
        /// <param name="curve">Curve to get plane from</param>
        /// <returns>Plane of the curve</returns>
        public static SketchPlane NewSketchPlaneFromCurve(Document document, Autodesk.Revit.DB.Curve curve)
        {
            XYZ startPoint = curve.GetEndPoint(0);
            XYZ endPoint = curve.GetEndPoint(1);

            // If Start end Endpoint are the same check further points.
            int i = 2;
            while (startPoint == endPoint && endPoint != null)
            {
                endPoint = curve.GetEndPoint(i);
                i++;
            }

            // Plane to return
            Plane plane;

            // If Z Values are equal the Plane is XY
            if (startPoint.Z == endPoint.Z)
            {
                plane = document.Application.Create.NewPlane(XYZ.BasisZ, startPoint);
            }
            // If X Values are equal the Plane is YZ
            else if (startPoint.X == endPoint.X)
            {
                plane = document.Application.Create.NewPlane(XYZ.BasisX, startPoint);
            }
            // If Y Values are equal the Plane is XZ
            else if (startPoint.Y == endPoint.Y)
            {
                plane = document.Application.Create.NewPlane(XYZ.BasisY, startPoint);
            }
            // Otherwise the Planes Normal Vector is not X,Y or Z.
            // We draw lines from the Origin to each Point and use the Plane this one spans up.
            else
            {
                CurveArray curves = new CurveArray();
                curves.Append(curve);
                curves.Append(Autodesk.Revit.DB.Line.CreateBound(new XYZ(0, 0, 0), startPoint));
                curves.Append(Autodesk.Revit.DB.Line.CreateBound(endPoint, new XYZ(0, 0, 0)));
                plane = document.Application.Create.NewPlane(curves);
            }

            // return new Sketchplane
            return SketchPlane.Create(document, plane);
        }
 /// <summary>
 /// Create a new curve with the same 
 /// geometry in the reverse direction.
 /// rom Jeremy Tammik
 /// </summary>
 /// <param name="orig">The original curve.</param>
 /// <returns>The reversed curve.</returns>
 /// <throws cref="NotImplementedException">If the 
 /// curve type is not supported by this utility.</throws>
 static Autodesk.Revit.DB.Curve CreateReversedCurve(Autodesk.Revit.DB.Curve orig)
 {
     if (orig is Autodesk.Revit.DB.Line)
     {
         return Autodesk.Revit.DB.Line.CreateBound(
           orig.GetEndPoint(1),
           orig.GetEndPoint(0));
     }
     else if (orig is Autodesk.Revit.DB.Arc)
     {
         return Autodesk.Revit.DB.Arc.Create(orig.GetEndPoint(1),
           orig.GetEndPoint(0),
           orig.Evaluate(0.5, true));
     }
     else
     {
         throw new Exception(
           "CreateReversedCurve - Unreachable");
     }
 }
Beispiel #4
0
 private static Autodesk.DesignScript.Geometry.Line Convert(Autodesk.Revit.DB.Line crv)
 {
     return Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(
          crv.GetEndPoint(0).ToPoint(), crv.GetEndPoint(1).ToPoint());
 }
Beispiel #5
0
        private static Autodesk.DesignScript.Geometry.Helix Convert(Autodesk.Revit.DB.CylindricalHelix crv)
        {
            if (crv.IsRightHanded)
            {
                // a negative pitch and axis vector produces helix in opposite direction
                return Autodesk.DesignScript.Geometry.Helix.ByAxis(crv.BasePoint.ToPoint(), (-1.0 * crv.ZVector).ToVector(),
                    crv.GetEndPoint(0).ToPoint(), -crv.Pitch, (crv.Height / crv.Pitch) * 360.0);
            }

            // clockwise is default
            return Autodesk.DesignScript.Geometry.Helix.ByAxis(crv.BasePoint.ToPoint(), crv.ZVector.ToVector(),
                crv.GetEndPoint(0).ToPoint(), crv.Pitch, (crv.Height/crv.Pitch)*360.0);
        }
Beispiel #6
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Arc crv)
        {
            var isCircle = !crv.IsBound ||
                           Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2*Math.PI) < 1e-6;

            if ( isCircle )
            {
                return Circle.ByCenterPointRadiusNormal(crv.Center.ToPoint(), crv.Radius, crv.Normal.ToVector());
            }

            return Arc.ByCenterPointStartPointSweepAngle(crv.Center.ToPoint(), crv.GetEndPoint(0).ToPoint(),
                (crv.GetEndParameter(1) - crv.GetEndParameter(0))*180/Math.PI, crv.Normal.ToVector());
        }