/// <summary> /// Form a Refernece plane from two end points in the Active view. The cut vector is the Z Axis. /// </summary> /// <param name="start">The location where the bubble will be located</param> /// <param name="end">The other end</param> /// <returns></returns> public static ReferencePlane ByStartPointEndPoint( Point start, Point end ) { if (start == null) { throw new ArgumentNullException("start"); } if (end == null) { throw new ArgumentNullException("end"); } return new ReferencePlane( start.ToXyz(), end.ToXyz(), (end.ToXyz() - start.ToXyz()).GetPerpendicular(), Document.ActiveView); }
/// <summary> /// Creates a Conduit by a curve. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="curve">The curve.</param> /// <returns></returns> public static Conduit ByCurve(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve) { Utils.Log(string.Format("Conduit.ByCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } Utils.Log(string.Format("Conduit.ByCurve completed.", "")); return(new Conduit(oType, s, e)); }
/// <summary> /// Creates a pipe by two points. /// </summary> /// <param name="pipeType">Type of the pipe.</param> /// <param name="pipingSystemType">Type of the piping system.</param> /// <param name="start">The start point.</param> /// <param name="end">The end point.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Pipe ByPoints(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level) { Utils.Log(string.Format("Pipe.ByPoints started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var totalTransform = RevitUtils.DocumentTotalTransform(); start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; totalTransform.Dispose(); Utils.Log(string.Format("Pipe.ByPoints completed.", "")); return(new Pipe(oType, oSystemType, s, e, l)); }
/// <summary> /// Create a Revit Axonometric (isometric) 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 AxonometricView ByEyePointTargetAndElement( Autodesk.DesignScript.Geometry.Point eyePoint, Autodesk.DesignScript.Geometry.Point target, Element element, string name, bool isolateElement) { if (element == null) { throw new ArgumentNullException("element"); } 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 AxonometricView(eyePoint.ToXyz(), target.ToXyz(), element.InternalElement, name, isolateElement)); }
/// <summary> /// Moves this viewport so that the center of the box outline (excluding the viewport label) is at a given point. /// </summary> /// <param name="point"></param> public Viewport SetBoxCenter(Autodesk.DesignScript.Geometry.Point point) { TransactionManager.Instance.EnsureInTransaction(Application.Document.Current.InternalDocument); this.InternalViewport.SetBoxCenter(point.ToXyz()); TransactionManager.Instance.TransactionTaskDone(); return(this); }
/// <summary> /// Form a Refernece plane from two end points in the Active view. The cut vector is the Z Axis. /// </summary> /// <param name="start">The location where the bubble will be located</param> /// <param name="end">The other end</param> /// <returns></returns> public static ReferencePlane ByStartPointEndPoint(Point start, Point end) { if (start == null) { throw new ArgumentNullException("start"); } if (end == null) { throw new ArgumentNullException("end"); } return(new ReferencePlane(start.ToXyz(), end.ToXyz(), (end.ToXyz() - start.ToXyz()).GetPerpendicular(), Document.ActiveView)); }
/// <summary> /// Creates a set of CableTrays following a PolyCurve specifying a maximum length. /// </summary> /// <param name="CableTrayType">The CableTray type.</param> /// <param name="polyCurve">The PolyCurve to follow.</param> /// <param name="maxLength">The maximum length of the CableTrays following the PolyCurve.</param> /// <returns></returns> private CableTray[] ByPolyCurve(Revit.Elements.Element CableTrayType, PolyCurve polyCurve, double maxLength) { Utils.Log(string.Format("CableTray.ByPolyCurve started...", "")); var oType = CableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; double length = polyCurve.Length; double subdivisions = Math.Ceiling(length / maxLength); double increment = 1 / subdivisions; IList <double> parameters = new List <double>(); double parameter = 0; IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); while (parameter <= 1) { points.Add(polyCurve.PointAtParameter(parameter)); parameter = parameter + increment; } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); IList <ElementId> ids = new List <ElementId>(); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var totalTransform = RevitUtils.DocumentTotalTransform(); for (int i = 0; i < points.Count - 1; ++i) { Autodesk.DesignScript.Geometry.Point start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = points[i + 1].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); Autodesk.Revit.DB.Electrical.CableTray p = Autodesk.Revit.DB.Electrical.CableTray.Create(DocumentManager.Instance.CurrentDBDocument, oType.Id, s, e, ElementId.InvalidElementId); ids.Add(p.Id); } for (int i = 0; i < GetCableTrayByIds(ids).Length - 1; ++i) { CableTray ct1 = GetCableTrayByIds(ids)[i]; CableTray ct2 = GetCableTrayByIds(ids)[i + 1]; Fitting.Elbow(ct1, ct2); } TransactionManager.Instance.TransactionTaskDone(); Utils.Log(string.Format("CableTray.ByPolyCurve completed.", "")); return(GetCableTrayByIds(ids)); }
/// <summary> /// Creates a Conduit by a curve. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="curve">The curve.</param> /// <param name="featureline">The featureline.</param> /// <returns></returns> public static Conduit ByCurveFeatureline(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve, Featureline featureline) { Utils.Log(string.Format("Conduit.ByCurveFeatureline started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var pipe = new Conduit(oType, s, e); var startSOE = featureline.GetStationOffsetElevationByPoint(curve.StartPoint); var endSOE = featureline.GetStationOffsetElevationByPoint(curve.EndPoint); double startStation = (double)startSOE["Station"]; double startOffset = (double)startSOE["Offset"]; double startElevation = (double)startSOE["Elevation"]; double endStation = (double)endSOE["Station"]; double endOffset = (double)endSOE["Offset"]; double endElevation = (double)endSOE["Elevation"]; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.RegionIndex.Name, featureline.BaselineRegionIndex); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionRelative.Name, startStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionNormalized.Name, (startStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(curve.StartPoint.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(curve.StartPoint.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(curve.StartPoint.Z, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round(startStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round(startOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round(startElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round(endStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round(endOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round(endElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionRelative.Name, endStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionNormalized.Name, (endStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 totalTransform.Dispose(); Utils.Log(string.Format("Conduit.ByCurveFeatureline completed.", "")); return(pipe); }
/// <summary> /// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API), it's coordinates in world space, and the Level /// </summary> /// <param name="familyType">Family Type. Also called Family Symbol.</param> /// <param name="point">Point in meters.</param> /// <param name="level">Level to host Family Instance.</param> /// <returns></returns> public static FamilyInstance ByPointAndLevel(FamilyType familyType, Point point, Level level) { if (familyType == null) { throw new ArgumentNullException("familyType"); } return(new FamilyInstance(familyType.InternalFamilySymbol, point.ToXyz(), level.InternalLevel)); }
public static bool ContainsPoint(global::Revit.Elements.Element area, Point point) { Autodesk.Revit.DB.Area internalArea = area.InternalElement as Autodesk.Revit.DB.Area; if (internalArea.Area == 0) { return(false); } XYZ xyz = point.ToXyz(); return(internalArea.AreaContains(xyz)); }
/// <summary> /// Add Point to Slab Shape /// </summary> public void AddPoint(Pt point) { if (this.InternalRoof.SlabShapeEditor == null) { throw new Exception(Properties.Resources.InvalidShapeEditor); } TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); this.InternalRoof.SlabShapeEditor.Enable(); this.InternalRoof.SlabShapeEditor.DrawPoint(point.ToXyz()); TransactionManager.Instance.TransactionTaskDone(); }
public static Dictionary <string, object> ByOriginDirection(Point origin, Vector direction, int maxBounces, Elements.Views.View3D view) { var startpt = origin.ToXyz(); var rayCount = 0; var bouncePts = new List <Point> { origin }; var bounceElements = new List <Elements.Element>(); for (int ctr = 1; ctr <= maxBounces; ctr++) { var referenceIntersector = new ReferenceIntersector((View3D)view.InternalElement); IList <ReferenceWithContext> references = referenceIntersector.Find(startpt, direction.ToXyz()); ReferenceWithContext rClosest = null; rClosest = FindClosestReference(references); if (rClosest == null) { break; } else { var reference = rClosest.GetReference(); var referenceElement = DocumentManager.Instance.CurrentDBDocument.GetElement(reference); var referenceObject = referenceElement.GetGeometryObjectFromReference(reference); bounceElements.Add(referenceElement.ToDSType(true)); var endpt = reference.GlobalPoint; if (startpt.IsAlmostEqualTo(endpt)) { break; } else { rayCount = rayCount + 1; var currFace = referenceObject as Face; var endptUV = reference.UVPoint; var FaceNormal = currFace.ComputeDerivatives(endptUV).BasisZ; // face normal where ray hits FaceNormal = rClosest.GetInstanceTransform().OfVector(FaceNormal); // transformation to get it in terms of document coordinates instead of the parent symbol var directionMirrored = direction.ToXyz() - 2 * direction.ToXyz().DotProduct(FaceNormal) * FaceNormal; //http://www.fvastro.org/presentations/ray_tracing.htm direction = directionMirrored.ToVector(); // get ready to shoot the next ray startpt = endpt; bouncePts.Add(endpt.ToPoint()); } } } return(new Dictionary <string, object> { { "points", bouncePts }, { "elements", bounceElements } }); }
/// <summary> /// Create a Reference Point from a point. /// </summary> /// <param name="pt"></param> /// <returns></returns> public static ReferencePoint ByPoint(Point pt) { if (pt == null) { throw new ArgumentNullException("pt"); } if (!Document.IsFamilyDocument) { throw new Exception(Properties.Resources.ReferencePointCreationFailure); } return(new ReferencePoint(pt.ToXyz())); }
/// <summary> /// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API) and its coordinates in world space /// </summary> /// <param name="familyType">Family Type. Also called Family Symbol.</param> /// <param name="point">Point in meters.</param> /// <returns></returns> public static FamilyInstance ByPoint(FamilyType familyType, Point point) { if (familyType == null) { throw new ArgumentNullException("familyType"); } if (point == null) { throw new ArgumentNullException("point"); } return(new FamilyInstance(familyType.InternalFamilySymbol, point.ToXyz())); }
/// <summary> /// Create a Reference Point from a point. /// </summary> /// <param name="pt"></param> /// <returns></returns> public static ReferencePoint ByPoint(Point pt) { if (pt == null) { throw new ArgumentNullException("pt"); } if (!Document.IsFamilyDocument) { throw new Exception("ReferencePoint Elements can only be created in a Family Document"); } return(new ReferencePoint(pt.ToXyz())); }
public static Dictionary<string,object> ByOriginDirection(Point origin, Vector direction, int maxBounces, Elements.Views.View3D view) { var startpt = origin.ToXyz(); var rayCount = 0; var bouncePts = new List<Point> {origin}; var bounceElements = new List<Elements.Element>(); for (int ctr = 1; ctr <= maxBounces; ctr++) { var referenceIntersector = new ReferenceIntersector((View3D)view.InternalElement); IList<ReferenceWithContext> references = referenceIntersector.Find(startpt, direction.ToXyz()); ReferenceWithContext rClosest = null; rClosest = FindClosestReference(references); if (rClosest == null) { break; } else { var reference = rClosest.GetReference(); var referenceElement = DocumentManager.Instance.CurrentDBDocument.GetElement(reference); var referenceObject = referenceElement.GetGeometryObjectFromReference(reference); bounceElements.Add(referenceElement.ToDSType(true)); var endpt = reference.GlobalPoint; if (startpt.IsAlmostEqualTo(endpt)) { break; } else { rayCount = rayCount + 1; var currFace = referenceObject as Face; var endptUV = reference.UVPoint; var FaceNormal = currFace.ComputeDerivatives(endptUV).BasisZ; // face normal where ray hits FaceNormal = rClosest.GetInstanceTransform().OfVector(FaceNormal); // transformation to get it in terms of document coordinates instead of the parent symbol var directionMirrored = direction.ToXyz() - 2 * direction.ToXyz().DotProduct(FaceNormal) * FaceNormal; //http://www.fvastro.org/presentations/ray_tracing.htm direction = directionMirrored.ToVector(); // get ready to shoot the next ray startpt = endpt; bouncePts.Add(endpt.ToPoint()); } } } return new Dictionary<string, object> { { "points", bouncePts }, { "elements", bounceElements } }; }
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); }
/// <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(Point basePoint, 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)); }
/// <summary> /// Creates a Conduit by two points. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="start">The start point.</param> /// <param name="end">The end point.</param> /// <returns></returns> public static Conduit ByPoints(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end) { Utils.Log(string.Format("Conduit.ByPoints started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); totalTransform.Dispose(); Utils.Log(string.Format("Conduit.ByPoints completed.", "")); return(new Conduit(oType, s, e)); }
/// <summary> /// Creates a CableTray by two Points. /// </summary> /// <param name="cableTrayType">Type of the cable tray.</param> /// <param name="start">The start Point.</param> /// <param name="end">The end Point.</param> /// <returns></returns> public static CableTray ByPoints(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end) { Utils.Log(string.Format("CableTray.ByPoints started...", "")); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var oType = cableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; var totalTransform = RevitUtils.DocumentTotalTransform(); start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); TransactionManager.Instance.TransactionTaskDone(); Utils.Log(string.Format("CableTray.ByPoints completed.", "")); return(new CableTray(oType, s, e)); }
/// <summary> /// Creates a pipe by two points. /// </summary> /// <param name="ductType">Type of the duct.</param> /// <param name="mechanicalSystemType">Type of the mechanical system.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Duct ByPoints(Revit.Elements.Element ductType, Revit.Elements.Element mechanicalSystemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level) { Utils.Log(string.Format("Duct.ByPoints started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); var oType = ductType.InternalElement as Autodesk.Revit.DB.Mechanical.DuctType; var oSystemType = mechanicalSystemType.InternalElement as Autodesk.Revit.DB.Mechanical.MechanicalSystemType; start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; totalTransform.Dispose(); Utils.Log(string.Format("Duct.ByPoints completed.", "")); return(new Duct(oType, oSystemType, s, e, l)); }
/// <summary> /// CableTray by curve. /// </summary> /// <param name="cableTrayType">Type of the cable tray.</param> /// <param name="curve">The curve.</param> /// <returns>It Uses the start and end Points of the curve to create the CableTray</returns> private static CableTray CableTrayByCurve(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Curve curve) { Utils.Log(string.Format("CableTray.CableTrayByCurve started...", "")); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var oType = cableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; var totalTransform = RevitUtils.DocumentTotalTransform(); Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); TransactionManager.Instance.TransactionTaskDone(); start.Dispose(); end.Dispose(); Utils.Log(string.Format("CableTray.CableTrayByCurve completed.", "")); return(new CableTray(oType, s, e)); }
/// <summary> /// Creates a pipe by curve. /// </summary> /// <param name="ductType">Type of the duct.</param> /// <param name="mechanicalSystemType">Type of the mechanical system.</param> /// <param name="curve">The curve.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Duct ByCurve(Revit.Elements.Element ductType, Revit.Elements.Element mechanicalSystemType, Autodesk.DesignScript.Geometry.Curve curve, Revit.Elements.Level level) { Utils.Log(string.Format("Duct.ByCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); Autodesk.DesignScript.Geometry.Point start = null; Autodesk.DesignScript.Geometry.Point end = null; if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = ductType.InternalElement as Autodesk.Revit.DB.Mechanical.DuctType; var oSystemType = mechanicalSystemType.InternalElement as Autodesk.Revit.DB.Mechanical.MechanicalSystemType; start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } Utils.Log(string.Format("Duct.ByCurve completed.", "")); return(new Duct(oType, oSystemType, s, e, l)); }
/// <summary> /// Create a Revit Axonometric (isometric) View from an Eye position and target position and Bounding Box /// </summary> /// <param name="eyePoint"></param> /// <param name="target"></param> /// <param name="boundingBox"></param> /// <param name="name"></param> /// <param name="isolateElement"></param> /// <returns></returns> public static AxonometricView 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 AxonometricView(eyePoint.ToXyz(), target.ToXyz(), boundingBox.ToRevitType(), name, isolateElement)); }
/// <summary> /// Place a Revit family instance given the FamilyType (also known as the FamilySymbol in the Revit API) /// on a surface derived from a backing Revit face as reference, a reference direction and a point location where to place the family. /// /// Note: The FamilyType should be workplane based and the input surface must be created from a Revit Face. The reference direction defines the rotation of the instance on the reference, and thus cannot be perpendicular to the face. /// </summary> /// <param name="familyType">Family Type. Also called Family Symbol.</param> /// <param name="face">Surface geometry derived from a Revit face as reference element</param> /// <param name="location">Point on the face where the instance is to be placed</param> /// <param name="referenceDirection">A vector that defines the direction of placement of the family instance</param> /// <returns>FamilyInstance</returns> public static FamilyInstance ByFace(FamilyType familyType, Surface face, Point location, Vector referenceDirection) { if (familyType == null) { throw new ArgumentNullException("familyType"); } if (face == null) { throw new ArgumentNullException("face"); } if (location == null) { throw new ArgumentNullException("location"); } if (referenceDirection == null) { throw new ArgumentNullException("referenceDirection"); } var reference = ElementFaceReference.TryGetFaceReference(face); return(new FamilyInstance(familyType.InternalFamilySymbol, reference.InternalReference, location.ToXyz(), referenceDirection.ToXyz())); }
/// <summary> /// Create a torus aligned to an axis with a radius and a section radius. /// </summary> /// <param name="axis"></param> /// <param name="center"></param> /// <param name="radius"></param> /// <param name="sectionRadius"></param> /// <returns></returns> public static Solid Torus(Vector axis, Point center, double radius, double sectionRadius) { if (center == null) { throw new ArgumentException("Center is null"); } if (axis == null || axis.Length < 1e-6) { throw new ArgumentException("Your axis is null or is 0 length."); } if (radius <= 0) { throw new ArgumentException("The radius must be greater than zero."); } if (sectionRadius <= 0) { throw new ArgumentException("The section radius must be greater than zero."); } var revolveAxis = axis.ToXyz(); // get axis that is perp to axis by first generating random vector var zaxis = revolveAxis.Normalize(); var randXyz = new XYZ(1, 0, 0); if (zaxis.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); // form origin of the arc var origin = center.ToXyz() + xaxis * radius; // create circle (this is ridiculous but curve loop doesn't work with a circle var arc1 = Autodesk.Revit.DB.Ellipse.Create(origin, sectionRadius, sectionRadius, xaxis, zaxis, 0, RevitPI); var arc2 = Autodesk.Revit.DB.Ellipse.Create(origin, sectionRadius, sectionRadius, xaxis, zaxis, RevitPI, 2 * RevitPI); // create curve loop from cirle var circleLoop = CurveLoop.Create(new List<Curve>() { arc1, arc2 }); var trans = Transform.Identity; trans.Origin = center.ToXyz(); trans.BasisX = xaxis; trans.BasisY = yaxis; trans.BasisZ = zaxis; return new Solid(circleLoop, trans, 0, 2*RevitPI); }
public static Dictionary <string, object> ByPolyCurve(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, PolyCurve polyCurve, Revit.Elements.Level level, double maxLength, Featureline featureline) { Utils.Log(string.Format("Pipe.ByPolyCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); var totalTransformInverse = totalTransform.Inverse(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var l = level.InternalElement as Autodesk.Revit.DB.Level; double length = polyCurve.Length; int subdivisions = Convert.ToInt32(Math.Ceiling(length / maxLength)); IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); points.Add(polyCurve.StartPoint); foreach (Autodesk.DesignScript.Geometry.Point p in polyCurve.PointsAtEqualChordLength(subdivisions)) { points.Add(p); } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); IList <ElementId> ids = new List <ElementId>(); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); Autodesk.DesignScript.Geometry.Point start = null; Autodesk.DesignScript.Geometry.Point end = null; Autodesk.DesignScript.Geometry.Point sp = null; Autodesk.DesignScript.Geometry.Point ep = null; Autodesk.DesignScript.Geometry.Curve curve = null; for (int i = 0; i < points.Count - 1; ++i) { start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = points[i + 1].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); Autodesk.Revit.DB.Plumbing.Pipe p = Autodesk.Revit.DB.Plumbing.Pipe.CreatePlaceholder(DocumentManager.Instance.CurrentDBDocument, oSystemType.Id, oType.Id, l.Id, s, e); ids.Add(p.Id); } var pipeIds = Autodesk.Revit.DB.Plumbing.PlumbingUtils.ConvertPipePlaceholders(DocumentManager.Instance.CurrentDBDocument, ids); TransactionManager.Instance.TransactionTaskDone(); DocumentManager.Instance.CurrentDBDocument.Regenerate(); Pipe[] pipes = GetPipesByIds(pipeIds); foreach (Pipe pipe in pipes) { curve = pipe.Location.Transform(totalTransformInverse) as Autodesk.DesignScript.Geometry.Curve; sp = curve.StartPoint; ep = curve.EndPoint; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(sp.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(sp.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(sp.Z, 3)); var soe = featureline.GetStationOffsetElevationByPoint(sp); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round((double)soe["Elevation"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); soe = featureline.GetStationOffsetElevationByPoint(ep); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round((double)soe["Elevation"], 3)); } IList <Fitting> fittings = new List <Fitting>(); for (int i = 0; i < pipes.Length - 1; ++i) { Fitting fitting = null; try { fitting = Fitting.Elbow(pipes[i], pipes[i + 1]); } catch { } fittings.Add(fitting); } if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } if (sp != null) { sp.Dispose(); } if (ep != null) { ep.Dispose(); } if (curve != null) { curve.Dispose(); } foreach (var item in points) { if (item != null) { item.Dispose(); } } points.Clear(); Utils.Log(string.Format("Pipe.ByPolyCurve completed.", "")); return(new Dictionary <string, object>() { { "Pipes", pipes }, { "Fittings", fittings } }); }
private static Conduit[] ByPolyCurve(Revit.Elements.Element conduitType, PolyCurve polyCurve, double maxLength) { Utils.Log(string.Format("Conduit.ByPolyCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; double length = polyCurve.Length; double subdivisions = Math.Ceiling(length / maxLength); double increment = 1 / subdivisions; IList <double> parameters = new List <double>(); double parameter = 0; IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); while (parameter <= 1) { points.Add(polyCurve.PointAtParameter(parameter)); parameter = parameter + increment; } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); // this is slow IList <ElementId> ids = new List <ElementId>(); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); Autodesk.DesignScript.Geometry.Point start = null; Autodesk.DesignScript.Geometry.Point end = null; for (int i = 0; i < points.Count - 1; ++i) { start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = points[i + 1].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); Autodesk.Revit.DB.Electrical.Conduit p = Autodesk.Revit.DB.Electrical.Conduit.Create(DocumentManager.Instance.CurrentDBDocument, oType.Id, s, e, ElementId.InvalidElementId); ids.Add(p.Id); } var res = GetConduitByIds(ids); for (int i = 0; i < GetConduitByIds(ids).Length - 1; ++i) { Conduit ct1 = res[i]; Conduit ct2 = res[i + 1]; Fitting.Elbow(ct1, ct2); } TransactionManager.Instance.TransactionTaskDone(); if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } foreach (var pt in points) { if (pt != null) { pt.Dispose(); } } points.Clear(); Utils.Log(string.Format("Conduit.ByPolyCurve completed.", "")); return(res); }
public static Dictionary <string, object> ByPolyCurve(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.PolyCurve polyCurve, double maxLength, Featureline featureline) { Utils.Log(string.Format("Conduit.ByPolyCurve started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var totalTransform = RevitUtils.DocumentTotalTransform(); var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; IList <Conduit> output = new List <Conduit>(); IList <Fitting> fittings = new List <Fitting>(); double length = polyCurve.Length; int subdivisions = Convert.ToInt32(Math.Ceiling(length / maxLength)); IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); points.Add(polyCurve.StartPoint); foreach (Autodesk.DesignScript.Geometry.Point p in polyCurve.PointsAtEqualChordLength(subdivisions)) { points.Add(p); } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); Autodesk.DesignScript.Geometry.Point start = null; Autodesk.DesignScript.Geometry.Point end = null; Autodesk.DesignScript.Geometry.Point sp = null; Autodesk.DesignScript.Geometry.Point ep = null; Autodesk.DesignScript.Geometry.Curve curve = null; for (int i = 0; i < points.Count - 1; ++i) { start = points[i]; end = points[i + 1]; curve = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(start, end); sp = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; ep = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var pipe = new Conduit(oType, sp.ToXyz(), ep.ToXyz()); pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(start.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(start.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(start.Z, 3)); var soe = featureline.GetStationOffsetElevationByPoint(start); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round((double)soe["Elevation"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); soe = featureline.GetStationOffsetElevationByPoint(end); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round((double)soe["Elevation"], 3)); output.Add(pipe); if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } if (sp != null) { sp.Dispose(); } if (ep != null) { ep.Dispose(); } if (curve != null) { curve.Dispose(); } } for (int i = 0; i < output.Count - 1; ++i) { Fitting fitting = null; try { fitting = Fitting.Elbow(output[i], output[i + 1]); } catch { } fittings.Add(fitting); } foreach (var pt in points) { if (pt != null) { pt.Dispose(); } } points.Clear(); Utils.Log(string.Format("Conduit.ByPolyCurve completed.", "")); return(new Dictionary <string, object>() { { "Conduit", output }, { "Fittings", fittings } }); }
/// <summary> /// Creates a new ElevationMarker. /// </summary> /// <param name="viewFamilyType">The ViewFamilyType that will be used by all elevations hosted on the new ElevationMarker.</param> /// <param name="location">The desired origin for the ElevationMarker.</param> /// <param name="initialViewScale">The view scale will be automatically applied to new elevations created on the ElevationMarker. The scale is the ratio of true model size to paper size (e.g. input 100 for 1:100 scale).</param> /// <returns>The new ElevationMarker element.</returns> public static ElevationMarker ByViewTypeLocation(Element viewFamilyType, Autodesk.DesignScript.Geometry.Point location, int initialViewScale) { TransactionManager.Instance.EnsureInTransaction(Document); var elevationMarker = Autodesk.Revit.DB.ElevationMarker.CreateElevationMarker(Document, viewFamilyType.InternalElement.Id, location.ToXyz(), initialViewScale); TransactionManager.Instance.TransactionTaskDone(); return(new ElevationMarker(elevationMarker)); }
public static Dictionary <string, object> ByPolyCurve(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.PolyCurve polyCurve, double maxLength, Featureline featureline) { Utils.Log(string.Format("CableTray.ByPolyCurve started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } double length = polyCurve.Length; var oType = cableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; IList <CableTray> output = new List <CableTray>(); IList <Fitting> fittings = new List <Fitting>(); int subdivisions = Convert.ToInt32(Math.Ceiling(length / maxLength)); Utils.Log(string.Format("subdivisions {0}", subdivisions)); IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); try { points.Add(polyCurve.StartPoint); foreach (Autodesk.DesignScript.Geometry.Point p in polyCurve.PointsAtEqualChordLength(subdivisions)) { points.Add(p); } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); // This is slow } catch { points = Featureline.PointsByChord(polyCurve, maxLength); // This is slow } Utils.Log(string.Format("Points {0}", points.Count)); var totalTransform = RevitUtils.DocumentTotalTransform(); Autodesk.DesignScript.Geometry.Point s = null; Autodesk.DesignScript.Geometry.Point e = null; Autodesk.DesignScript.Geometry.Point sp = null; Autodesk.DesignScript.Geometry.Point ep = null; Autodesk.DesignScript.Geometry.Curve curve = null; TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); for (int i = 0; i < points.Count - 1; ++i) { s = points[i]; e = points[i + 1]; curve = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(s, e); sp = s.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; ep = e.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var pipe = new CableTray(); Autodesk.Revit.DB.MEPCurve fi; if (DocumentManager.Instance.CurrentDBDocument.IsFamilyDocument) { fi = null; } else { fi = Autodesk.Revit.DB.Electrical.CableTray.Create(DocumentManager.Instance.CurrentDBDocument, oType.Id, sp.ToXyz(), ep.ToXyz(), ElementId.InvalidElementId) as Autodesk.Revit.DB.MEPCurve; } pipe.InitObject((Autodesk.Revit.DB.Electrical.CableTray)fi); pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(s.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(s.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(s.Z, 3)); var soe = featureline.GetStationOffsetElevationByPoint(s); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round((double)soe["Elevation"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); soe = featureline.GetStationOffsetElevationByPoint(e); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round((double)soe["Elevation"], 3)); output.Add(pipe); Utils.Log(string.Format("Pipe {0}", pipe.Id)); } for (int i = 0; i < output.Count - 1; ++i) { Fitting fitting = null; try { fitting = Fitting.Elbow(output[i], output[i + 1]); } catch { } fittings.Add(fitting); } TransactionManager.Instance.TransactionTaskDone(); Utils.Log(string.Format("CableTray.ByPolyCurve completed.", "")); return(new Dictionary <string, object>() { { "CableTray", output }, { "Fittings", fittings } }); }
/// <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(Point basePoint, 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); }
/// <summary> /// Create a Reference Point from a point. /// </summary> /// <param name="pt"></param> /// <returns></returns> public static ReferencePoint ByPoint(Point pt) { if (pt == null) { throw new ArgumentNullException("pt"); } if (!Document.IsFamilyDocument) { throw new Exception("ReferencePoint Elements can only be created in a Family Document"); } return new ReferencePoint(pt.ToXyz()); }
/// <summary> /// Create a box by minimum and maximum points. /// </summary> /// <returns></returns> public static Solid BoxByTwoCorners(Point minimum, Point maximum) { if ((maximum.Z-minimum.Z)<1e-6) { throw new ArgumentException("The minimum and maximum points specify a box with zero height."); } var bottomInput = minimum.ToXyz(); var topInput = maximum.ToXyz(); XYZ top, bottom; if (bottomInput.Z > topInput.Z) { top = bottomInput; bottom = topInput; } else { top = topInput; bottom = bottomInput; } // obtain coordinates of base rectangle var p0 = bottom; var p1 = p0 + new XYZ(top.X - bottom.X, 0, 0); var p2 = p1 + new XYZ(0, top.Y - bottom.Y, 0); var p3 = p2 - new XYZ(top.X - bottom.X, 0, 0); // form edges of base rect var l1 = Autodesk.Revit.DB.Line.CreateBound(p0, p1); var l2 = Autodesk.Revit.DB.Line.CreateBound(p1, p2); var l3 = Autodesk.Revit.DB.Line.CreateBound(p2, p3); var l4 = Autodesk.Revit.DB.Line.CreateBound(p3, p0); // form curve loop from lines of base rect var cl = new Autodesk.Revit.DB.CurveLoop(); cl.Append(l1); cl.Append(l2); cl.Append(l3); cl.Append(l4); // get height of box var height = top.Z - bottom.Z; return new Solid(new List<CurveLoop>{ cl },XYZ.BasisZ,height); }
/// <summary> /// Create a box by center and dimensions. /// </summary> /// <param name="center"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public static Solid BoxByCenterAndDimensions(Point center,double x, double y, double z) { var bottom = center.ToXyz() - new XYZ(x / 2, y / 2, z / 2); var top = center.ToXyz() + new XYZ(x / 2, y / 2, z / 2); return BoxByTwoCorners(bottom.ToPoint(), top.ToPoint()); }
/// <summary> /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType) and it's coordinates in world space /// </summary> /// <param name="familySymbol"></param> /// <param name="point"></param> /// <returns></returns> public static FamilyInstance ByPoint(FamilySymbol familySymbol, Point point) { if (familySymbol == null) { throw new ArgumentNullException("familySymbol"); } if (point == null) { throw new ArgumentNullException("point"); } return new FamilyInstance(familySymbol.InternalFamilySymbol, point.ToXyz()); }
public static Autodesk.Revit.DB.XYZ ToRevitType(this Autodesk.DesignScript.Geometry.Point pt, bool convertUnits = true) { return(pt.ToXyz(convertUnits)); }
/// <summary> /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType), it's coordinates in world space, and the Level /// </summary> /// <param name="familySymbol"></param> /// <param name="point"></param> /// <param name="level"></param> /// <returns></returns> public static FamilyInstance ByPointAndLevel(FamilySymbol familySymbol, Point point, Level level) { if (familySymbol == null) { throw new ArgumentNullException("familySymbol"); } return new FamilyInstance(familySymbol.InternalFamilySymbol, point.ToXyz(), level.InternalLevel); }