private static ElementCurveReference TryGetCurveReference(Revit.Elements.Element curveObject, string nodeTypeString = "This node")
        {
            var cs = curveObject.InternalGeometry().OfType<Autodesk.Revit.DB.Curve>();
            if (cs.Any()) return new ElementCurveReference(cs.First());

            throw new ArgumentException(nodeTypeString + " requires a ElementCurveReference extracted from a Revit Element! " +
                             "You supplied an " + curveObject.ToString() + ", but we could not extract a CurveReference from it!");
        }
        private static ElementFaceReference TryGetFaceReference(Revit.Elements.Element curveObject, string nodeTypeString = "This node")
        {
            var cs = curveObject.InternalGeometry().OfType <Autodesk.Revit.DB.Face>();

            if (cs.Any())
            {
                return(new ElementFaceReference(cs.First()));
            }

            var ss = curveObject.InternalGeometry().OfType <Autodesk.Revit.DB.Solid>();

            if (ss.Any())
            {
                return(new ElementFaceReference(ss.First().Faces.Cast <Autodesk.Revit.DB.Face>().First()));
            }

            throw new ArgumentException(string.Format(Properties.Resources.FaceReferenceExtractionFailure, nodeTypeString) +
                                        string.Format(Properties.Resources.FaceReferenceExtractionDetail, curveObject));
        }
Exemple #3
0
        /// <summary>
        /// Create a Dimension for an Element in the specified direction and view.
        /// </summary>
        /// <param name="view">View to place dimension in</param>
        /// <param name="element">The element of generated Dimension</param>
        /// <param name="direction">The direction to create Dimension</param>
        /// <param name="line">location of the dimension</param>
        /// <param name="suffix">Suffix</param>
        /// <param name="prefix">Prefix</param>
        /// <returns></returns>
        public static Dimension ByElementDirection(Revit.Elements.Views.View view, Revit.Elements.Element element, Autodesk.DesignScript.Geometry.Vector direction, [DefaultArgument("null")] Autodesk.DesignScript.Geometry.Line line, string suffix = "", string prefix = "")
        {
            Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement;
            if (!view.IsAnnotationView())
            {
                throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations);
            }

            var revitDirection = direction.ToRevitType();

            List <Autodesk.Revit.DB.PlanarFace> planars = new List <PlanarFace>();

            ReferenceArray array = new ReferenceArray();

            var opt = new Options();

            opt.ComputeReferences = true;

            var  faces      = element.InternalGeometry(false).OfType <Autodesk.Revit.DB.Solid>().SelectMany(x => x.Faces.OfType <Autodesk.Revit.DB.PlanarFace>());
            var  references = faces.Select(x => x.Reference);
            Line revitLine  = null;

            foreach (var face in faces)
            {
                var isParallel = direction.IsParallel(face.FaceNormal.ToVector());
                if (isParallel)
                {
                    array.Append(face.Reference);
                    planars.Add(face);
                }
            }

            if (planars.Count < 2)
            {
                throw new Exception(string.Format(Properties.Resources.NotEnoughDataError, "Surface on this Direction"));
            }

            if (line == null)
            {
                revitLine = Line.CreateBound(planars[0].Origin, planars[0].Origin.Add(direction.ToXyz()));
            }
            else
            {
                revitLine = (Line)line.ToRevitType(true);
            }

            return(new Dimension(revitView, revitLine, array, suffix, prefix));
        }
 public static IEnumerable <Autodesk.Revit.DB.Solid> GetRevitSolids(Element ele)
 {
     return(ele.InternalGeometry().OfType <Autodesk.Revit.DB.Solid>().ToArray());
 }
Exemple #5
0
 public static IEnumerable<Autodesk.Revit.DB.Solid> GetRevitSolids(Element ele)
 {
     return ele.InternalGeometry().OfType<Autodesk.Revit.DB.Solid>().ToArray();
 }