/// <summary>
        /// Runs the command.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string pdfLocation;
            string receiverMail;
            string confirmMail;
            string defaultMessage;
            string fileName;

            SendAgreementForm form = new SendAgreementForm();

            // Put together the file name
            fileName = Path.GetFileNameWithoutExtension(doc.Name);

            pdfLocation = getPdfLocation();            //prompt the user and retrieve the location of the final pdf Document
            form.ShowDialog();                         // display the form to get the relevant details

            receiverMail   = form.getReceiverMail();   //retrieve the entered values (mail address)
            defaultMessage = form.getDefaultMessage(); //retrieve the entered values (default message address)


            //Grab the location of the saved PDF file
            String fileLocation = Path.GetDirectoryName(doc.Path) + @"\" + fileName + ".pdf";
            int    lastPage     = RhinoUtilities.calculatePageNumbers(fileLocation); //get the total page count of the PDF (to find the locatin of agreement)

            Rhino.RhinoApp.WriteLine("Please wait while the system sends the final PDF with the Agreement to the Client");
            sendAgreement(fileLocation, fileName, lastPage.ToString(), receiverMail, defaultMessage);
            Rhino.RhinoApp.WriteLine("Successfully sent");


            return(Result.Success);
        }
        //this method sets the visibility status of different layers based on the selected option
        private void setLayerVisibility(RhinoDoc doc, Boolean completed)
        {
            if (selectedOption.Equals("PandL") && !completed)
            {
                if (doc.Layers.Find("DOT SCRIBE LABEL", true) >= 0)
                {
                    RhinoUtilities.setLayerVisibility("DOT SCRIBE LABEL", false);
                }
                RhinoUtilities.setLayerVisibility("TOOL HIT", false);
                RhinoUtilities.setLayerVisibility("FIXING HOLES", false);
                RhinoUtilities.setLayerVisibility("FOLDED PANEL FINISHED", false);
                RhinoUtilities.setLayerVisibility("FOLDS", false);
                RhinoUtilities.setLayerVisibility("BORDERS", false);
                RhinoUtilities.setLayerVisibility("DIMENSIONS BLUE", false);
                RhinoUtilities.setLayerVisibility("DETAILS", false);
                RhinoUtilities.setLayerVisibility("PERF ORIENTATION", false);
                RhinoUtilities.setLayerVisibility("BORDERS", false);
                RhinoUtilities.setLayerVisibility("FIXING HOLE DIMENSIONS", false);
                RhinoUtilities.setLayerVisibility("DIMENSIONS BLACK", false);
            }
            if (selectedOption.Equals("FullLayer") && !completed)
            {
                RhinoUtilities.setLayerVisibility("DOT SCRIBE LABEL", true);
                RhinoUtilities.setLayerVisibility("TOOL HIT", true);
                RhinoUtilities.setLayerVisibility("FIXING HOLES", true);
                RhinoUtilities.setLayerVisibility("FOLDED PANEL FINISHED", false);
                RhinoUtilities.setLayerVisibility("FOLDS", false);
                RhinoUtilities.setLayerVisibility("BORDERS", false);
                RhinoUtilities.setLayerVisibility("DIMENSIONS BLUE", false);
                RhinoUtilities.setLayerVisibility("LAYOUT DETAILS", false);
                RhinoUtilities.setLayerVisibility("PERFORATION", false);
                RhinoUtilities.setLayerVisibility("BORDERS", false);
                RhinoUtilities.setLayerVisibility("CLUSTER SAMPLE", false);
                RhinoUtilities.setLayerVisibility("FIXING HOLES DIMENSIONS", false);
                RhinoUtilities.setLayerVisibility("DIMENSIONS BLACK", false);
            }

            if (completed)
            {
                RhinoUtilities.setLayerVisibility("DOT SCRIBE LABEL", true);
                RhinoUtilities.setLayerVisibility("TOOL HIT", true);
                RhinoUtilities.setLayerVisibility("FOLDED PANEL FINISHED", true);
                RhinoUtilities.setLayerVisibility("FOLDS", true);
                RhinoUtilities.setLayerVisibility("BORDERS", true);
                RhinoUtilities.setLayerVisibility("DIMENSIONS BLUE", true);
                RhinoUtilities.setLayerVisibility("LAYOUT DETAILS", true);
                RhinoUtilities.setLayerVisibility("PERFORATION", true);
                RhinoUtilities.setLayerVisibility("BORDERS", true);
                RhinoUtilities.setLayerVisibility("CLUSTER SAMPLE", false);
                RhinoUtilities.setLayerVisibility("FIXING HOLES DIMENSIONS", true);
                RhinoUtilities.setLayerVisibility("DIMENSIONS BLACK", true);
            }
        }
        public void drawBlock(RhinoDoc doc, string labelName, string area, int panelNum, PanelParameters panelParas)
        {
            RhinoUtilities.SetActiveLayer("LAYOUT DETAILS", System.Drawing.Color.Black);

            //// Get the location of current API
            //String path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Logo\\MetrixLogo.jpg";

            //Plane picture = new Plane(new Point3d(5, 10, 0), new Vector3d(0, 0, 1));

            //// Add Company logo.
            //doc.Objects.AddPictureFrame(picture, path, false, 62.5, 25, false, false);

            // Draw bottom line
            doc.Objects.AddLine(new Point3d(5, 5, 0), new Point3d(205, 5, 0));

            // Top line
            doc.Objects.AddLine(new Point3d(5, 292, 0), new Point3d(205, 292, 0));

            // Left line
            doc.Objects.AddLine(new Point3d(5, 5, 0), new Point3d(5, 292, 0));

            // Right line
            doc.Objects.AddLine(new Point3d(205, 5, 0), new Point3d(205, 292, 0));

            //// Divider line
            //doc.Objects.AddLine(new Point3d(5, 10, 0), new Point3d(205, 10, 0));

            //// Row 1 line
            //doc.Objects.AddLine(new Point3d(67.5, 15, 0), new Point3d(205, 15, 0));

            //// Row 2 line
            //doc.Objects.AddLine(new Point3d(67.5, 20, 0), new Point3d(205, 20, 0));

            //// Row 3 line
            //doc.Objects.AddLine(new Point3d(67.5, 25, 0), new Point3d(205, 25, 0));

            //// Row 4 line
            //doc.Objects.AddLine(new Point3d(67.5, 30, 0), new Point3d(205, 30, 0));

            //// Row 5 line
            //doc.Objects.AddLine(new Point3d(67.5, 35, 0), new Point3d(205, 35, 0));

            //// Vertical divider line
            //doc.Objects.AddLine(new Point3d(136.5, 5, 0), new Point3d(136.5, 35, 0));

            //// Vertical divider line
            //doc.Objects.AddLine(new Point3d(87.5, 10, 0), new Point3d(87.5, 35, 0));

            //// Vertical divider line
            //doc.Objects.AddLine(new Point3d(156.5, 10, 0), new Point3d(156.5, 35, 0));

            // Draw Approval Box
            // Horizontal lines
            //doc.Objects.AddLine(new Point3d(136.5, 40, 0), new Point3d(200, 40, 0));
            //doc.Objects.AddLine(new Point3d(136, 39.5, 0), new Point3d(200.5, 39.5, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 45, 0), new Point3d(200, 45, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 55, 0), new Point3d(200, 55, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 60, 0), new Point3d(200, 60, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 65, 0), new Point3d(200, 65, 0));
            //doc.Objects.AddLine(new Point3d(136, 65.5, 0), new Point3d(200.5, 65.5, 0));

            //// Vertical lines
            //doc.Objects.AddLine(new Point3d(136, 39.5, 0), new Point3d(136, 65.5, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 40, 0), new Point3d(136.5, 65, 0));
            //doc.Objects.AddLine(new Point3d(156.5, 40, 0), new Point3d(156.5, 60, 0));
            //doc.Objects.AddLine(new Point3d(200, 40, 0), new Point3d(200, 65, 0));
            //doc.Objects.AddLine(new Point3d(200.5, 39.5, 0), new Point3d(200.5, 65.5, 0));

            string text   = "51 Holloway Drive            metrixgroup.com.au\nBayswater VIC 3153                  1300 792 493";
            double height = 3.5;

            Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(11, 15 + height, 0);
            string font = "Arial";

            Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
            plane.Origin = pt;
            Guid id;

            // id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = "Supply of this order will be solely and exlusively according to the terms and conditions of Metrix Group Pty Ltd.";
            //plane.Origin = new Point3d(7, 6, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = "PANEL";
            //plane.Origin = new Point3d(69, 31, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            height       = 1.5;
            text         = labelName;
            plane.Origin = new Point3d(89, 31 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "DRAWN";
            //plane.Origin = new Point3d(69, 26, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "CHECKED";
            //plane.Origin = new Point3d(69, 21, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "m²";
            //plane.Origin = new Point3d(69, 16, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            text         = area;
            plane.Origin = new Point3d(89, 16 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "Page ";
            //plane.Origin = new Point3d(69, 11, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            text         = panelNum + " of " + panelParas.TotalPanel;
            plane.Origin = new Point3d(89, 11 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "PROJECT";
            //plane.Origin = new Point3d(138, 31, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            height       = 1.5;
            text         = panelParas.Project;
            plane.Origin = new Point3d(158, 31 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "CUSTOMER ";
            //plane.Origin = new Point3d(138, 26, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            height       = 1.5;
            text         = panelParas.CustomerName;
            plane.Origin = new Point3d(158, 26 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "JOB NO.";
            //plane.Origin = new Point3d(138, 21, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            height       = 1.5;
            text         = panelParas.JobNo;
            plane.Origin = new Point3d(158, 21 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "MATERIAL";
            //plane.Origin = new Point3d(138, 16, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            height       = 1.5;
            text         = panelParas.Material;
            plane.Origin = new Point3d(158, 16 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "COATING";
            //plane.Origin = new Point3d(138, 11, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            height       = 1.5;
            text         = panelParas.Coating;
            plane.Origin = new Point3d(158, 11 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            text         = "Copyright © Metrix Group " + DateTime.Today.Year;
            plane.Origin = new Point3d(138, 6 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "APPROVED BY";
            //plane.Origin = new Point3d(138, 61, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "NAME";
            //plane.Origin = new Point3d(138, 56, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "SIGNATURE";
            //plane.Origin = new Point3d(138, 51, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "DATE";
            //plane.Origin = new Point3d(138, 41, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            if (panelParas.DotFont == 1)
            {
                text         = "* 10 mm Dot font labelling to the rear of all panels";
                plane.Origin = new Point3d(136.5, 70 + height, 0);
                id           = doc.Objects.AddText(text, plane, height, font, false, false);

                text         = "The purple line represents the unperforated distance" + "\nbetween the edge of the panel and the perforation";
                plane.Origin = new Point3d(136.5, 65 + height, 0);
                id           = doc.Objects.AddText(text, plane, height, font, false, false);
            }
        }
        public void drawBlock(RhinoDoc doc, string labelName, string area, int panelNum, PerforationPanel panel, int panelQty)
        {
            RhinoUtilities.SetActiveLayer("LAYOUT DETAILS", System.Drawing.Color.Black);

            //// Get the location of current API
            //String path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Logo\\MetrixLogo.jpg";

            //Plane picture = new Plane(new Point3d(5, 10, 0), new Vector3d(0, 0, 1));

            //// Add Company logo.
            //doc.Objects.AddPictureFrame(picture, path, false, 62.5, 25, false, false);

            // Draw bottom line
            doc.Objects.AddLine(new Point3d(5, 5, 0), new Point3d(205, 5, 0));

            // Top line
            doc.Objects.AddLine(new Point3d(5, 292, 0), new Point3d(205, 292, 0));

            // Left line
            doc.Objects.AddLine(new Point3d(5, 5, 0), new Point3d(5, 292, 0));

            // Right line
            doc.Objects.AddLine(new Point3d(205, 5, 0), new Point3d(205, 292, 0));

            //// Divider line
            //doc.Objects.AddLine(new Point3d(5, 10, 0), new Point3d(205, 10, 0));

            //// Row 1 line
            //doc.Objects.AddLine(new Point3d(67.5, 15, 0), new Point3d(205, 15, 0));

            //// Row 2 line
            //doc.Objects.AddLine(new Point3d(67.5, 20, 0), new Point3d(205, 20, 0));

            //// Row 3 line
            //doc.Objects.AddLine(new Point3d(67.5, 25, 0), new Point3d(205, 25, 0));

            //// Row 4 line
            //doc.Objects.AddLine(new Point3d(67.5, 30, 0), new Point3d(205, 30, 0));

            //// Row 5 line
            //doc.Objects.AddLine(new Point3d(67.5, 35, 0), new Point3d(205, 35, 0));

            //// Vertical divider line
            //doc.Objects.AddLine(new Point3d(136.5, 5, 0), new Point3d(136.5, 35, 0));

            //// Vertical divider line
            //doc.Objects.AddLine(new Point3d(87.5, 10, 0), new Point3d(87.5, 35, 0));

            //// Vertical divider line
            //doc.Objects.AddLine(new Point3d(156.5, 10, 0), new Point3d(156.5, 35, 0));

            // Draw Approval Box
            // Horizontal lines
            //doc.Objects.AddLine(new Point3d(136.5, 40, 0), new Point3d(200, 40, 0));
            //doc.Objects.AddLine(new Point3d(136, 39.5, 0), new Point3d(200.5, 39.5, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 45, 0), new Point3d(200, 45, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 55, 0), new Point3d(200, 55, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 60, 0), new Point3d(200, 60, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 65, 0), new Point3d(200, 65, 0));
            //doc.Objects.AddLine(new Point3d(136, 65.5, 0), new Point3d(200.5, 65.5, 0));

            //// Vertical lines
            //doc.Objects.AddLine(new Point3d(136, 39.5, 0), new Point3d(136, 65.5, 0));
            //doc.Objects.AddLine(new Point3d(136.5, 40, 0), new Point3d(136.5, 65, 0));
            //doc.Objects.AddLine(new Point3d(156.5, 40, 0), new Point3d(156.5, 60, 0));
            //doc.Objects.AddLine(new Point3d(200, 40, 0), new Point3d(200, 65, 0));
            //doc.Objects.AddLine(new Point3d(200.5, 39.5, 0), new Point3d(200.5, 65.5, 0));

            Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(11, 15, 0);
            string text   = "51 Holloway Drive            metrixgroup.com.au\nBayswater VIC 3153                  1300 792 493";
            double height = 3.5;
            string font   = "Arial";

            Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
            plane.Origin = pt;
            Guid id;

            //XXX: This has been turned off due to a request by Keyur(Confirmed with Ross)
            //if (panel.FixingHoles == "1") //Add this text only if there are fixing holes
            //{
            //   pt = new Rhino.Geometry.Point3d(43, 45, 0);
            //   text = "Fixing Holes Diameter : " + panel.HoleDiameter + " and Centers Approximated at : "+panel.FixingHoleCentres;
            //   height = 2.3;
            //   font = "Arial";
            //   plane.Origin = pt;
            //   id = doc.Objects.AddText(text, plane, height, font, false, false);
            //}
            //if (panel.DrawPerf != 3) //If draw perf is not solid panel
            //{

            //   //MetrixUtilities.createMetrixBordersDimension();
            //   //pt = new Rhino.Geometry.Point3d(43, 65, 0);
            //   //text = "Pattern: " + panel.PatternName;
            //   //height = 2.3;
            //   //font = "Arial";
            //   //plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
            //   //plane.Origin = pt;
            //   //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //   //pt = new Rhino.Geometry.Point3d(43, 55, 0);
            //   //text = "Open Area: " + openArea + "%";
            //   //height = 2.3;
            //   //font = "Arial";
            //   //plane.Origin = pt;
            //   //id = doc.Objects.AddText(text, plane, height, font, false, false);
            //}
            //else
            //{
            //   pt = new Rhino.Geometry.Point3d(43, 65, 0);
            //   text = "Solid Panel";
            //   height = 2.3;
            //   font = "Arial";
            //   plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
            //   plane.Origin = pt;
            //   id = doc.Objects.AddText(text, plane, height, font, false, false);
            //}
            // id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = "Supply of this order will be solely and exlusively according to the terms and conditions of Metrix Group Pty Ltd.";
            //plane.Origin = new Point3d(7, 6, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = "PANEL";
            //plane.Origin = new Point3d(69, 31, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            height       = 1.5;
            text         = labelName;
            plane.Origin = new Point3d(89, 31 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "DRAWN";
            //plane.Origin = new Point3d(69, 26, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);
            //Using reg pattern to split part name and extract the quantity
            //Regex re = new Regex(@"([a-zA-Z]+)(\d+)");
            //Match result = re.Match(panel.PartName);
            //text = result.Groups[2].Value;
            text         = "" + panel.PanelQuantity; //set the quantity for each panel
            plane.Origin = new Point3d(89, 21 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "m²";
            //plane.Origin = new Point3d(69, 16, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            text         = area;
            plane.Origin = new Point3d(89, 16 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "Page ";
            //plane.Origin = new Point3d(69, 11, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            text         = panelNum + " of " + panelQty;
            plane.Origin = new Point3d(89, 11 + height, 0);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "PROJECT";
            //plane.Origin = new Point3d(138, 31, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = panelParas.Project;
            //plane.Origin = new Point3d(158, 31, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "CUSTOMER ";
            //plane.Origin = new Point3d(138, 26, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = panelParas.CustomerName;
            //plane.Origin = new Point3d(158, 26, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "JOB NO.";
            //plane.Origin = new Point3d(138, 21, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = panelParas.JobNo;
            //plane.Origin = new Point3d(158, 21, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "MATERIAL";
            //plane.Origin = new Point3d(138, 16, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = panelParas.Material;
            //plane.Origin = new Point3d(158, 16, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "COATING";
            //plane.Origin = new Point3d(138, 11, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //height = 1.5;
            //text = panelParas.Coating;
            //plane.Origin = new Point3d(158, 11, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "Copyright © Metrix Group " + DateTime.Today.Year;
            //plane.Origin = new Point3d(138, 6, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "APPROVED BY";
            //plane.Origin = new Point3d(138, 61, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "NAME";
            //plane.Origin = new Point3d(138, 56, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "SIGNATURE";
            //plane.Origin = new Point3d(138, 51, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            //text = "DATE";
            //plane.Origin = new Point3d(138, 41, 0);
            //id = doc.Objects.AddText(text, plane, height, font, false, false);

            if (panel.DotFontLabel == 1)
            {
                if (panel.DotFontLabellerSide.Equals("Rear"))
                {
                    text         = "* 9 mm Dot font labelling to the rear of all panels";
                    plane.Origin = new Point3d(136.392, 53.865 + height, 0.000);
                    id           = doc.Objects.AddText(text, plane, height, font, false, false);
                }
                else
                {
                    text         = "* 9 mm Dot font labelling to the front of all panels";
                    plane.Origin = new Point3d(136.392, 53.865 + height, 0.000);
                    id           = doc.Objects.AddText(text, plane, height, font, false, false);
                }
            }
            text         = "** The purple line represents the unperforated distance" + "\nbetween the edge of the panel and the perforation";
            plane.Origin = new Point3d(136.392, 48.865 + height, 0.000);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            text         = "*** The border dimensions shown are minimum values.\n Actual borders will be ≥ those shown.";
            plane.Origin = new Point3d(136.284, 42.595 + height, 0.000);
            id           = doc.Objects.AddText(text, plane, height, font, false, false);

            var parentlayerIndex = doc.Layers.Find("LAYERS FOR APPROVAL DRAWINGS", true); //get parent layer index

            // Draw the sample block
            createSubLayers.createSubLayer("COLOUR AND QUANTITY",
                                           System.Drawing.Color.Red, doc.Layers[parentlayerIndex]); //create layer called perf orientation (sublayer)

            if (panel.coating.Equals("Mill finish") || panel.coating.Equals("Mill Finish"))
            {
                text         = "Quantity: " + panel.PanelQuantity + "\nColour: " + panel.coating;
                plane.Origin = new Point3d(102.148, 63.946 + height, 0.000);
            }
            else
            {
                text         = "Quantity: " + panel.PanelQuantity + "\nColour: " + panel.colour;
                plane.Origin = new Point3d(102.204, 65.299 + height, 0.000);
            }
            height = 2.5;
            ObjectAttributes objAttributes = new ObjectAttributes();

            objAttributes.ObjectColor     = System.Drawing.Color.Red;
            objAttributes.ColorSource     = ObjectColorSource.ColorFromObject;
            objAttributes.PlotColor       = System.Drawing.Color.Red;
            objAttributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject;
            id = doc.Objects.AddText(text, plane, height, font, false, false, objAttributes);
            RhinoObject colorText = doc.Objects.Find(id);

            colorText.Attributes.LayerIndex = doc.Layers.Find("COLOUR AND QUANTITY", true);
            colorText.CommitChanges();
            doc.Views.Redraw();
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;

            go.SetCommandPrompt("Select All circles you want to filter:");
            GetResult result = go.GetMultiple(1, 0);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            int fixingHoleCounter = go.ObjectCount;

            RhinoApp.WriteLine("circle selection counter = {0}", fixingHoleCounter);

            int i = 0;

            Point3d[]     fixingHole  = new Point3d[fixingHoleCounter];
            double[]      fixingHoleD = new double[fixingHoleCounter];
            RhinoObject[] references  = new RhinoObject[fixingHoleCounter];

            for (i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();
                Curve       curve       = (new ObjRef(rhinoObject)).Curve();
                if (curve == null)
                {
                    continue;
                }

                if (curve.IsClosed == false)
                {
                    continue;
                }

                if (curve.IsPlanar() == false)
                {
                    continue;
                }

                if (curve.IsCircle())
                {
                    BoundingBox boundingBox = curve.GetBoundingBox(true);
                    fixingHoleD[i] = boundingBox.Max.X - boundingBox.Min.X;
                    fixingHole[i]  = boundingBox.Center;
                    references[i]  = rhinoObject;
                }
            }

            //Get the gap clearance offset
            go.SetCommandPrompt("Enter detection radius:");
            go.AcceptNumber(true, false);
            go.Get();
            double offset = go.Number();

            double perforationHoldD;
            string layerName = "";


            //for testing purpose, draw the hole with offset using red color

            /*Curve[] circles = new Curve[fixingHole.Length];
             * for (i = 0; i < circles.Length; i++)
             * {
             *
             *  circles[i] = new ArcCurve(new Circle(fixingHole[i], offset));
             * }
             *
             *
             * if (circles != null)
             * {
             *  layerName = offset + "mm GAP CLEARANCE";
             *  RhinoUtilities.SetActiveLayer(layerName, System.Drawing.Color.Red);
             *
             *  foreach (Curve cv in circles)
             *  {
             *      Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(cv);
             *  }
             * }*/

            string clashHoleLayerName = "HOLES CLASHED";
            Layer  clashHoleLayer     = new Layer();

            clashHoleLayer.Name  = clashHoleLayerName;
            clashHoleLayer.Color = System.Drawing.Color.Red;

            int clashHoleLayerIndex = doc.Layers.Add(clashHoleLayer);
            int currentHoleCounter;
            int flag;

            bool[] deletedCircles = new bool[fixingHole.Length];
            for (i = 0; i < deletedCircles.Length; i++)
            {
                deletedCircles[i] = false;
            }

            Curve circles;

            RhinoUtilities.SetActiveLayer(clashHoleLayerName, System.Drawing.Color.Red);
            for (i = 0; i < fixingHole.Length - 1; i++)
            {
                currentHoleCounter = 0;
                flag = 0;
                for (int j = i + 1; j < fixingHole.Length; j++)
                {
                    if (deletedCircles[j] == true)
                    {
                        continue;
                    }
                    if (fixingHole[i].DistanceTo(fixingHole[j]) < fixingHoleD[i] + offset)
                    {
                        if (currentHoleCounter == 0)
                        {
                            flag = j;
                            currentHoleCounter++;
                        }
                        else
                        {
                            currentHoleCounter++;
                            break;
                        }
                    }
                    if (currentHoleCounter == 1)
                    {
                        circles = new ArcCurve(new Circle(fixingHole[flag], fixingHoleD[flag] / 2));
                        Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(circles);

                        RhinoDoc.ActiveDoc.Objects.Delete(references[flag], false);
                        deletedCircles[flag] = true;
                    }
                    else if (currentHoleCounter == 2)
                    {
                        circles = new ArcCurve(new Circle(fixingHole[i], fixingHoleD[i] / 2));
                        Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(circles);

                        RhinoDoc.ActiveDoc.Objects.Delete(references[i], false);
                        deletedCircles[i] = true;
                    }
                }
            }


            RhinoUtilities.setLayerVisibility("HOLES CLASHED", true);

            RhinoUtilities.setLayerVisibility(layerName, false);

            doc.Views.Redraw();

            return(Result.Success);
        }
        public void drawBlock(RhinoDoc doc, List <FoldedPerforationPanel> panel, double openAreaDifference)
        {
            RhinoUtilities.SetActiveLayer("LAYOUT DETAILS", System.Drawing.Color.Black);


            string[] textArray = new string[15];

            textArray[0]  = "Customer : ";
            textArray[1]  = "Project : ";
            textArray[2]  = "Customer Purchase Order Number : ";
            textArray[3]  = "Metrix Part Number : ";
            textArray[4]  = "Metrix Sales Order Number : ";
            textArray[5]  = "Metrix Job Number : ";
            textArray[6]  = "Description : ";
            textArray[7]  = "Pattern : ";
            textArray[8]  = "Open Area : ";
            textArray[9]  = "Dot Fonts : ";
            textArray[10] = "Panel Types : ";
            textArray[11] = "Fixing Holes : ";
            textArray[12] = "Coating : ";
            textArray[13] = "Total Quantity of Panels : ";
            textArray[14] = "Total SQM of Panels : ";

            double height = 5.5;
            string font   = "Arial";

            Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
            Guid id;
            int  i = 0;

            //Add headings to Summary Layout
            foreach (string text in textArray)
            {
                plane.Origin = new Point3d(7, 260 - 10 * i + height, 0);
                id           = doc.Objects.AddText(text, plane, height, font, false, false);
                i++;
            }

            //Add Customer Name
            string valueText = panel[0].customerName;

            if (valueText.Length > 50)
            {
                plane.Origin = new Point3d(50, 260 + 4, 0);
                id           = doc.Objects.AddText(valueText, plane, 4, font, false, false);
            }
            else
            {
                plane.Origin = new Point3d(50, 260 + height, 0);
                id           = doc.Objects.AddText(valueText, plane, height, font, false, false);
            }

            //Add Project Name
            valueText    = panel[0].project;
            plane.Origin = new Point3d(50, 250 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Customer Number
            valueText    = panel[0].CustomerOrderNo;
            plane.Origin = new Point3d(135, 240 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Metrix Part Number
            valueText    = panel[0].MetrixPartNo;
            plane.Origin = new Point3d(82, 230 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Customer Number
            valueText    = panel[0].MetrixSalesNo;
            plane.Origin = new Point3d(107, 220 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Job Number
            valueText    = panel[0].jobNo;
            plane.Origin = new Point3d(82, 210 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Description
            valueText    = panel[0].SheetThickness + "mm / " + panel[0].material;
            plane.Origin = new Point3d(50, 200 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Pattern
            valueText    = panel[0].PatternName;
            plane.Origin = new Point3d(40, 190 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Pattern Open Area
            if (openAreaDifference <= 2)
            {
                valueText = panel[0].PatternOpenArea + "%";
            }
            else
            {
                valueText = "%";
            }

            //valueText = panel[0].PatternOpenArea + "%";
            plane.Origin = new Point3d(50, 180 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Dot Fonts
            if (panel[0].DotFontLabel == 1)
            {
                valueText    = panel[0].DotFontLabellerSide;
                plane.Origin = new Point3d(50, 170 + height, 0);
                id           = doc.Objects.AddText(valueText, plane, height, font, false, false);
            }
            else
            {
                valueText    = "No";
                plane.Origin = new Point3d(50, 170 + height, 0);
                id           = doc.Objects.AddText(valueText, plane, height, font, false, false);
            }

            //Add Panel Types
            List <string> pnlList = new List <string>();

            pnlList.Add(panel[0].PanelType);
            foreach (FoldedPerforationPanel pnl in panel)
            {
                if (!pnlList.Contains(pnl.PanelType))
                {
                    pnlList.Add(pnl.PanelType);
                }
            }
            valueText = "";
            int textCounter = 0;

            foreach (string type in pnlList)
            {
                if (textCounter == 0)
                {
                    valueText += type;
                }
                else
                {
                    valueText += " & " + type;
                }
                textCounter++;
            }
            plane.Origin = new Point3d(55, 160 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add Fixing Holes
            if (panel[0].FixingHoles.Equals("0"))
            {
                valueText    = "No";
                plane.Origin = new Point3d(55, 150 + height, 0);
                id           = doc.Objects.AddText(valueText, plane, height, font, false, false);
            }
            else
            {
                valueText    = "Yes";
                plane.Origin = new Point3d(55, 150 + height, 0);
                id           = doc.Objects.AddText(valueText, plane, height, font, false, false);
            }

            //Add Coating
            if (panel[0].coating.Equals("Mill Finish") || panel[0].coating.Equals("Mill finish"))
            {
                valueText    = panel[0].coating;
                plane.Origin = new Point3d(40, 140 + height, 0);
                id           = doc.Objects.AddText(valueText, plane, height, font, false, false);
            }
            else
            {
                valueText    = panel[0].colour;
                plane.Origin = new Point3d(40, 140 + 4.5, 0);
                id           = doc.Objects.AddText(valueText, plane, 4.5, font, false, false);
            }


            //Add Panel Quantity
            valueText    = panel[0].TotalPanelQuantity;
            plane.Origin = new Point3d(95, 130 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);

            //Add SQM of Panels
            valueText    = Math.Round(panel[0].TotalPanelSQM, 2).ToString();
            plane.Origin = new Point3d(85, 120 + height, 0);
            id           = doc.Objects.AddText(valueText, plane, height, font, false, false);
        }
示例#7
0
        public Result createPDF(RhinoDoc doc, bool askToolHit)
        {
            RhinoApp.RunScript("Save", true); //save file before printing
            string fileName = Path.GetFileNameWithoutExtension(doc.Name);

            System.Windows.Forms.PrintDialog dlg = new PrintDialog();

            //Prompt the user whether the tool hit is required on the final PDF or not
            if (askToolHit)
            {
                if (!MessageBoxes.Messages.showToolHitRequired())
                {
                    //If the tool hit is not required, make the tool hit layer invisible
                    RhinoUtilities.SetActiveLayer("LABELS", System.Drawing.Color.Red);
                    RhinoUtilities.setLayerVisibility("Tool Hit", false);
                }
                else
                {
                    RhinoUtilities.SetActiveLayer("LABELS", System.Drawing.Color.Red);
                    RhinoUtilities.setLayerVisibility("Tool Hit", true);
                }
            }
            else
            {
                RhinoUtilities.SetActiveLayer("LABELS", System.Drawing.Color.Red);
                RhinoUtilities.setLayerVisibility("Tool Hit", false);
            }

            //set the cluster sample layer to invisible
            RhinoUtilities.setLayerVisibility("CLUSTER SAMPLE", false);
            if (dlg.PrinterSettings.IsValid == false)
            {
                Messages.showBullzipNotInstalled();
            }
            else
            {
                // If Page Views is 0
                if (doc.Views.GetPageViews().Count() != 0)
                {
                    try
                    {
                        tempPdfPath = Path.GetDirectoryName(doc.Path) + @"\" + "temp" + ".pdf";  //create a temporary pdf with panels
                        oriPdfPath  = Path.GetDirectoryName(doc.Path) + @"\" + fileName + ".pdf";
                        PdfSettings pdfSettings = new PdfSettings();
                        //pdfSettings.PrinterName = PRINTERNAME;
                        pdfSettings.SetValue("Output", tempPdfPath);
                        pdfSettings.SetValue("ShowPDF", "no");
                        pdfSettings.SetValue("ShowSettings", "never");
                        pdfSettings.SetValue("ShowSaveAS", "never");
                        pdfSettings.SetValue("ShowProgress", "yes");
                        pdfSettings.SetValue("ShowProgressFinished", "no");
                        pdfSettings.SetValue("ConfirmOverwrite", "no");
                        pdfSettings.SetValue("Orientation", "portrait");
                        pdfSettings.WriteSettings(PdfSettingsFileType.RunOnce);


                        string command = string.Format("-_Print _Setup _Destination _Printer \"Bullzip PDF Printer\" _PageSize 210.000 297.00 _OutputType=Vector _Enter _View _AllLayouts _Enter _Enter _Go _Enter");
                        RhinoApp.RunScript(command, true);

                        string[] pdfs = new String[2]; //create a string array to hold the locations of the pdf with panel and agreement form pdf.
                        pdfs[0] = tempPdfPath;
                        pdfs[1] = agreementLocation;

                        //Uncomment the below line when adobe is purchased
                        // RhinoUtilities.combinePDF(oriPdfPath, pdfs, 0, 1, "Drawings First"); //pass the array and the target location to save the final pdf

                        RhinoUtilities.combinePDF(oriPdfPath, pdfs, 0, 1, "Watermark Only");
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show("Error printing PDF document." + ex.Message);
                    }
                }
            }
            return(Result.Success);
        }
        public void drawCaveImageTool(double cx, double cy, double angleRad, int currentLayerIndex, string location)
        {
            String             layerOne    = "SURFACES TRIM"; //Layer names found in the imported drawing rhino
            String             layerTwo    = "SURFACES 2";
            RhinoDoc           doc         = RhinoDoc.ActiveDoc;
            List <RhinoObject> imported    = new List <RhinoObject>();
            List <RhinoObject> transformed = new List <RhinoObject>();
            String             loggedUser  = Environment.UserName;

            // String fileLocation = "C:\\Users\\"+ loggedUser+"\\Documents\\RotateForm_Rhino_Document\\ROTATEFORM.3dm";


            String fileImportScript = String.Format("_-Import \"{0}\" _Enter", location); //import the cave image

            RhinoApp.RunScript(fileImportScript, true);                                   //run the script

            //Import the objects in the layers
            foreach (RhinoObject obj in doc.Objects.FindByLayer(layerOne))
            {
                imported.Add(obj); //import all objects found in the layer1 of the imported cave tool
            }
            foreach (RhinoObject obj in doc.Objects.FindByLayer(layerTwo))
            {
                imported.Add(obj); //import all objects found in layer2 of the imported cave tool
            }


            //Find the location of the hole
            var locationOfCircle = new Vector3d(cx, cy, 0);



            foreach (RhinoObject objRef in imported) //Move the objects to the location of the hole
            {
                RhinoObject testObj = objRef;
                var         xform   = Transform.Translation(locationOfCircle);
                doc.Objects.Transform(objRef, xform, true);
                transformed.Add(doc.Objects.Find(objRef.Id));
            }

            //Select objects from the 2 layers
            Rhino.DocObjects.RhinoObject[] rhobjs = doc.Objects.FindByLayer(layerOne); //selecting objects in layer 1

            for (int i = 0; i < rhobjs.Length; i++)
            {
                rhobjs[i].Select(true);
            }

            rhobjs = doc.Objects.FindByLayer(layerTwo); //selecting objects in layer 2

            for (int y = 0; y < rhobjs.Length; y++)
            {
                rhobjs[y].Select(true);
            }

            //Rotate all the selected objects (using the script)
            RhinoApp.RunScript("_-rotate " + cx + "," + cy + " " + angleRad, true);

            foreach (RhinoObject objRef in transformed)           //Move the objects to the location of the hole
            {
                objRef.Attributes.LayerIndex = currentLayerIndex; //change the layerindex of the holes
                objRef.CommitChanges();
            }
            //delete the original layers of the hole and their objects
            RhinoUtilities.deleteLayer(layerOne);
            RhinoUtilities.deleteLayer(layerTwo);
        }
        /// <summary>
        /// Draws the perforation.
        /// </summary>
        /// <returns></returns>
        public override double drawPerforation(Curve boundaryCurve)
        {
            List <PointMap> pointMapList = new List <PointMap>();

            // Add two Point Map in the list
            pointMapList.Add(new PointMap());
            pointMapList.Add(new PointMap());

            // Find the boundary
            BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY);
            Point3d     min         = boundingBox.Min;
            Point3d     max         = boundingBox.Max;

            double spanX = max.X - min.X;
            double spanY = max.Y - min.Y;

            int    punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1;
            double marginX   = (spanX - ((punchQtyX - 1) * XSpacing)) / 2;
            double YSpacing  = XSpacing;

            int    punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1;
            double marginY   = (spanY - ((punchQtyY - 1) * YSpacing)) / 2;

            Point3d  point;
            RhinoDoc doc    = RhinoDoc.ActiveDoc;
            double   firstX = min.X + marginX;
            double   firstY = min.Y + marginY;

            // Set the layer
            int currentLayer = doc.Layers.CurrentLayerIndex;

            Random random     = new Random();
            int    tool0Count = 0;
            int    tool1Count = 0;

            for (int y = 0; y < punchQtyY; y++)
            {
                for (int x = 0; x < punchQtyX; x++)
                {
                    // Locate the point
                    point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0);

                    // If the randomness is bigger than random, put small tool
                    if (random.NextDouble() < randomness)
                    {
                        if (punchingToolList[0].isInside(boundaryCurve, point) == true)
                        {
                            pointMapList[1].AddPoint(new PunchingPoint(point));
                            punchingToolList[1].drawTool(point);
                            tool1Count++;
                            if (MetrixUtilities.IsLayerFound("TemporaryPerfLayer"))
                            {
                                RhinoUtilities.SetActiveLayer("TemporaryTool2Layer", System.Drawing.Color.Yellow);
                                punchingToolList[1].drawTool(point);
                                doc.Layers.SetCurrentLayerIndex(currentLayer, true);
                            }
                            else
                            {
                                RhinoUtilities.SetActiveLayer("Tool 2 Layer", System.Drawing.Color.Yellow);
                                punchingToolList[1].drawTool(point);
                                RhinoUtilities.SetActiveLayer(Properties.Settings.Default.PerforationLayerName, System.Drawing.Color.Green);
                            }
                        }
                    }
                    else
                    {
                        if (punchingToolList[0].isInside(boundaryCurve, point) == true)
                        {
                            if (punchingToolList[1].ClusterTool.Enable == true)
                            {
                                pointMapList[1].AddPoint(new PunchingPoint(point));
                            }

                            if (MetrixUtilities.IsLayerFound("TemporaryPerfLayer"))
                            {
                                RhinoUtilities.SetActiveLayer("TemporaryTool2Layer", System.Drawing.Color.Yellow);
                                punchingToolList[1].drawTool(point);
                                doc.Layers.SetCurrentLayerIndex(currentLayer, true);
                            }
                            else
                            {
                                RhinoUtilities.SetActiveLayer("Tool 2 Layer", System.Drawing.Color.Yellow);
                                punchingToolList[1].drawTool(point);
                                RhinoUtilities.SetActiveLayer(Properties.Settings.Default.PerforationLayerName, System.Drawing.Color.Green);
                            }
                            pointMapList[0].AddPoint(new PunchingPoint(point));
                            punchingToolList[0].drawTool(point);
                            tool0Count++;
                        }
                    }
                }
            }

            // Draw the cluster for each tool
            for (int i = 0; i < punchingToolList.Count; i++)
            {
                // Only draw cluster tool if it is enable
                if (punchingToolList[i].ClusterTool.Enable == true)
                {
                    drawCluster(pointMapList[i], punchingToolList[i]);
                }
                else
                {
                    // Set to Tool Hit Layer
                    RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, Color.Black);

                    // Places where cannot cluster punch
                    for (int k = 0; k < pointMapList[i].YCount; k++)
                    {
                        SortedDictionary <int, PunchingPoint> xDict = pointMapList[i].getXDictionary(k);

                        for (int m = 0; m < xDict.Count; m++)
                        {
                            if (xDict.ElementAt(m).Value.HasPunched == false)
                            {
                                // Draw the tool
                                punchingToolList[i].drawTool(xDict.ElementAt(m).Value.Point);
                            }
                        }
                    }

                    doc.Views.Redraw();
                }
            }

            // Display the open area calculation
            AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve);

            RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##"));

            double tool0Area = punchingToolList[0].getArea() * tool0Count;

            RhinoApp.WriteLine("Tool 1 area: {0} mm^2", tool0Area.ToString("#.##"));

            double tool1Area = punchingToolList[1].getArea() * tool1Count;

            RhinoApp.WriteLine("Tool 2 area: {0} mm^2", tool1Area.ToString("#.##"));

            openArea = (tool0Area + tool1Area) * 100 / area.Area;

            RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#."));

            doc.Views.Redraw();

            doc.Layers.SetCurrentLayerIndex(currentLayer, true);
            return(openArea);
        }
        ///<summary>The only instance of this command.</summary>
        ///<param name="doc" RhinoDoc></param>
        ///<param name="mode" Run mode></param>
        ///<returns>returns sucess if doc is successfully created </returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoApp.RunScript("Save", true); //save file before printing
            String patternFound;

            patternFound = extractToolHit(doc);         //get the pattern

            if (patternFound.Contains("Round Hole 60")) //check if pattern is a round hole 60
            {
                //set the location to round hole 60 pattern
                toolHitLocation = "W:\\Orders Current\\nOOL PDF's\\ROUND HOLE CLUSTERS\\RH60 CLUSTERS";
                //Trim the pattern, so that it only reads the tool hit size
                patternFound = patternFound.Split(new string[] { "Round Hole " }, StringSplitOptions.None)[1];
                patternFound = "RH" + patternFound;
            }

            if (patternFound.Contains("Round Hole 90")) //check if pattern is a round hole 90
            {
                //set the location to round hole 60 pattern
                toolHitLocation = "W:\\Orders Current\\nOOL PDF's\\ROUND HOLE CLUSTERS\\RH90 CLUSTERS";
                //Trim the pattern, so that it only reads the tool hit size
                patternFound = patternFound.Split(new string[] { "Round Hole " }, StringSplitOptions.None)[1];
                patternFound = "RH" + patternFound;
            }

            if (patternFound.Contains("Round Hole 45")) //check if pattern is a round hole 45
            {
                //set the location to round hole 60 pattern
                toolHitLocation = "W:\\Orders Current\\nOOL PDF's\\ROUND HOLE CLUSTERS\\RH45 CLUSTERS";
                //Trim the pattern, so that it only reads the tool hit size
                patternFound = patternFound.Split(new string[] { "Round Hole " }, StringSplitOptions.None)[1];
                patternFound = "RH" + patternFound;
            }

            toolHitPdfLocation = findToolHitPdf(patternFound, toolHitLocation);
            if (toolHitPdfLocation.Equals("Pattern not found"))
            {
                MessageBoxes.Messages.showFileNotFoundForPattern(patternFound);
                return(Result.Failure);
            }


            string fileName = Path.GetFileNameWithoutExtension(doc.Name);

            String[] nameSplit = fileName.Split(new string[] { "_" }, StringSplitOptions.None);

            //Add Nesting part to the file Name
            fileName = nameSplit[0] + "_" + nameSplit[1] + "_Nesting_" + nameSplit[2] + nameSplit[3] + "_" + nameSplit[4];

            System.Windows.Forms.PrintDialog dlg = new PrintDialog();

            if (dlg.PrinterSettings.IsValid == false)
            {
                Messages.showBullzipNotInstalled();
            }
            else
            {
                // If Page Views is 0
                if (doc.Views.GetPageViews().Count() != 0)
                {
                    try
                    {
                        tempPdfPath = Path.GetDirectoryName(doc.Path) + @"\" + "temp" + ".pdf"; //create a temporary pdf with panels
                        oriPdfPath  = Path.GetDirectoryName(doc.Path) + @"\" + fileName + ".pdf";
                        //set the tool hit layer and cluster sample layer to invisible
                        RhinoUtilities.setLayerVisibility("Tool Hit", false);
                        RhinoUtilities.setLayerVisibility("CLUSTER SAMPLE", false);
                        PdfSettings pdfSettings = new PdfSettings();
                        pdfSettings.SetValue("Output", tempPdfPath);
                        pdfSettings.SetValue("ShowPDF", "no");
                        pdfSettings.SetValue("ShowSettings", "never");
                        pdfSettings.SetValue("ShowSaveAS", "never");
                        pdfSettings.SetValue("ShowProgress", "yes");
                        pdfSettings.SetValue("ShowProgressFinished", "no");
                        pdfSettings.SetValue("ConfirmOverwrite", "no");
                        pdfSettings.WriteSettings(PdfSettingsFileType.RunOnce);

                        string command = string.Format("-_Print _Setup _Destination _Printer \"Bullzip PDF Printer\" _PageSize 297.000 210.00 _OutputType=Vector _Enter _View _AllLayout _Enter _Enter _Go");
                        RhinoApp.RunScript(command, true);

                        string[] pdfs = new String[2]; //create a string array to hold the locations of the pdf with panel and agreement form pdf.
                        pdfs[0] = tempPdfPath;
                        pdfs[1] = toolHitPdfLocation;

                        RhinoUtilities.combinePDF(oriPdfPath, pdfs, 0, 1, "Drawings Second"); //pass the array and the target location to save the final pdf
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show("Error printing PDF document." + ex.Message);
                    }
                }
            }
            return(Result.Success);
        }