public void Arc_Basic() { var o = new Autodesk.Revit.DB.XYZ(5,2,3); var x = (new Autodesk.Revit.DB.XYZ(0, 0, 1)).Normalize(); var y = (new Autodesk.Revit.DB.XYZ(0,-1, 0)).Normalize(); var r = 10; var sp = 0.1; var ep = 2.5; var re = Autodesk.Revit.DB.Arc.Create(o, r, sp, ep, x, y); var pc = re.ToProtoType(); Assert.NotNull(pc); Assert.IsAssignableFrom<Autodesk.DesignScript.Geometry.Arc>(pc); var pa = (Autodesk.DesignScript.Geometry.Arc)pc; (pa.SweepAngle * Math.PI / 180).ShouldBeApproximately(ep - sp); pa.StartPoint.ShouldBeApproximately(re.GetEndPoint(0)); pa.EndPoint.ShouldBeApproximately(re.GetEndPoint(1)); //var tessPts = re.Tessellate(); //// assert the tesselation is very close to original curve //foreach (var pt in tessPts) //{ // var closestPt = pa.ClosestPointTo(pt.ToPoint()); // Assert.Less(closestPt.DistanceTo(pt.ToPoint()), 1e-6); //} }
public void EllipseArc_Basic() { var c = new Autodesk.Revit.DB.XYZ(5, 2, 3); var rx = 10; var ry = 2.5; var x = new Autodesk.Revit.DB.XYZ(1, 0, 0); var y = new Autodesk.Revit.DB.XYZ(0, 1, 0); var sp = Math.PI/4; var ep = 3 * Math.PI / 4; var re = Autodesk.Revit.DB.Ellipse.Create(c, rx, ry, x, y, sp, ep); re.MakeBound(sp, ep); var pc = re.ToProtoType(); Assert.NotNull(pc); Assert.IsAssignableFrom<Autodesk.DesignScript.Geometry.EllipseArc>(pc); var pa = (Autodesk.DesignScript.Geometry.EllipseArc)pc; pa.StartAngle.ToRadians().ShouldBeApproximately(sp); (pa.SweepAngle.ToRadians()).ShouldBeApproximately(ep - sp); pa.StartPoint.ShouldBeApproximately(re.GetEndPoint(0)); pa.EndPoint.ShouldBeApproximately(re.GetEndPoint(1)); pa.MajorAxis.Length.ShouldBeApproximately(rx); pa.MinorAxis.Length.ShouldBeApproximately(ry); pa.CenterPoint.ShouldBeApproximately(re.Center); var tessPts = re.Tessellate(); // assert the tesselation is very close to original curve foreach (var pt in tessPts) { var closestPt = pa.GetClosestPoint(pt.ToPoint()); Assert.Less(closestPt.DistanceTo(pt.ToPoint()), 1e-6); } }
public void DoBinding(WallInfo wallInfo, Autodesk.Revit.DB.DisplayUnit?unitSystem, double beamLength = 0) { familyNameLabel.Visibility = System.Windows.Visibility.Visible; familyName.Visibility = System.Windows.Visibility.Visible; typeNameLabel.Visibility = System.Windows.Visibility.Visible; typeName.Visibility = System.Windows.Visibility.Visible; familyName.Content = wallInfo.FamilyName; typeName.Content = wallInfo.TypeName; wallViewer.Children.Clear(); double scale = 1.2; double actualWidth = wallViewer.MinWidth; double actualHeight = wallViewer.MinHeight; if (wallViewer.ActualWidth > 0) { actualWidth = wallViewer.ActualWidth; } if (wallViewer.ActualHeight > 0) { actualHeight = wallViewer.ActualHeight; } double horizontalMargin = actualWidth / 8; double verticalMargin = actualHeight / 6; double width = actualWidth - 2 * horizontalMargin; double height = actualHeight - 2 * verticalMargin; horizontalMargin += (width - width * scale) / 2.0; verticalMargin += (height - height * scale) / 2.0; double horizontalShift = horizontalMargin; double verticalShift = verticalMargin; XYZ xyz_min = wallInfo.Contour.GetMinimumBoundary(); XYZ xyz_max = wallInfo.Contour.GetMaximumBoundary(); width = Math.Abs(xyz_max.X - xyz_min.X); height = Math.Abs(xyz_max.Y - xyz_min.Y); double stretchCoeff = 0; if (height > width) { stretchCoeff = (actualHeight - 2 * verticalMargin) / height; horizontalShift += ((actualWidth - 2 * horizontalMargin) - (width * stretchCoeff)) / 2.0; } else { stretchCoeff = (actualWidth - 2 * horizontalMargin) / width; verticalShift += ((actualHeight - 2 * verticalMargin) - (height * stretchCoeff)) / 2; } if (xyz_min.X < 0) { horizontalShift -= stretchCoeff * xyz_min.X; } if (xyz_min.Y < 0) { verticalShift -= stretchCoeff * xyz_min.Y; } System.Windows.Shapes.Shape contour = null; List <System.Windows.Shapes.Shape> openings = new List <System.Windows.Shapes.Shape>(); Polygon polygon = null; PointCollection points = null; if (wallInfo.Contour != null && wallInfo.Contour.Points.Count > 2) { polygon = new Polygon(); points = new PointCollection(); foreach (XYZ xyz in wallInfo.Contour.Points) { points.Add(new Point(xyz.X * stretchCoeff, xyz.Y * stretchCoeff)); } polygon.Points = points; polygon.Fill = Brushes.LightSlateGray; polygon.Stretch = Stretch.None; polygon.Stroke = Brushes.Black; polygon.StrokeThickness = 1; contour = polygon; } foreach (Autodesk.Revit.DB.CodeChecking.Engineering.Shape opening in wallInfo.Openings) { polygon = new Polygon(); points = new PointCollection(); foreach (XYZ xyz in opening.Points) { points.Add(new Point(xyz.X * stretchCoeff, xyz.Y * stretchCoeff)); } polygon.Points = points; polygon.Fill = Brushes.White; polygon.Stretch = Stretch.None; polygon.Stroke = Brushes.Black; polygon.StrokeThickness = 1; openings.Add(polygon); } if (contour != null) { Canvas.SetLeft(contour, horizontalShift); Canvas.SetTop(contour, verticalShift); wallViewer.Children.Add(contour); } foreach (System.Windows.Shapes.Shape opening in openings) { Canvas.SetLeft(opening, horizontalShift); Canvas.SetTop(opening, verticalShift); wallViewer.Children.Add(opening); } double viewerWidth, viewerHeight; wallViewer.GetViewerWidthAndHeight(out viewerWidth, out viewerHeight); double dimHeight = Math.Abs(xyz_max.Y - xyz_min.Y); double dimWidth = Math.Abs(xyz_max.X - xyz_min.X); if (viewerWidth / 2.0 > horizontalShift) { horizontalShift += dimWidth * stretchCoeff; } double offset = 0.0; if (viewerHeight / 2.0 > verticalShift) { offset = dimHeight * stretchCoeff; } else { verticalShift -= dimHeight * stretchCoeff; } double x = horizontalShift + 10; Point start = new Point(x, verticalShift); Point end = new Point(x, start.Y + dimHeight * stretchCoeff); CreateDimensionLine(dimHeight, start, end, stretchCoeff, unitSystem); double y = verticalShift + dimHeight * stretchCoeff + 10; start = new Point(horizontalShift - (dimWidth * stretchCoeff), y); end = new Point(start.X + dimWidth * stretchCoeff, y); CreateDimensionLine(dimWidth, start, end, stretchCoeff, unitSystem); }
public static void ShouldBeApproximately(this Autodesk.Revit.DB.XYZ p0, Point p1, double epsilon = Epsilon) { p0.ShouldBeApproximately(p1.X, p1.Y, p1.Z, epsilon); }
/// <summary> /// The Z value of a Revit XYZ point. /// </summary> /// <param name="XYZ">A Revit XYZ point</param> /// <returns name="Z">A double</returns> public static double Z(revitXYZ XYZ) { return(XYZ.Z); }
/// <summary> /// The X value of a Revit XYZ point. /// </summary> /// <param name="XYZ">A Revit XYZ point</param> /// <returns name="X">A double</returns> public static double X(revitXYZ XYZ) { return(XYZ.X); }
/// <summary> /// Interface to write one section include normal and vertex. /// </summary> /// <param name="normal">Facet normal.</param> /// <param name="vertexArr">Vertex array.</param> /// <returns>True if succeeded, false if failed.</returns> public abstract bool WriteSection(Autodesk.Revit.DB.XYZ normal, double[] vertexArr);
/// <summary> /// Sort a list of curves to make them correctly /// ordered and oriented to form a closed loop. /// From Jeremy Tammik /// </summary> public static void SortCurvesContiguous(IList <Autodesk.Revit.DB.Curve> curves) { int n = curves.Count; // Walk through each curve (after the first) // to match up the curves in order for (int i = 0; i < n; ++i) { Autodesk.Revit.DB.Curve curve = curves[i]; Autodesk.Revit.DB.XYZ endPoint = curve.GetEndPoint(1); Autodesk.Revit.DB.XYZ p; // Find curve with start point = end point bool found = (i + 1 >= n); for (int j = i + 1; j < n; ++j) { p = curves[j].GetEndPoint(0); // If there is a match end->start, // this is the next curve if (_sixteenth > p.DistanceTo(endPoint)) { if (i + 1 != j) { Autodesk.Revit.DB.Curve tmp = curves[i + 1]; curves[i + 1] = curves[j]; curves[j] = tmp; } found = true; break; } p = curves[j].GetEndPoint(1); // If there is a match end->end, // reverse the next curve if (_sixteenth > p.DistanceTo(endPoint)) { if (i + 1 == j) { curves[i + 1] = CreateReversedCurve(curves[j]); } else { Autodesk.Revit.DB.Curve tmp = curves[i + 1]; curves[i + 1] = CreateReversedCurve(curves[j]); curves[j] = tmp; } found = true; break; } } if (!found) { throw new Exception("SortCurvesContiguous:" + " non-contiguous input curves"); } } }
internal FamilyInstances(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.Element host, Autodesk.Revit.DB.Level level) { SafeInit(() => InitFamilyInstance(fs, point, host, level)); }
internal FamilyInstances(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.View view) { SafeInit(() => InitFamilyInstance(fs, point, view)); }
private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ referenceDir) { //Phase 1 - Check to see if the object exists and should be rebound var doc = DocumentManager.Instance.CurrentDBDocument; var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(doc); //There was a point, rebind to that, and adjust its position if (oldFam != null) { InternalSetFamilyInstance(oldFam); InternalSetFamilySymbol(fs); return; } //Phase 2- There was no existing point, create one TransactionManager.Instance.EnsureInTransaction(doc); //If the symbol is not active, then activate it if (!fs.IsActive) { fs.Activate(); } var fi = doc.Create.NewFamilyInstance(reference, point, referenceDir, fs); InternalSetFamilyInstance(fi); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Internal constructor - creates a single StructuralFraming instance /// </summary> internal StructuralFraming(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol) { SafeInit(() => InitStructuralFraming(curve, upVector, level, structuralType, symbol)); }
private static FamilyInstanceCreationData GetCreationData(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol) { //calculate the desired rotation //we do this by finding the angle between the z axis //and vector between the start of the beam and the target point //both projected onto the start plane of the beam. var zAxis = new Autodesk.Revit.DB.XYZ(0, 0, 1); var yAxis = new Autodesk.Revit.DB.XYZ(0, 1, 0); //flatten the beam line onto the XZ plane //using the start's z coordinate var start = curve.GetEndPoint(0); var end = curve.GetEndPoint(1); var newEnd = new Autodesk.Revit.DB.XYZ(end.X, end.Y, start.Z); //drop end point to plane //catch the case where the end is directly above //the start, creating a normal with zero length //in that case, use the Z axis var planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize(); var gamma = upVector.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal); return(new FamilyInstanceCreationData(curve, symbol, level, structuralType) { RotateAngle = gamma }); }
public Autodesk.Revit.DB.XYZ readXYZ() { double x = readDouble(); double y = readDouble(); double z = readDouble(); Autodesk.Revit.DB.XYZ c = new Autodesk.Revit.DB.XYZ(x, y, z); return c; }
private void AddShapesToRender(SectionsInfo sectionsInfo, Canvas sectionViewer, double scale) { sectionViewer.Children.Clear(); double actualWidth = sectionViewer.Width; double actualHeight = sectionViewer.MinHeight; if (sectionViewer.ActualWidth > 0) { actualWidth = sectionViewer.ActualWidth; } if (sectionViewer.ActualHeight > 0) { actualHeight = sectionViewer.ActualHeight; } double horizontalMargin = actualWidth / 6; double verticalMargin = actualHeight / 6; double width = actualWidth - 2 * horizontalMargin; double height = actualHeight - 2 * verticalMargin; horizontalMargin += (width - width * scale) / 2.0; verticalMargin += (height - height * scale) / 2.0; double horizontalShift = horizontalMargin; double verticalShift = verticalMargin; XYZ xyz_min = sectionsInfo.GetMinimumBoundary(); XYZ xyz_max = sectionsInfo.GetMaximumBoundary(); width = Math.Abs(xyz_max.X - xyz_min.X); height = Math.Abs(xyz_max.Y - xyz_min.Y); double stretchCoeff = 0; if (height > width) { stretchCoeff = (actualHeight - 2 * verticalMargin) / height; horizontalShift += (height - width) * stretchCoeff / 2; } else { stretchCoeff = (actualWidth - 2 * horizontalMargin) / width; verticalShift += (width - height) * stretchCoeff / 2; } if (xyz_min.X < 0) { horizontalShift -= stretchCoeff * xyz_min.X; } if (xyz_min.Y < 0) { verticalShift -= stretchCoeff * xyz_min.Y; } List <System.Windows.Shapes.Shape> contours = new List <System.Windows.Shapes.Shape>(); List <System.Windows.Shapes.Shape> holes = new List <System.Windows.Shapes.Shape>(); XYZ maxB = sectionsInfo.GetMaximumBoundary(); XYZ minB = sectionsInfo.GetMinimumBoundary(); foreach (Autodesk.Revit.DB.CodeChecking.Engineering.Section section in sectionsInfo.Sections) { Polygon polygon = new Polygon(); PointCollection points = new PointCollection(); foreach (XYZ xyz in section.Contour.Points) { points.Add(new Point(xyz.X * stretchCoeff, (minB.Y + (maxB.Y - xyz.Y)) * stretchCoeff)); } polygon.Points = points; polygon.Fill = Brushes.LightSteelBlue; polygon.Stretch = Stretch.None; polygon.Stroke = Brushes.Black; polygon.StrokeThickness = 1; contours.Add(polygon); foreach (Autodesk.Revit.DB.CodeChecking.Engineering.Shape shape in section.Holes) { polygon = new Polygon(); points = new PointCollection(); foreach (XYZ xyz in shape.Points) { points.Add(new Point(xyz.X * stretchCoeff, (minB.Y + (maxB.Y - xyz.Y)) * stretchCoeff)); } polygon.Points = points; polygon.Fill = Brushes.White; polygon.Stretch = Stretch.None; polygon.Stroke = Brushes.Black; polygon.StrokeThickness = 1; holes.Add(polygon); } } if (contours.Count() < 1) { horizontalShift = (actualWidth - defaultShapeToRender.Width) / 2; verticalShift = (actualHeight - defaultShapeToRender.Height) / 2; Canvas.SetLeft(defaultShapeToRender, horizontalShift); Canvas.SetTop(defaultShapeToRender, verticalShift); sectionViewer.Children.Add(defaultShapeToRender); return; } foreach (System.Windows.Shapes.Shape contour in contours) { Canvas.SetLeft(contour, horizontalShift); Canvas.SetTop(contour, verticalShift); sectionViewer.Children.Add(contour); } foreach (System.Windows.Shapes.Shape hole in holes) { Canvas.SetLeft(hole, horizontalShift); Canvas.SetTop(hole, verticalShift); sectionViewer.Children.Add(hole); } }
internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ location, Autodesk.Revit.DB.XYZ referenceDirection) { SafeInit(() => InitFamilyInstance(fs, reference, location, referenceDirection)); }
private static Autodesk.Revit.DB.Connector FindClosest(IEnumerable connectors, Autodesk.Revit.DB.XYZ pt) { Autodesk.Revit.DB.Connector c = null; var closest = 999999.0; foreach (Autodesk.Revit.DB.Connector conn in connectors) { var distance = conn.Origin.DistanceTo(pt); if (!(distance <= closest)) { continue; } c = conn; closest = distance; } return(c); }
internal FamilyInstances(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ referenceDir) { SafeInit(() => InitFamilyInstance(fs, point, reference, referenceDir)); }
public Xyz(string label, Autodesk.Revit.DB.XYZ val) : base(label) { m_val = val; }
public static bool ShouldBeApproximately(this Autodesk.Revit.DB.XYZ p0, Point p1, double epsilon = Epsilon) { return(p0.ShouldBeApproximately(p1.X, p1.Y, p1.Z)); }
/// <summary> /// Converts a Revit XYZ object into a Dynamo Vector /// </summary> /// <param name="XYZ">A Autodesk.Revit.DB.XYZ object</param> /// <returns name="Vector">Returns a dynamo Vector</returns> public static dynaVector ConvertXYZToVector(revitXYZ XYZ) { return(dynaVector.ByCoordinates(XYZ.X, XYZ.Y, XYZ.Z)); }
public static bool ShouldBeApproximately(this Autodesk.Revit.DB.XYZ p0, double x, double y, double z, double epsilon = Epsilon) { return(ShouldBeApproximately(p0.X, p0.Y, p0.Z, x, y, z, epsilon)); }
/// <summary> /// The Y value of a Revit XYZ point. /// </summary> /// <param name="XYZ">A Revit XYZ point</param> /// <returns name="Y">A double</returns> public static double Y(revitXYZ XYZ) { return(XYZ.Y); }
public static void AssertShouldBeApproximately(this Autodesk.Revit.DB.XYZ p0, Autodesk.Revit.DB.XYZ p1, double epsilon = Epsilon) { p0.AssertShouldBeApproximately(p1.X, p1.Y, p1.Z); }
Xyz(string label, Autodesk.Revit.DB.XYZ val) : base(label) { m_val = val; }
/// <summary> /// Creates a new ViewOrientation3D given a EyePosition, UpDirection and ForwardDirection /// </summary> /// <param name="EyePosition">The coordinates for the EyePosition</param> /// <param name="UpDirection">A vector pointing to the Up direciton of the view (top of the screen)</param> /// <param name="ForwardDirection">A vector pointing from the camera towards the screen</param> /// <returns></returns> public static revitViewOrient ByEyeUpForwardDirections(revitXYZ EyePosition, revitXYZ UpDirection, revitXYZ ForwardDirection) { return(new revitViewOrient(EyePosition, UpDirection, ForwardDirection)); }
public void Line_Basic() { var s = new Autodesk.Revit.DB.XYZ(5, 2, 3); var e = new Autodesk.Revit.DB.XYZ(10,20,1); var rl = Autodesk.Revit.DB.Line.CreateBound(s, e); var pc = rl.ToProtoType(); Assert.NotNull(pc); Assert.IsAssignableFrom<Autodesk.DesignScript.Geometry.Line>(pc); var pl = (Autodesk.DesignScript.Geometry.Line) pc; Assert.AreEqual(rl.GetEndPoint(0).ToPoint(), pl.StartPoint ); Assert.AreEqual(rl.GetEndPoint(1).ToPoint(), pl.EndPoint ); }
private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ location, Autodesk.Revit.DB.XYZ referenceDirection) { //Phase 1 - Check to see if the object exists and should be rebound var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document); //There was an existing family instance, rebind to that, and adjust its position if (oldFam != null && oldFam.HostFace.ElementId == reference.ElementId) { InternalSetFamilyInstance(oldFam); InternalSetFamilySymbol(fs); InternalSetPosition(location); return; } //Phase 2- There was no existing point, create one TransactionManager.Instance.EnsureInTransaction(Document); //If the symbol is not active, then activate it if (!fs.IsActive) { fs.Activate(); } var fi = Document.IsFamilyDocument ? Document.FamilyCreate.NewFamilyInstance(reference, location, referenceDirection, fs) : Document.Create.NewFamilyInstance(reference, location, referenceDirection, fs); InternalSetFamilyInstance(fi); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Internal constructor for a FamilyInstance /// </summary> internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ pos) { SafeInit(() => InitFamilyInstance(fs, pos)); }
public void Ellipse_Basic() { var c = new Autodesk.Revit.DB.XYZ(5, 2, 3); var rx = 10; var ry = 2.5; var x = new Autodesk.Revit.DB.XYZ(1,0,0); var y = new Autodesk.Revit.DB.XYZ(0,1,0); var sp = 0; var ep = Math.PI * 2; var re = Autodesk.Revit.DB.Ellipse.Create(c, rx, ry, x, y, sp, ep); re.MakeBound(sp, ep); var pc = re.ToProtoType(false); Assert.NotNull(pc); Assert.IsAssignableFrom<Autodesk.DesignScript.Geometry.Ellipse>(pc); var pa = (Autodesk.DesignScript.Geometry.Ellipse) pc; // no elliptical arcs yet //(pa.SweepAngle * Math.PI / 180).AssertShouldBeApproximately(ep - sp); pa.StartPoint.ShouldBeApproximately(re.GetEndPoint(0)); pa.EndPoint.ShouldBeApproximately(re.GetEndPoint(1)); pa.MajorAxis.Length.ShouldBeApproximately(rx); pa.MinorAxis.Length.ShouldBeApproximately(ry); pa.CenterPoint.ShouldBeApproximately(re.Center); //var tessPts = re.Tessellate(); //// assert the tesselation is very close to original curve //foreach (var pt in tessPts) //{ // var closestPt = pa.ClosestPointTo(pt.ToPoint(false)); // Assert.Less(closestPt.DistanceTo(pt.ToPoint(false)), 1e-6); //} }