Ejemplo n.º 1
0
        public void ByGeometryAndView_ProviedesExpectedConversion()
        {
            // construct the cuboid in meters
            var c0     = Point.ByCoordinates(-1, -1, -1);
            var c1     = Point.ByCoordinates(1, 1, 1);
            var cuboid = Cuboid.ByCorners(c0, c1);

            // set the view into which the ImportInstance will be imported
            var elevation = 100;
            var level     = Revit.Elements.Level.ByElevation(elevation);

            Assert.NotNull(level);
            var view = Revit.Elements.Views.FloorPlanView.ByLevel(level);

            // import
            var import = Revit.Elements.ImportInstance.ByGeometryAndView(cuboid, view);
            // extract geometry
            var importGeometry = import.Geometry().First();

            Assert.IsAssignableFrom(typeof(Autodesk.DesignScript.Geometry.Solid), importGeometry);

            var solidImport = (Autodesk.DesignScript.Geometry.Solid)importGeometry;

            var c2      = Point.ByCoordinates(-1, -1, -1 + elevation);
            var c3      = Point.ByCoordinates(1, 1, 1 + elevation);
            var cuboid2 = Cuboid.ByCorners(c2, c3);

            cuboid2.Volume.ShouldBeApproximately(solidImport.Volume);
            cuboid2.BoundingBox.MinPoint.ShouldBeApproximately(solidImport.BoundingBox.MinPoint);
            cuboid2.BoundingBox.MaxPoint.ShouldBeApproximately(solidImport.BoundingBox.MaxPoint);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This node will obtain the outline of the Viewport title if one is used. This is the label outline.
        /// </summary>
        /// <param name="viewport">Viewport to obtain data from.</param>
        /// <returns name="labelOutline">The label outline of the viewport.</returns>
        /// <search>
        /// viewport, Viewport.LabelOutline, rhythm
        /// </search>
        public static List <Autodesk.DesignScript.Geometry.Curve> LabelOutline(global::Revit.Elements.Element viewport)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;

            //this obtains the label outline
            var labelOutline = internalViewport.GetLabelOutline();
            //create plane that corresponds to sheet plane
            Plane labelPlane   = Plane.ByOriginNormal(labelOutline.MaximumPoint.ToPoint(), Vector.ZAxis());
            var   labelCuboid  = Cuboid.ByCorners(labelOutline.MaximumPoint.ToPoint(), labelOutline.MinimumPoint.ToPoint());
            var   labelSurface = labelCuboid.Intersect(labelPlane);
            List <Autodesk.DesignScript.Geometry.Curve[]> labelCurves = new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (Surface surf in labelSurface)
            {
                labelCurves.Add(surf.PerimeterCurves());
            }
            List <Autodesk.DesignScript.Geometry.Curve> labelSheetCurves = new List <Autodesk.DesignScript.Geometry.Curve>();

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

            return(labelSheetCurves);
        }
 public Cuboid BoxToNative(Box box)
 {
     using (var coordinateSystem = PlaneToNative(box.basePlane).ToCoordinateSystem())
         using (var cLow = DS.Point.ByCartesianCoordinates(coordinateSystem, box.xSize.start ?? 0, box.ySize.start ?? 0, box.zSize.start ?? 0))
             using (var cHigh = DS.Point.ByCartesianCoordinates(coordinateSystem, box.xSize.end ?? 0, box.ySize.end ?? 0, box.zSize.end ?? 0))
                 return(Cuboid.ByCorners(cLow, cHigh));
 }
