Esempio n. 1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string ID = null;

            if (!DA.GetData(0, ref ID))
            {
                return;
            }
            Guid gd = new Guid(ID);

            if (Rhino.RhinoDoc.ActiveDoc.Objects.Find(gd) is Rhino.DocObjects.TextObject)
            {
                Rhino.DocObjects.TextObject obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(gd) as Rhino.DocObjects.TextObject;
                TextEntity tx  = obj.TextGeometry;
                Plane      pln = tx.Plane;
                string     mm  = obj.DisplayText;
                DA.SetData(0, mm);
                DA.SetData(1, pln);
                DA.SetData(2, tx.TextHeight);
                DA.SetDataList(3, tx.Explode());
            }
            else if (Rhino.RhinoDoc.ActiveDoc.Objects.Find(gd) is Rhino.DocObjects.TextDotObject)
            {
                Rhino.DocObjects.TextDotObject obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(gd) as Rhino.DocObjects.TextDotObject;
                TextDot td = (TextDot)obj.Geometry;
                DA.SetData(0, td.Text);
                DA.SetData(1, td.Point);
            }
        }
        public Result drawDotMatrix(Point3d pt, string text, double textHeight, double panelWidth)
        {
            TextEntity dotMatrixText = new TextEntity();
            Vector3d   normalVector  = new Vector3d(0, 0, -1);
            Plane      textPlane     = new Plane(pt, normalVector);


            //if (panelWidth <= 70)
            //{
            //   textPlane.XAxis = new Vector3d(0, 1, 0);
            //   textPlane.YAxis = new Vector3d(1, 0, 0);
            //   textPlane.ZAxis = new Vector3d(0, 0, -1);
            //}
            dotMatrixText.Plane       = textPlane;
            dotMatrixText.Text        = text;
            dotMatrixText.TextHeight  = textHeight;
            dotMatrixText.FontIndex   = RhinoDoc.ActiveDoc.Fonts.FindOrCreate("Dot-Matrix", false, false);
            dotMatrixText.DrawForward = false;
            Rhino.Geometry.Curve[] curves    = dotMatrixText.Explode();
            Rhino.Geometry.Curve[] newCurves = new Curve[curves.Length];

            // Get each centre of the curves
            for (int i = 0; i < curves.Length; i++)
            {
                // Find the centre
                BoundingBox bbox = curves[i].GetBoundingBox(true);

                BoundingBox newBox = new BoundingBox(new Point3d(bbox.Center.X - 0.5, bbox.Center.Y - 0.5, 0), new Point3d(bbox.Center.X + 0.5, bbox.Center.Y + 0.5, 0));

                List <Point3d> rectangle_corners = newBox.GetCorners().Distinct().ToList();
                // add 1st point at last to close the loop
                rectangle_corners.Add(rectangle_corners[0]);

                newCurves[i] = new PolylineCurve(rectangle_corners);
            }


            if (newCurves != null)
            {
                foreach (Curve curve in newCurves)
                {
                    Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(curve);

                    int idx = RhinoDoc.ActiveDoc.Groups.Find(text, false);

                    if (idx < 0)
                    {
                        idx = RhinoDoc.ActiveDoc.Groups.Add(text);
                    }

                    RhinoDoc.ActiveDoc.Groups.AddToGroup(idx, guid);
                }
            }



            return(Result.Success);
        }
