/// <summary> /// This method contains workarounds for increasing the robustness of input geometry /// </summary> /// <param name="geometry"></param> /// <param name="translation"></param> private static void Robustify(ref Autodesk.DesignScript.Geometry.Geometry[] geometry, ref Autodesk.DesignScript.Geometry.Vector translation) { // translate all geom to centroid of bbox, then translate back var bb = Autodesk.DesignScript.Geometry.BoundingBox.ByGeometry(geometry); // get center of bbox var trans = ((bb.MinPoint.ToXyz() + bb.MaxPoint.ToXyz())/2).ToVector().Reverse(); // translate all geom so that it is centered by bb geometry = geometry.Select(x => x.Translate(trans)).ToArray(); // so that we can move it all back translation = trans.Reverse(); }
public static DividedPath ByCurvesAndDivisions(Autodesk.DesignScript.Geometry.Curve[] curve, int divisions) { if (curve == null) { throw new ArgumentNullException("curve"); } if (divisions < 2) { throw new Exception("The number of divisions must be greater than 2!"); } if (curve.Any(x => x == null)) { throw new ArgumentNullException(String.Format("curves[{0}]", Array.FindIndex(curve, x => x == null))); } return new DividedPath(curve.Select(x => ElementCurveReference.TryGetCurveReference(x)).ToArray(), divisions); }
/// <summary> /// Create an adaptive component by uv points on a face. /// </summary> /// <param name="uvs">An array of UV pairs</param> /// <param name="surface">The surface on which to place the AdaptiveComponent</param> /// <param name="familySymbol"></param> /// <returns></returns> public static AdaptiveComponent ByParametersOnFace( Autodesk.DesignScript.Geometry.UV[] uvs, Surface surface, FamilySymbol familySymbol) { if (uvs == null) { throw new ArgumentNullException("uvs"); } if (surface == null) { throw new ArgumentNullException("surface"); } if (familySymbol == null) { throw new ArgumentNullException("familySymbol"); } return new AdaptiveComponent(uvs.Select(x => new []{x.U,x.V}).ToArray(), ElementFaceReference.TryGetFaceReference(surface), familySymbol); }
/// <summary> /// Import a collection of Geometry (Solid, Curve, Surface, etc) into Revit as an ImportInstance. This variant is much faster than /// ImportInstance.ByGeometry as it uses a batch method. /// </summary> /// <param name="geometries">A collection of Geometry</param> /// <returns></returns> public static ImportInstance ByGeometries(Autodesk.DesignScript.Geometry.Geometry[] geometries) { if (geometries == null) { throw new ArgumentNullException("geometries"); } // transform geometry from dynamo unit system (m) to revit (ft) geometries = geometries.Select(x => x.InHostUnits()).ToArray(); var translation = Vector.ByCoordinates(0, 0, 0); Robustify(ref geometries, ref translation); // Export to temporary file var fn = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".sat"; var exported_fn = Autodesk.DesignScript.Geometry.Geometry.ExportToSAT(geometries, fn); return new ImportInstance(exported_fn, translation.ToXyz()); }