Ejemplo n.º 1
0
        public void ByTextSketchPlaneAndPosition_ValidArgs()
        {
            var origin = Point.ByCoordinates(1, 2, 3);
            var normal = Vector.ByCoordinates(0, 0, 1);
            var plane  = Plane.ByOriginNormal(origin, normal);
            var text   = "Snickers - why wait?";

            var name          = "Model Text 1";
            var modelTextType = ModelTextType.ByName(name);

            var sketchPlane = SketchPlane.ByPlane(plane);
            var depth       = 1;
            var x           = 10;
            var y           = 3;
            var mt          = ModelText.ByTextSketchPlaneAndPosition(text, sketchPlane, x, y, depth, modelTextType);

            Assert.NotNull(mt);
            Assert.NotNull(mt.InternalElement);
            Assert.IsTrue(DocumentManager.Instance.ElementExistsInDocument(
                              new ElementUUID(mt.InternalElement.UniqueId)));

            mt.Depth.ShouldBeApproximately(depth);

            // with unit conversion
            InternalDepth(mt).ShouldBeApproximately(depth * UnitConverter.DynamoToHostFactor);

            var expectedInternalLoc =
                origin.InHostUnits()
                .Add(Vector.XAxis().Scale(x * UnitConverter.DynamoToHostFactor))
                .Add(Vector.YAxis().Scale(y * UnitConverter.DynamoToHostFactor));

            InternalLocation(mt).ShouldBeApproximately(expectedInternalLoc);
        }
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);
        }
Ejemplo n.º 3
0
        private Plane Offset(Vector offset)
        {
            IPointEntity origin    = Origin.PointEntity;
            IPointEntity newOrigin = origin.Add(offset);
            Plane        plane     = Plane.ByOriginNormal(newOrigin.ToPoint(false, null), Normal, Size);

            plane.Context = this;
            return(plane);
        }
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);
        }
Ejemplo n.º 5
0
        public void ByTextSketchPlaneAndPosition_BadArgs()
        {
            var origin = Point.ByCoordinates(1, 2, 3);
            var normal = Vector.ByCoordinates(0, 0, 1);
            var plane  = Plane.ByOriginNormal(origin, normal);
            var text   = "Snickers - why wait?";

            var name          = "Model Text 1";
            var modelTextType = ModelTextType.ByName(name);

            var sketchPlane = SketchPlane.ByPlane(plane);

            Assert.Throws(typeof(System.ArgumentNullException), () => ModelText.ByTextSketchPlaneAndPosition(null, sketchPlane, 0, 0, 1, modelTextType));
            Assert.Throws(typeof(System.ArgumentNullException), () => ModelText.ByTextSketchPlaneAndPosition(text, null, 0, 0, 1, modelTextType));
            Assert.Throws(typeof(System.ArgumentNullException), () => ModelText.ByTextSketchPlaneAndPosition(text, sketchPlane, 0, 0, 1, null));
        }
Ejemplo n.º 6
0
        private static Plane FromCoordinateSystem(CoordinateSystem cs)
        {
            if (null == cs)
            {
                return(null);
            }

            Plane plane = Plane.ByOriginNormal(cs.Origin, cs.ZAxis);

            if (null == plane)
            {
                return(null);
            }

            plane.ContextCoordinateSystem = cs;
            return(plane);
        }
Ejemplo n.º 7
0
        internal override Geometry TransformBy(ICoordinateSystemEntity csEntity)
        {
            //Let the default code handle orthogonal transform.
            if (csEntity.IsScaledOrtho())
            {
                return(base.TransformBy(csEntity));
            }

            using (IPointEntity origin = Origin.PointEntity.CopyAndTransform(CoordinateSystem.WCS.CSEntity, csEntity) as IPointEntity)
            {
                using (IPointEntity pt = Origin.PointEntity.CopyAndTranslate(Normal.IVector) as IPointEntity)
                {
                    using (IPointEntity transformPt = pt.CopyAndTransform(CoordinateSystem.WCS.CSEntity, csEntity) as IPointEntity)
                    {
                        Vector normal = origin.GetVectorTo(transformPt).Normalize();
                        return(Plane.ByOriginNormal(origin.ToPoint(false, null), normal, Size));
                    }
                }
            }
        }