コード例 #1
0
        public void NurbsCurve()
        {
            HostFactory.Instance.StartUp();

            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(1, 0, 0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(3, 0, 0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(10, 0, 0)
            };

            var spline = Autodesk.DesignScript.Geometry.NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);
            Assert.AreEqual(3, spline.Degree);
            var eval0 = spline.PointAtParameter(0);
            var eval1 = spline.PointAtParameter(1);

            var expectedPoint0 = Point.ByCoordinates(0, 0, 0);
            var expectedPoint1 = Point.ByCoordinates(10, 0, 0);

            Assert.AreEqual(0, expectedPoint0.DistanceTo(eval0), 1e-6);
            Assert.AreEqual(0, expectedPoint1.DistanceTo(eval1), 1e-6);

            var closestPoint0 = spline.GetClosestPoint(expectedPoint0);

            Assert.AreEqual(0, expectedPoint0.DistanceTo(closestPoint0), 1e-6);

            HostFactory.Instance.ShutDown();
        }
コード例 #2
0
        public void ByPointsOnCurve_ValidInput()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(1, 0, 0),
                Point.ByCoordinates(3, 0, 0),
                Point.ByCoordinates(10, 0, 0),
                Point.ByCoordinates(12, 0, 0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);

            Assert.NotNull(modCurve);

            // obtain the family from the document
            var fs = FamilySymbol.ByName("3PointAC");

            // build the AC
            var parms = new double[]
            {
                0, 0.5, 1
            };

            var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve.ElementCurveReference, fs);

            Assert.NotNull(ac);
        }
コード例 #3
0
        public void ByPointsOnCurve_ValidInput()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0,0,0),
                Point.ByCoordinates(1,0,0),
                Point.ByCoordinates(3,0,0),
                Point.ByCoordinates(10,0,0),
                Point.ByCoordinates(12,0,0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);
            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);
            Assert.NotNull(modCurve);

            // obtain the family from the document
            var fs = FamilySymbol.ByName("3PointAC");

            // build the AC
            var parms = new double[]
            {
                0, 0.5, 1
            };

            var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve.ElementCurveReference, fs);
            Assert.NotNull(ac);

        }
コード例 #4
0
ファイル: GeometryTests.cs プロジェクト: TheChosen0ne/Dynamo
        public void NurbsCurve()
        {
            HostFactory.Instance.StartUp();

            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(0,0,0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(1,0,0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(3,0,0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(10,0,0)
            };

            var spline = Autodesk.DesignScript.Geometry.NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);
            Assert.AreEqual(3, spline.Degree);
            var eval0 = spline.PointAtParameter(0);
            var eval1 = spline.PointAtParameter(1);

            var expectedPoint0 = Point.ByCoordinates(0, 0, 0);
            var expectedPoint1 = Point.ByCoordinates(10, 0, 0);

            Assert.AreEqual(0, expectedPoint0.DistanceTo(eval0), 1e-6);
            Assert.AreEqual(0, expectedPoint1.DistanceTo(eval1), 1e-6);

            var closestPoint0 = spline.GetClosestPoint(expectedPoint0);
            Assert.AreEqual(0, expectedPoint0.DistanceTo(closestPoint0), 1e-6);

            HostFactory.Instance.ShutDown();
        }
コード例 #5
0
        public static Dictionary <string, object> LocationData(global::Revit.Elements.Element viewport)
        {
            //obtain the element id from the sheet
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;
            //obtain the box center of the viewport
            var boxCenterInternal = internalViewport.GetBoxCenter().ToPoint();

            //Construct new point at sheet elevation of 0
            Autodesk.DesignScript.Geometry.Point boxCenter =
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(boxCenterInternal.X, boxCenterInternal.Y, 0);
            //this obtains the box outline
            var boxOutline = internalViewport.GetBoxOutline();
            //temporary geometry
            var bBox      = BoundingBox.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint());
            var boxCuboid = Cuboid.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint());
            //create plane that corresponds to sheet plane
            Plane boxPlane   = Plane.ByOriginNormal(boxOutline.MaximumPoint.ToPoint(), Vector.ZAxis());
            var   boxSurface = boxCuboid.Intersect(boxPlane);
            List <Autodesk.DesignScript.Geometry.Curve[]> boxCurves = new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (var geometry in boxSurface)
            {
                var surf = (Surface)geometry;
                boxCurves.Add(surf.PerimeterCurves());
                surf.Dispose();
            }
            List <Autodesk.DesignScript.Geometry.Curve> boxSheetCurves = new List <Autodesk.DesignScript.Geometry.Curve>();

            //pull the curves onto a plane at 0,0,0
            foreach (Autodesk.DesignScript.Geometry.Curve[] curve in boxCurves)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve c in curve)
                {
                    boxSheetCurves.Add(c.PullOntoPlane(Plane.XY()));
                    c.Dispose();
                }
            }

            //dispose of temporary geometries
            boxCuboid.Dispose();
            boxPlane.Dispose();
            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "bBox", bBox },
                { "boxCenter", boxCenter },
                { "boxOutline", boxSheetCurves }
            };

            return(outInfo);
        }