Esempio n. 3
0
        public Result drawDotMatrix(Point3d pt, string text, double textHeight)
        {
            TextEntity dotMatrixText = new TextEntity();
            Vector3d   normalVector  = new Vector3d(0, 0, 1);
            Plane      textPlane     = new Plane(pt, normalVector);

            dotMatrixText.Plane         = textPlane;
            dotMatrixText.Text          = text;
            dotMatrixText.Justification = TextJustification.BottomRight;
            dotMatrixText.TextHeight    = textHeight;
            dotMatrixText.FontIndex     = RhinoDoc.ActiveDoc.Fonts.FindOrCreate("Dot-Matrix", false, false);
            dotMatrixText.DrawForward   = false;
            Rhino.Geometry.Curve[] curves    = dotMatrixText.Explode();
            Rhino.Geometry.Curve[] newCurves = new Curve[curves.Length];

            // Get each centre of the curves
            for (int i = 0; i < curves.Length; i++)
            {
                // Find the centre
                BoundingBox bbox = curves[i].GetBoundingBox(true);

                newCurves[i] = new ArcCurve(new Circle(bbox.Center, 0.5));
            }


            if (newCurves != null)
            {
                foreach (Curve curve in newCurves)
                {
                    Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(curve);

                    int idx = RhinoDoc.ActiveDoc.Groups.Find(text, false);

                    if (idx < 0)
                    {
                        idx = RhinoDoc.ActiveDoc.Groups.Add(text);
                    }

                    RhinoDoc.ActiveDoc.Groups.AddToGroup(idx, guid);
                }
            }



            return(Result.Success);
        }
Esempio n. 4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Plane  plane     = new Plane();
            string text      = "";
            double size      = 5;
            int    justify   = 0;
            string font      = "";
            bool   bold      = false;
            double offsetDis = 0;

            DA.GetData("Location", ref plane);
            DA.GetData("Text", ref text);
            DA.GetData("Size", ref size);
            DA.GetData("Justification", ref justify);
            DA.GetData("Font", ref font);
            DA.GetData("Bold", ref bold);
            DA.GetData("OffsetDistance", ref offsetDis);

            if (justify < 0 || justify > 8)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid Justification.Only 0-8 are allowed.");
                justify = 4;
            }

            TextJustification justification = TextJustification.MiddleCenter;

            if (justify == 0)
            {
                Message       = "BottomLeft";
                justification = TextJustification.BottomLeft;
            }
            else if (justify == 1)
            {
                Message       = "BottomCenter";
                justification = TextJustification.BottomCenter;
            }
            else if (justify == 2)
            {
                Message       = "BottomRight";
                justification = TextJustification.BottomRight;
            }
            else if (justify == 3)
            {
                Message       = "MiddleLeft";
                justification = TextJustification.MiddleLeft;
            }
            else if (justify == 4)
            {
                Message       = "MiddleCenter";
                justification = TextJustification.MiddleCenter;
            }
            else if (justify == 5)
            {
                Message       = "MiddleRight";
                justification = TextJustification.MiddleRight;
            }
            else if (justify == 6)
            {
                Message       = "TopLeft";
                justification = TextJustification.TopLeft;
            }
            else if (justify == 7)
            {
                Message       = "TopCenter";
                justification = TextJustification.TopCenter;
            }
            else if (justify == 8)
            {
                Message       = "TopRight";
                justification = TextJustification.TopRight;
            }


            TextEntity t = new TextEntity();

            t.Plane          = plane;
            t.PlainText      = text;
            t.DimensionScale = size;
            t.Font           = Rhino.DocObjects.Font.InstalledFonts(font)[0];
            t.Justification  = justification;
            t.SetBold(bold);
            List <Curve> curves = new List <Curve>(t.Explode());

            List <Point3d> boxCorner = new List <Point3d>();

            foreach (Curve crv in curves)
            {
                foreach (Point3d pt in crv.GetBoundingBox(plane).GetCorners())
                {
                    boxCorner.Add(pt);
                }
            }

            Box box = new Box(plane, new BoundingBox(boxCorner));

            Point3d[] corners = box.GetCorners();
            Point3d[] pts     = new Point3d[5] {
                corners[0], corners[1], corners[2], corners[3], corners[0]
            };

            PolylineCurve polyCrv = new PolylineCurve(pts);
            Curve         bound;

            if (offsetDis == 0)
            {
                bound = polyCrv;
            }
            else
            {
                bound = polyCrv.Offset(plane, offsetDis, GH_Component.DocumentTolerance(), CurveOffsetCornerStyle.Round)[0];
            }



            DA.SetDataList("Curve", curves);
            DA.SetData("Bound", bound);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string face    = "";
            bool   bold    = false;
            bool   italics = false;
            double size    = 0;
            string content = "";
            Plane  pl      = Plane.Unset;

            if (!DA.GetData("Face", ref face))
            {
                return;
            }
            if (!DA.GetData("Bold", ref bold))
            {
                return;
            }
            if (!DA.GetData("Italics", ref italics))
            {
                return;
            }
            if (!DA.GetData("Size", ref size))
            {
                return;
            }
            if (!DA.GetData("Text Content", ref content))
            {
                return;
            }
            if (!DA.GetData("Plane", ref pl))
            {
                return;
            }

            if (size == 0)
            {
                size = 1;
            }

            if (!string.IsNullOrEmpty(face) && size > 0 && !string.IsNullOrEmpty(content) &&
                pl.IsValid)
            {
                if (!Rhino.DocObjects.Font.AvailableFontFaceNames().Contains(face))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ("That face is not available"));
                }
                Rhino.DocObjects.Font.FontWeight weight = Rhino.DocObjects.Font.FontWeight.Normal;
                Rhino.DocObjects.Font.FontStyle  style  = Rhino.DocObjects.Font.FontStyle.Upright;

                if (bold)
                {
                    weight = Rhino.DocObjects.Font.FontWeight.Bold;
                }

                if (italics)
                {
                    style = Rhino.DocObjects.Font.FontStyle.Italic;
                }

                var te = new TextEntity()
                {
                    Plane      = pl,
                    PlainText  = content,
                    TextHeight = size,
                    Font       = new Rhino.DocObjects.Font(face, weight, style, false, false)
                };
                var crvs = te.Explode();
                DA.SetDataList("Text Curves", crvs);
                var bbox = BoundingBox.Empty;
                foreach (var curve in crvs)
                {
                    bbox.Union(curve.GetBoundingBox(true));
                }
                DA.SetData("Text Bounding Box", bbox);
            }
        }
