Exemplo n.º 1
0
        /// <summary>
        /// Creates the panel with the signal name and connects it to the input parameter
        /// </summary>
        /// <param name="text"> The signal name. </param>
        private void CreatePanel(string text)
        {
            // Create a panel
            Grasshopper.Kernel.Special.GH_Panel panel = new Grasshopper.Kernel.Special.GH_Panel();

            // Set the text with the signal name
            panel.SetUserText(text);

            // Change the color of the panel
            panel.Properties.Colour = System.Drawing.Color.White;

            // Get the current active canvas / document
            GH_Document doc = Grasshopper.Instances.ActiveCanvas.Document;

            // Add the panel to the active canvas
            doc.AddObject(panel, false);

            // Change the size of the panel
            panel.Attributes.Bounds = new System.Drawing.RectangleF(0.0f, 0.0f, 80.0f, 25.0f);

            // Set the location of the panel (relative to the location of the input parameter)
            panel.Attributes.Pivot = new System.Drawing.PointF(
                (float)this.Attributes.DocObject.Attributes.Bounds.Left - panel.Attributes.Bounds.Width - 30,
                (float)this.Params.Input[1].Attributes.Bounds.Y - 2);

            // Connect the panel to the input parameter
            Params.Input[1].AddSource(panel);
        }
Exemplo n.º 2
0
        // This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Component Component           = this;
            GH_Document   GrasshopperDocument = this.OnPingDocument();

            // Creating input parameters
            List <string> data      = new List <string>();
            string        groupName = "";
            bool          trigger   = false;
            object        template  = null;

            // Getting the data from Grasshopper
            DA.GetDataList <string>(0, data);
            DA.GetData <string>(1, ref groupName);
            DA.GetData <object>(2, ref template);
            DA.GetData <bool>(3, ref trigger);

            // If the botton is pressed it will proceed
            if (!trigger)
            {
                return;
            }

            // Detecting the the source parameter for the templateInput
            Grasshopper.Kernel.IGH_Param         templateInput = Component.Params.Input[2];
            IList <Grasshopper.Kernel.IGH_Param> sources       = templateInput.Sources;

            if (!sources.Any())
            {
                return;
            }
            IGH_DocumentObject templateComp = sources[0].Attributes.GetTopLevel.DocObject;


            // Gets component attributes like the bounds of the Panel which is used to shift
            //the next one and get the size of the panels
            IGH_Attributes att    = templateComp.Attributes;
            RectangleF     bounds = att.Bounds;
            int            vShift = (int)Math.Round(bounds.Height) + 10;
            float          refX   = bounds.X;
            float          refY   = bounds.Y + 30 + vShift;

            // Creating a Grasshopper Group g and assignning a nickname and color to it.
            //Adding group g to the GrasshopperDocument
            Grasshopper.Kernel.Special.GH_Group g = new Grasshopper.Kernel.Special.GH_Group();
            g.NickName = groupName;
            g.Colour   = Grasshopper.GUI.Canvas.GH_Skin.group_back;
            GrasshopperDocument.AddObject(g, false);
            List <IGH_Component> components = new List <IGH_Component>();


            // For-loop used to create panels and assign properties to it (size, datalist...)
            int nbCopy = data.Count;

            for (int i = 0; i < nbCopy; i++)
            {
                Grasshopper.Kernel.Special.GH_Panel panel = new Grasshopper.Kernel.Special.GH_Panel();
                panel.CreateAttributes();
                panel.SetUserText(data[i]);
                panel.Attributes.Bounds = bounds;
                panel.Attributes.Pivot  = new PointF(refX, refY + i * vShift);
                GrasshopperDocument.AddObject(panel, false);

                g.AddObject(panel.InstanceGuid);
            }
            GrasshopperDocument.DeselectAll();
        }