コード例 #6
0
        public void ByPointsOnCurve_ProducesValidAdaptiveComponentAndLocations()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(1, 0, 0),
                Point.ByCoordinates(3, 0, 0),
                Point.ByCoordinates(10, 0, 0),
                Point.ByCoordinates(12, 0, 0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);

            Assert.NotNull(modCurve);

            // obtain the family from the document
            var ft = FamilyType.ByName("3PointAC");

            // build the AC
            var parms = new double[]
            {
                0, 0.5, 1
            };

            var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve.ElementCurveReference, ft);

            // with unit conversion
            foreach (var pt in ac.Locations)
            {
                spline.DistanceTo(pt).ShouldBeApproximately(0);
            }

            // without unit conversion
            var unconvertedPoints = GetInternalPoints((FamilyInstance)ac.InternalElement);

            foreach (var pt in unconvertedPoints)
            {
                spline.DistanceTo(pt.ToPoint()).ShouldBeApproximately(0);
            }

            Assert.NotNull(ac);
        }
コード例 #7
0
        /// <summary>
        /// Create a Revit Grid Element in a project between two end points
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static Grid ByStartPointEndPoint(Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end)
        {
            if (Document.IsFamilyDocument)
            {
                throw new Exception("A Grid Element can only be created in a Revit Project");
            }

            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            if (end == null)
            {
                throw new ArgumentNullException("end");
            }

            var line = Autodesk.Revit.DB.Line.CreateBound(start.ToXyz(), end.ToXyz());

            return(new Grid(line));
        }
コード例 #8
0
        public static List <global::Revit.Elements.Element> GetAreaAtPoint(Autodesk.DesignScript.Geometry.Point point, double areaHeight = 10.0)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;

            List <global::Revit.Elements.Element> areaLocations = new List <global::Revit.Elements.Element>();

            //collect the areas to do some cool stuff
            FilteredElementCollector          areaColl = new FilteredElementCollector(doc);
            IList <Autodesk.Revit.DB.Element> areas    = areaColl.OfCategory(BuiltInCategory.OST_Areas).ToElements();

            foreach (var area in areas)
            {
                Solid solid = Rhythm.Revit.Elements.Areas.Solid(area.ToDSType(true), areaHeight);
                if (solid.DoesIntersect(point))
                {
                    areaLocations.Add(area.ToDSType(true));
                }
                solid.Dispose();
            }
            return(areaLocations);
        }
