void setupParticleSystem(Autodesk.Revit.DB.Face f, int uDiv, int vDiv, double springDampening, double springRestLength, double springConstant, double mass) { BoundingBoxUV bbox = f.GetBoundingBox(); double uStep = (bbox.Max.U - bbox.Min.U) / uDiv; double vStep = (bbox.Max.V - bbox.Min.V) / vDiv; for (int j = 0; j <= uDiv; j++) // Y axis is outer loop { double u = bbox.Min.U + uStep * j; for (int i = 0; i <= vDiv; i++) // X axis is inner loop { double v = bbox.Min.V + vStep * i; Particle a = particleSystem.makeParticle(mass, f.Evaluate(new UV(u, v)), false); if (i > 0) { particleSystem.makeSpring(particleSystem.getParticle((i - 1) + (j * (vDiv + 1))), a, springRestLength, springConstant, springDampening); } if (j > 0) { Particle b = particleSystem.getParticle(i + ((j - 1) * (vDiv + 1))); particleSystem.makeSpring(a, b, springRestLength, springConstant, springDampening); } if (i == 0 || i == vDiv || j == 0 || j == uDiv) { a.makeFixed(); } } } }
static Surface ToRhinoSurface(this DB.Face face) { Surface surface = default; using (var faceSurface = face.GetSurface()) { var bboxUV = face.GetBoundingBox(); switch (faceSurface) { case DB.Plane planeSurface: surface = planeSurface.ToRhino(bboxUV); break; case DB.ConicalSurface conicalSurface: surface = conicalSurface.ToRhino(bboxUV); break; case DB.CylindricalSurface cylindricalSurface: surface = cylindricalSurface.ToRhino(bboxUV); break; case DB.RevolvedSurface revolvedSurface: surface = revolvedSurface.ToRhino(bboxUV); break; case DB.RuledSurface ruledSurface: surface = ruledSurface.ToRhino(bboxUV); break; case DB.HermiteSurface hermiteSurface: try { using (var nurbsData = DB.ExportUtils.GetNurbsSurfaceDataForFace(face)) surface = nurbsData.ToRhino(bboxUV); } catch (Autodesk.Revit.Exceptions.ArgumentException) { } break; default: throw new NotImplementedException(); } } return(surface); }
public Surface FaceToSpeckle(DB.Face face, out bool parametricOrientation, double relativeTolerance = 0.0, string units = null) { var u = units ?? ModelUnits; using (var surface = face.GetSurface()) parametricOrientation = surface.OrientationMatchesParametricOrientation; switch (face) { case null: return(null); case PlanarFace planar: return(FaceToSpeckle(planar, relativeTolerance, u)); case ConicalFace conical: return(FaceToSpeckle(conical, relativeTolerance, u)); case CylindricalFace cylindrical: return(FaceToSpeckle(cylindrical, relativeTolerance, u)); case RevolvedFace revolved: return(FaceToSpeckle(revolved, relativeTolerance, u)); case RuledFace ruled: return(FaceToSpeckle(ruled, relativeTolerance, u)); case HermiteFace hermite: return(FaceToSpeckle(hermite, face.GetBoundingBox(), u)); default: throw new NotImplementedException(); } }
public Geometry.Surface FaceToSpeckle(DB.Face face, DB.BoundingBoxUV uvBox, string units = null) { #if (REVIT2021 || REVIT2022) var surf = DB.ExportUtils.GetNurbsSurfaceDataForSurface(face.GetSurface()); #else var surf = DB.ExportUtils.GetNurbsSurfaceDataForFace(face); #endif var spcklSurface = NurbsSurfaceToSpeckle(surf, face.GetBoundingBox(), units ?? ModelUnits); return(spcklSurface); }
public Geometry.Surface FaceToSpeckle(DB.Face face, DB.BoundingBoxUV uvBox) { #if REVIT2021 var surf = DB.ExportUtils.GetNurbsSurfaceDataForSurface(face.GetSurface()); #else var surf = DB.ExportUtils.GetNurbsSurfaceDataForFace(face); #endif var spcklSurface = NurbsSurfaceToSpeckle(surf, face.GetBoundingBox()); return(spcklSurface); }
/// <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)); }