Esempio n. 6
0
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            // TODO: start here modifying the behaviour of your command.
            // ---

            /*
             * RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);
             *
             * Point3d pt0;
             * using (GetPoint getPointAction = new GetPoint())
             * {
             *  getPointAction.SetCommandPrompt("Please select the start point");
             *  if (getPointAction.Get() != GetResult.Point)
             *  {
             *      RhinoApp.WriteLine("No start point was selected.");
             *      return getPointAction.CommandResult();
             *  }
             *  pt0 = getPointAction.Point();
             * }
             *
             * Point3d pt1;
             * using (GetPoint getPointAction = new GetPoint())
             * {
             *  getPointAction.SetCommandPrompt("Please select the end point");
             *  getPointAction.SetBasePoint(pt0, true);
             *  getPointAction.DrawLineFromPoint(pt0, true);
             *  if (getPointAction.Get() != GetResult.Point)
             *  {
             *      RhinoApp.WriteLine("No end point was selected.");
             *      return getPointAction.CommandResult();
             *  }
             *  pt1 = getPointAction.Point();
             * }
             *
             * doc.Objects.AddLine(pt0, pt1);
             * doc.Views.Redraw();
             * RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);
             */

            var font_index = doc.Fonts.FindOrCreate("Times New Roman", true, false);

            var text_entity = new TextEntity
            {
                FontIndex     = font_index,
                Justification = TextJustification.None,
                Plane         = Plane.WorldXY,
                Text          = "Hell Yes!",
                TextHeight    = 5.0
            };

            var curves = text_entity.Explode();

            var dir = new Vector3d(0, 0, 5);

            foreach (var curve in curves)
            {
                var surface = Surface.CreateExtrusion(curve, dir);
                doc.Objects.AddSurface(surface);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }