public static Autodesk.Revit.DB.BoundingBoxXYZ ToRevitBoundingBox(
            Autodesk.DesignScript.Geometry.CoordinateSystem cs,
            Autodesk.DesignScript.Geometry.Point minPoint,
            Autodesk.DesignScript.Geometry.Point maxPoint, bool convertUnits = true)
        {
            var rbb = new BoundingBoxXYZ();
            rbb.Enabled = true;

            rbb.Transform = cs.ToTransform(convertUnits);

            rbb.Max = maxPoint.ToXyz(convertUnits);
            rbb.Min = minPoint.ToXyz(convertUnits);

            return rbb;
        }
Exemple #2
0
        /// <summary>
        /// Create a Revit Grid Element in a project between two end points
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static Grid ByStartPointEndPoint(Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end)
        {
            if (Document.IsFamilyDocument)
            {
                throw new Exception("A Grid Element can only be created in a Revit Project");
            }

            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            if (end == null)
            {
                throw new ArgumentNullException("end");
            }

            var line = Autodesk.Revit.DB.Line.CreateBound(start.ToXyz(), end.ToXyz());

            return new Grid(line);
        }
Exemple #3
0
        /// <summary>
        /// Create a Revit Structural Member - a special FamilyInstance
        /// </summary>
        /// <param name="curve">The curve path for the structural member</param>
        /// <param name="upVector">The up vector for the element - this is required to determine the orientation of the element</param>
        /// <param name="level">The level on which the member should appear</param>
        /// <param name="structuralType">The type of the structural element - a beam, column, etc</param>
        /// <param name="structuralFramingType">The structural framing type representing the structural type</param>
        /// <returns></returns>
        public static StructuralFraming ByCurveLevelUpVectorAndType(Autodesk.DesignScript.Geometry.Curve curve, Level level, 
            Autodesk.DesignScript.Geometry.Vector upVector, StructuralType structuralType, FamilySymbol structuralFramingType)
        {
            if (curve == null)
            {
                throw new System.ArgumentNullException("curve");
            }

            if (level == null)
            {
                throw new System.ArgumentNullException("level");
            }

            if (upVector == null)
            {
                throw new System.ArgumentNullException("upVector");
            }

            if (structuralFramingType == null)
            {
                throw new System.ArgumentNullException("structuralFramingType");
            }            

            return new StructuralFraming(curve.ToRevitType(), upVector.ToXyz(), level.InternalLevel,
                structuralType.ToRevitType(), structuralFramingType.InternalFamilySymbol);
        }
Exemple #4
0
        /// <summary>
        /// Create a Revit Perspective View from an Eye position and target position and Bounding Box
        /// </summary>
        /// <param name="eyePoint">Eye point in meters</param>
        /// <param name="target">Target of view in meters</param>
        /// <param name="boundingBox">Bounding box represented in meters</param>
        /// <param name="name"></param>
        /// <param name="isolateElement"></param>
        /// <returns></returns>
        public static PerspectiveView ByEyePointTargetAndBoundingBox(Autodesk.DesignScript.Geometry.Point eyePoint, Autodesk.DesignScript.Geometry.Point target, Autodesk.DesignScript.Geometry.BoundingBox boundingBox, string name, bool isolateElement)
        {
            if (boundingBox == null)
            {
                throw new ArgumentNullException("boundingBox");
            }

            if (eyePoint == null)
            {
                throw new ArgumentNullException("eyePoint");
            }

            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return new PerspectiveView(eyePoint.ToXyz(), target.ToXyz(), boundingBox.ToRevitType(), name, isolateElement);
        }
Exemple #5
0
        /// <summary>
        /// Create a Revit Perspective View from an Eye position and target position and Element
        /// </summary>
        /// <param name="eyePoint"></param>
        /// <param name="target"></param>
        /// <param name="element"></param>
        /// <param name="name"></param>
        /// <param name="isolateElement"></param>
        /// <returns></returns>
        public static PerspectiveView ByEyePointTargetAndElement(Autodesk.DesignScript.Geometry.Point eyePoint, Autodesk.DesignScript.Geometry.Point target, Element element, string name, bool isolateElement)
        {
            if (eyePoint == null)
            {
                throw new ArgumentNullException("eyePoint");
            }

            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return new PerspectiveView(eyePoint.ToXyz(), target.ToXyz(), element.InternalElement, name, isolateElement);
        }
        /// <summary>
        /// Create a Reference Point Element offset from a point along a vector
        /// </summary>
        /// <param name="basePoint"></param>
        /// <param name="direction"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static ReferencePoint ByPointVectorDistance(Autodesk.DesignScript.Geometry.Point basePoint, Autodesk.DesignScript.Geometry.Vector direction, double distance)
        {
            if (!Document.IsFamilyDocument)
            {
                throw new Exception("ReferencePoint Elements can only be created in a Family Document");
            }

            if (basePoint == null)
            {
                throw new ArgumentNullException("basePoint");
            }

            if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }

            var pt = basePoint.ToXyz() + direction.ToXyz() * distance;

            return new ReferencePoint(pt.X, pt.Y, pt.Z);
        }
