Example #1
0
 public void drawExtrusion(Rhino.Geometry.Point3d point1, double height, double width, double thickness)
 {
     Rhino.Geometry.Plane       plane   = new Rhino.Geometry.Plane(point1, Rhino.Geometry.Vector3d.ZAxis);
     Rhino.Geometry.Point3d     cornerA = new Rhino.Geometry.Point3d(point1.X - width / 2, point1.Y - height / 2, point1.Z);
     Rhino.Geometry.Point3d     cornerB = new Rhino.Geometry.Point3d(point1.X + width / 2, point1.Y + height / 2, point1.Z);
     Rhino.Geometry.Rectangle3d rect    = new Rhino.Geometry.Rectangle3d(plane, cornerA, cornerB);
     Rhino.Geometry.Surface     srf     = Rhino.Geometry.Surface.CreateExtrusion(rect.ToNurbsCurve(), new Rhino.Geometry.Vector3d(0, 0, thickness));
     SetPreview(srf.ToBrep());
 }
Example #2
0
        public static string makeDocBox()
        {
            try
            {
                //If docBox has not been created, create it and place it on its natalus layer.

                /* Abandoning layer idea for now. Not working as intended.
                 * Rhino.DocObjects.Layer layer_D10 = new Rhino.DocObjects.Layer();
                 * int layer_D10_index = -1;
                 *
                 * if (RhinoDoc.ActiveDoc.Layers.FindName("D10").Index < 0)
                 * {
                 *  RhinoDoc.ActiveDoc.Layers.Add(layer_D10);
                 *  layer_D10_index = layer_D10.Index;
                 * }
                 * else
                 * {
                 *  layer_D10 = RhinoDoc.ActiveDoc.Layers.FindName("D10");
                 *  layer_D10_index = layer_D10.Index;
                 * }
                 */

                //Set initial dimensions and record to D01 if D01 does not exist.
                string D01_Path = utils.file_structure.getPathFor("D01");
                string D20_Path = utils.file_structure.getPathFor("D20");

                double docBox_width  = 12;
                double docBox_height = 12;

                Rhino.Geometry.Point3d refPoint = new Rhino.Geometry.Point3d(0, 0, 0);

                //Check if previous dim configuration existed.
                if (System.IO.File.Exists(D01_Path) == true)
                {
                    string[] dims = System.IO.File.ReadAllText(D01_Path).Split('|');

                    docBox_width  = Convert.ToDouble(dims[0]);
                    docBox_height = Convert.ToDouble(dims[1]);
                }
                else
                {
                    System.IO.File.WriteAllText(D01_Path, "12|12");
                }

                double adjust = 0;

                if (System.IO.File.Exists(D20_Path) == true)
                {
                    string[] coords = System.IO.File.ReadAllText(D20_Path).Split(',');

                    refPoint.X = Convert.ToDouble(coords[0]);
                    refPoint.Y = Convert.ToDouble(coords[1]);

                    adjust = docBox_height;
                }
                else if (System.IO.File.Exists(D20_Path) == false)
                {
                    adjust = 0;
                }

                Rhino.Geometry.Plane docBox_plane = Rhino.Geometry.Plane.WorldXY;
                docBox_plane.OriginX = refPoint.X;
                docBox_plane.OriginY = refPoint.Y - adjust;

                Rhino.Geometry.Rectangle3d docBox = new Rhino.Geometry.Rectangle3d(docBox_plane, docBox_width, docBox_height);

                Rhino.DocObjects.ObjectAttributes docBox_attributes = new Rhino.DocObjects.ObjectAttributes();

                //Until layer process resolved, docBox to be on any layer.
                int activeIndex = RhinoDoc.ActiveDoc.Layers.CurrentLayerIndex;
                docBox_attributes.LayerIndex = activeIndex;

                //(Rhino 5) Convert docBox Rectangle3D to polyline curve.
                Rhino.Geometry.Polyline docBoxPolyline = docBox.ToPolyline();

                //Freeze updating while docBox is created.
                string x10_path = utils.file_structure.getPathFor("x10");
                System.IO.File.WriteAllText(x10_path, "false");

                //Determine GUID and record to D10.
                Guid newGuid = RhinoDoc.ActiveDoc.Objects.AddPolyline(docBoxPolyline);

                Rhino.DocObjects.ObjRef      docBoxObj   = new Rhino.DocObjects.ObjRef(newGuid);
                Rhino.DocObjects.CurveObject docBoxCurve = docBoxObj.Object() as Rhino.DocObjects.CurveObject;

                string docBoxGUID = newGuid.ToString();

                string D10_Path = utils.file_structure.getPathFor("D10");
                if (System.IO.File.Exists(D10_Path) && System.IO.File.ReadAllText(D10_Path) != "")
                {
                    string D11_Path = utils.file_structure.getPathFor("D11");
                    System.IO.File.WriteAllText(D11_Path, System.IO.File.ReadAllText(D10_Path));
                }
                System.IO.File.WriteAllText(D10_Path, docBoxGUID);

                //Set curve to Illustrator orange.
                System.Drawing.Color docBoxColor = System.Drawing.Color.FromArgb(240, 120, 6);

                docBoxCurve.Attributes.ColorSource      = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
                docBoxCurve.Attributes.ObjectColor      = docBoxColor;
                docBoxCurve.Attributes.PlotColorSource  = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject;
                docBoxCurve.Attributes.PlotColor        = docBoxColor;
                docBoxCurve.Attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject;
                docBoxCurve.Attributes.PlotWeight       = 1.5;

                docBoxCurve.CommitChanges();

                //Label it!
                Rhino.Geometry.TextEntity label = new Rhino.Geometry.TextEntity();

                label.TextHeight = .4;

                Rhino.Geometry.Plane label_plane = Rhino.Geometry.Plane.WorldXY;
                label_plane.OriginX = docBox_plane.OriginX;
                label_plane.OriginY = docBox_plane.OriginY - .4 - .1;
                label.Plane         = label_plane;

                label.Text = ("Linked Illustrator Artboard");

                Guid docBoxLabel = RhinoDoc.ActiveDoc.Objects.AddText(label);

                Rhino.DocObjects.ObjRef     labelObj  = new Rhino.DocObjects.ObjRef(docBoxLabel);
                Rhino.DocObjects.TextObject labelText = labelObj.Object() as Rhino.DocObjects.TextObject;

                labelText.Attributes.ColorSource     = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
                labelText.Attributes.ObjectColor     = docBoxColor;
                labelText.Attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject;
                labelText.Attributes.PlotColor       = docBoxColor;

                labelText.CommitChanges();

                string docBoxLabelGUID = docBoxLabel.ToString();

                string D30_Path = utils.file_structure.getPathFor("D30");
                if (System.IO.File.Exists(D30_Path) && System.IO.File.ReadAllText(D30_Path) != "")
                {
                    string D31_Path = utils.file_structure.getPathFor("D31");
                    System.IO.File.WriteAllText(D31_Path, System.IO.File.ReadAllText(D30_Path));
                }
                System.IO.File.WriteAllText(D30_Path, docBoxLabelGUID);


                //Unfreeze updating.
                System.IO.File.WriteAllText(x10_path, "true");

                //Update illustrator boundaries.
                int    conversion = utils.units.conversion();
                string jsxPath    = utils.file_structure.getJavascriptPath();

                echo.interop echo = new echo.interop();
                echo.docBounds(docBox_width, System.Math.Abs(docBox_height), conversion, jsxPath);

                return(docBoxGUID);
            }
            catch (Exception e)
            {
                debug.alert(e.Message + " | " + e.Source);

                return("error");
            }
        }
Example #3
0
 public void drawExtrusion(Rhino.Geometry.Point3d point1, double height, double width, double thickness)
 {
     Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(point1,Rhino.Geometry.Vector3d.ZAxis);
     Rhino.Geometry.Point3d cornerA = new Rhino.Geometry.Point3d(point1.X - width / 2, point1.Y - height / 2, point1.Z);
     Rhino.Geometry.Point3d cornerB = new Rhino.Geometry.Point3d(point1.X + width / 2, point1.Y + height / 2, point1.Z);
     Rhino.Geometry.Rectangle3d rect = new Rhino.Geometry.Rectangle3d(plane, cornerA, cornerB);
     Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(rect.ToNurbsCurve(), new Rhino.Geometry.Vector3d(0, 0, thickness));
     SetPreview(srf.ToBrep());
 }