Ejemplo n.º 4
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);
        }
        public static Cuboid CuboidBySpace(Space space)
        {
            if (space == null)
            {
                return(null);
            }

            Point2d pos2 = new Point2d(space.Position.X, space.Position.Y);
            Point2d dim2 = new Point2d(space.Dimensions.X, space.Dimensions.Y);
            Point3d p0   = new Point3d(pos2 - dim2 / 2.0, space.Position.Z);
            Point3d p1   = new Point3d(pos2 + dim2 / 2.0, space.Position.Z + space.Dimensions.Z);

            return(Cuboid.ByCorners(PointByPoint3d(p0), PointByPoint3d(p1)));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This node will get the bounds of the view in paper space (in feet).
        /// </summary>
        /// <param name="view">The view to get outline from.</param>
        /// <returns name="outline">The bounds of the view in paper space (in feet).</returns>
        /// <search>
        /// view, outline,rhythm
        /// </search>
        public static List <Autodesk.DesignScript.Geometry.Curve[]> GetOutline(global::Revit.Elements.Element view)
        {
            Autodesk.Revit.DB.View internalView = (Autodesk.Revit.DB.View)view.InternalElement;
            var viewBbox   = internalView.Outline;
            var viewCuboid = Cuboid.ByCorners(Point.ByCoordinates(viewBbox.Max.U, viewBbox.Max.V, 0),
                                              Point.ByCoordinates(viewBbox.Min.U, viewBbox.Min.V, 0));
            var viewOutlineSurface = viewCuboid.Intersect(Plane.XY());
            List <Autodesk.DesignScript.Geometry.Curve[]> viewOutlineCurves =
                new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (Surface surf in viewOutlineSurface)
            {
                viewOutlineCurves.Add(surf.PerimeterCurves());
            }

            return(viewOutlineCurves);
        }
Ejemplo n.º 7
0
        private static List <Cuboid> CuboidsFromItems(List <Item> items)
        {
            List <Cuboid> cuboids = new List <Cuboid>();

            foreach (Item item in items)
            {
                Point  lowPoint  = Point.ByCoordinates(Convert.ToDouble(item.CoordX), Convert.ToDouble(item.CoordZ), Convert.ToDouble(item.CoordY));
                Point  highPoint = lowPoint.Add(Vector.ByCoordinates(Convert.ToDouble(item.PackDimX), Convert.ToDouble(item.PackDimZ), Convert.ToDouble(item.PackDimY)));
                Cuboid cuboid    = Cuboid.ByCorners(lowPoint, highPoint);
                cuboids.Add(cuboid);

                //Dispose redundant Geometry
                lowPoint.Dispose();
                highPoint.Dispose();
            }
            return(cuboids);
        }
Ejemplo n.º 8
0
        private void ByBrepNameCategoryMaterial_Cuboid()
        {
            var p1 = Point.ByCoordinates(0.0, 0.0, 0.0);
            var p2 = Point.ByCoordinates(10.0, 10.0, 10.0);
            var p3 = Point.ByCoordinates(2.5, 2.5, 0.0);
            var p4 = Point.ByCoordinates(7.5, 7.5, 10.0);

            // Create a cube
            var c1 = Cuboid.ByCorners(p1, p2);
            // Create another smaller cube
            var c2 = Cuboid.ByCorners(p3, p4);
            // Combine the cubes
            var c3 = c1.Difference(c2);

            c1.Dispose();
            c2.Dispose();

            var mat = DocumentManager.Instance.ElementsOfType <Autodesk.Revit.DB.Material>().First();
            var ds  = DirectShape.ByGeometry(c3, Category.ByName("OST_GenericModel"), Material.ByName(mat.Name), "a cube with a square hole");

            c3.Dispose();

            Assert.NotNull(ds);

            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
            DocumentManager.Regenerate();
            var Revitgeo = ds.InternalElement.get_Geometry(new Autodesk.Revit.DB.Options());

            TransactionManager.Instance.TransactionTaskDone();
            var geo = Revitgeo.First() as Autodesk.Revit.DB.Solid;

            Assert.NotNull(geo);
            // Check number of faces
            Assert.AreEqual(10, geo.Faces.Size);
            // Check number of Edges
            Assert.AreEqual(24, geo.Edges.Size);
            // Check that material is set
            Assert.AreNotEqual(-1, geo.Faces.get_Item(0).MaterialElementId.IntegerValue);

            // Check bounding box to make sure we got unit conversion right
            ds.BoundingBox.MaxPoint.ShouldBeApproximately(10.0, 10.0, 10.0);
        }
Ejemplo n.º 9
0
        public void ByGeometry_ProvidesExpectedConversion()
        {
            // construct the cuboid in meters
            var c0     = Point.ByCoordinates(-1, -1, -1);
            var c1     = Point.ByCoordinates(1, 1, 1);
            var cuboid = Cuboid.ByCorners(c0, c1);

            // import
            var import = Revit.Elements.ImportInstance.ByGeometry(cuboid);

            // extract geometry
            var importGeometry = import.Geometry().First();

            Assert.IsAssignableFrom(typeof(Autodesk.DesignScript.Geometry.Solid), importGeometry);

            var solidImport = (Autodesk.DesignScript.Geometry.Solid)importGeometry;

            cuboid.Volume.ShouldBeApproximately(solidImport.Volume);
            cuboid.BoundingBox.MinPoint.ShouldBeApproximately(solidImport.BoundingBox.MinPoint);
            cuboid.BoundingBox.MaxPoint.ShouldBeApproximately(solidImport.BoundingBox.MaxPoint);
        }
Ejemplo n.º 10
0
        public static Dictionary <string, object> GetCropBox(global::Revit.Elements.Element viewPlan)
        {
            Autodesk.Revit.DB.View internalView = (Autodesk.Revit.DB.View)viewPlan.InternalElement;
            var viewBbox           = internalView.CropBox;
            var viewCuboid         = Cuboid.ByCorners(viewBbox.Max.ToPoint(), viewBbox.Min.ToPoint());
            var viewOutlineSurface = viewCuboid.Intersect(internalView.SketchPlane.GetPlane().ToPlane());
            List <Autodesk.DesignScript.Geometry.Curve[]> viewOutlineCurves =
                new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (Surface surf in viewOutlineSurface)
            {
                viewOutlineCurves.Add(surf.PerimeterCurves());
            }
            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "cropBox", viewBbox },
                { "cropBoxCurves", viewOutlineCurves }
            };

            return(outInfo);
        }