コード例 #9
0
        public void ByPointsOnCurve_ProducesValidAdaptiveComponentAndLocations()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0,0,0),
                Point.ByCoordinates(1,0,0),
                Point.ByCoordinates(3,0,0),
                Point.ByCoordinates(10,0,0),
                Point.ByCoordinates(12,0,0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);
            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);
            Assert.NotNull(modCurve);

            // obtain the family from the document
            var fs = FamilySymbol.ByName("3PointAC");

            // build the AC
            var parms = new double[]
            {
                0, 0.5, 1
            };

            var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve.ElementCurveReference, fs);

            // with unit conversion
            foreach (var pt in ac.Locations)
                spline.DistanceTo(pt).ShouldBeApproximately(0);

            // without unit conversion
            var unconvertedPoints = GetInternalPoints((FamilyInstance)ac.InternalElement);

            foreach (var pt in unconvertedPoints)
            {
                spline.DistanceTo(pt.ToPoint()).ShouldBeApproximately(0);
            }

            Assert.NotNull(ac);

        }
コード例 #10
0
        /// <summary>
        /// This node will place the given view on the given sheet, if possible. For floor plan views: They cannot be on any other sheets. Now supports schedules!
        /// </summary>
        /// <param name="sheet">The sheet to place views on.</param>
        /// <param name="view">The view to place.</param>
        /// <param name="location">The location of the view.</param>
        /// <returns name="Result">The result</returns>
        /// <search>
        /// viewport, addview,rhythm
        /// </search>
        public static global::Revit.Elements.Element Create(global::Revit.Elements.Views.Sheet sheet, global::Revit.Elements.Element view, Autodesk.DesignScript.Geometry.Point location)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            ElementId sheetId = new ElementId(sheet.Id);

            global::Revit.Elements.Element result = null;

            if (view.InternalElement.ToString() == "Autodesk.Revit.DB.ViewSchedule")
            {
                //obtain the element id from the view
                ElementId viewId = new ElementId(view.Id);
                //chane the dynamo point to a revit point
                var revitPoint = location.ToRevitType(true);
                //start the transaction to place views
                TransactionManager.Instance.EnsureInTransaction(doc);
                result = Autodesk.Revit.DB.ScheduleSheetInstance.Create(doc, sheetId, viewId, revitPoint).ToDSType(true);
                TransactionManager.Instance.TransactionTaskDone();
            }
            else
            {
                //obtain the element id from the view
                ElementId viewId = new ElementId(view.Id);
                //chane the dynamo point to a revit point
                var revitPoint = location.ToRevitType(true);
                //start the transaction to place views
                TransactionManager.Instance.EnsureInTransaction(doc);
                result = Autodesk.Revit.DB.Viewport.Create(doc, sheetId, viewId, revitPoint).ToDSType(true);
                TransactionManager.Instance.TransactionTaskDone();
            }

            return(result);
        }
コード例 #11
0
        public static object Create(global::Revit.Elements.Views.Sheet sheet, global::Revit.Elements.Element view, Autodesk.DesignScript.Geometry.Point location)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            ElementId sheetId = new ElementId(sheet.Id);

            Autodesk.Revit.DB.Element result = null;
            //change the dynamo point to a revit point
            var revitPoint = location.ToRevitType(true);
            //obtain the element id from the view
            ElementId viewId = new ElementId(view.Id);



            try
            {
                //start the transaction to place views
                TransactionManager.Instance.EnsureInTransaction(doc);
                if (view.InternalElement.ToString() == "Autodesk.Revit.DB.ViewSchedule")
                {
                    result = Autodesk.Revit.DB.ScheduleSheetInstance.Create(doc, sheetId, viewId, revitPoint);
                }
                else
                {
                    result = Autodesk.Revit.DB.Viewport.Create(doc, sheetId, viewId, revitPoint);
                }

                TransactionManager.Instance.TransactionTaskDone();

                return(result.ToDSType(true));
            }
            catch (Exception e)
            {
                if (!Autodesk.Revit.DB.Viewport.CanAddViewToSheet(doc, sheetId, viewId))
                {
                    return("Error: View " + view.Id + " cannot be added to the sheet because it is already on another sheet.");
                }
                if (result == null)
                {
                    return("Error: View " + view.Id + " cannot be added to the sheet because it is empty.");
                }

                return("Error: View " + view.Id + e.Message);
            }
        }