Exemple #7
0
 public Dictionary<string, object> Project(Autodesk.DesignScript.Geometry.Point point)
 {
     try
     {
         var result = InternalFace.Project(point.ToXyz());
         return new Dictionary<string, object>()
         {
             {"point", result.XYZPoint.ToPoint()},
             {"uv", result.UVPoint.ToProtoType()},
             {"dist", result.Distance},
             {"edge", result.EdgeObject.Wrap()},
             {"edgeParm", result.EdgeParameter }
         };
     }
     catch
     {
         return null;
     }
 }
Exemple #8
0
        /// <summary>
        /// Create a sphere of a given radius at a given center point. 
        /// </summary>
        /// <param name="center"></param>
        /// <param name="radius"></param>
        /// <returns></returns>
        public static Solid Sphere(Autodesk.DesignScript.Geometry.Point center, double radius)
        {
            if (center == null)
            {
                throw new ArgumentException("Center point is null.");
            }

            if (radius <= 0)
            {
                throw new ArgumentException("Radius must be greater than zero.");
            }

            var origin = center.ToXyz();

            // create semicircular arc
            var semicircle = Autodesk.Revit.DB.Arc.Create(origin, radius, 0, RevitPI, XYZ.BasisZ, XYZ.BasisX);

            // create axis curve of sphere - running from north to south pole
            var axisCurve = Autodesk.Revit.DB.Line.CreateBound(new XYZ(origin.X, origin.Y, origin.Z-radius),
                new XYZ(origin.X, origin.Y, origin.Z + radius));

            var circleLoop = Autodesk.Revit.DB.CurveLoop.Create(new List<Curve>() { semicircle, axisCurve });

            var trans = Transform.Identity;
            trans.Origin = origin;
            trans.BasisX = XYZ.BasisX;
            trans.BasisY = XYZ.BasisY;
            trans.BasisZ = XYZ.BasisZ;

            return new Solid(circleLoop, trans, 0, 2*RevitPI);
        }
Exemple #9
0
        /// <summary>
        /// Create cylinder geometry by extruding a circle of a given radius, by a given height
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="radius"></param>
        /// <param name="direction"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static Solid Cylinder(Autodesk.DesignScript.Geometry.Point origin, double radius, Vector direction, double height)
        {
            if (radius <= 0)
            {
                throw new ArgumentException("Radius must be greater than zero.");
            }

            if (direction == null)
            {
                throw new ArgumentException("Direction can not be null.");
            }

            if (height <= 0)
            {
                throw new ArgumentException("Height must be greater than zero.");
            }

            var axis = direction.ToXyz();

            // get axis that is perp to axis by first generating random vector
            var zaxis = axis.Normalize();
            var randXyz = new XYZ(1, 0, 0);
            if (axis.IsAlmostEqualTo(randXyz)) randXyz = new XYZ(0, 1, 0);
            var yaxis = zaxis.CrossProduct(randXyz).Normalize();

            // get second axis that is perp to axis
            var xaxis = yaxis.CrossProduct(zaxis);

            // create circle (this is ridiculous, but curve loop doesn't work with a circle - you need two arcs)
            var arc1 = Autodesk.Revit.DB.Ellipse.Create(origin.ToXyz(), radius, radius, xaxis, yaxis, 0, RevitPI);
            var arc2 = Autodesk.Revit.DB.Ellipse.Create(origin.ToXyz(), radius, radius, xaxis, yaxis, RevitPI, 2 * RevitPI);

            // create curve loop from cirle
            var circleLoop = Autodesk.Revit.DB.CurveLoop.Create(new List<Curve>() { arc1, arc2 });

            return new Solid(new List<CurveLoop>{circleLoop}, axis, height);
        }