public override Value Evaluate(FSharpList <Value> args) { Reference faceRef = (args[1] as Value.Container).Item as Reference; Autodesk.Revit.DB.Face f = (faceRef == null) ? ((args[1] as Value.Container).Item as Autodesk.Revit.DB.Face) : dynRevitSettings.Doc.Document.GetElement(faceRef).GetGeometryObjectFromReference(faceRef) as Autodesk.Revit.DB.Face; XYZ norm = null; if (f != null) { //each item in the list will be a reference point UV uv = (UV)(args[0] as Value.Container).Item; norm = f.ComputeNormal(uv); } return(Value.NewContainer(norm)); }
/// <summary> /// Returns a vector represnting the normal of an analysis surface. Useful for sorting/grouping surfaces upstream of a SetSurfaceParameters node. /// </summary> /// <param name="SurfaceId">The ElementId of the surface to create a vector from. Get this from AnalysisZones > CreateFrom* > SurfaceIds output list</param> /// <returns></returns> public static Autodesk.DesignScript.Geometry.Vector AnalysisSurfaceVector(ElementId SurfaceId) { //local varaibles Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document; MassSurfaceData surf = null; Autodesk.Revit.DB.ElementId myEnergyModelId = null; //try to get the MassSurfaceData object from the document try { surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId)); if (surf == null) { throw new Exception(); } } catch (Exception) { throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString()); } //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from try { myEnergyModelId = surf.ReferenceElementId; if (myEnergyModelId == null) { throw new Exception(); } } catch (Exception) { throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + surf.ReferenceElementId.ToString()); } //try to get the MassSurfaceData object from the document try { surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId)); if (surf == null) { throw new Exception(); } } catch (Exception) { throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString()); } //get the smallest face Autodesk.Revit.DB.Face bigFace = GetLargestFace(RvtDoc, surf, myEnergyModelId); // Find the face normal at the center of the face BoundingBoxUV bbox = bigFace.GetBoundingBox(); // center of the face in the UV of the face Autodesk.Revit.DB.UV center = new Autodesk.Revit.DB.UV((bbox.Max.U - bbox.Min.U) / 2 + bbox.Min.U, (bbox.Max.V - bbox.Min.V) / 2 + bbox.Min.V); XYZ faceNormal = bigFace.ComputeNormal(center); XYZ normal = faceNormal.Normalize(); return(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(normal.X, normal.Y, normal.Z, true)); }