english_1_3_3

3.4: Input- and Output-Plugs

Now it is time to add the input- and output-plugs to the new component. This is the listing of the first few lines of “TensionElimComponent.cs” which implements this functionality:

using System;
using System.Collections.Generic;

using Grasshopper.Kernel;

using Karamba.Models;
using Karamba.GHopper.Models;

namespace TensionElim {
    public class TensionElimComponent : GH_Component
    {
        public TensionElimComponent()
            : base("TensionElim", "TenElim ",
                ".", " Karamba " , " E x t r a " )
                {
                }

                protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
                {
                    pManager.AddParameter(new Param_Model(), "Model_in", "Model_in",
                        "Model to be manipulated", GH_ParamAccess.item);
                }

                protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
                {
                    pManager.RegisterParam(new Param_Model(), "Model_out", "Model_out",
                        "Model after eliminating all tension elements");
                    pManager.Register_BooleanParam("isActive", "isActive",
                        "List of boolean values corresponding to each element in the model." +
                        "True if the element is active.");
                    pManager.Register_NumberParam("maximum displacement", "maxDisp",
                        " Maximum displacement [m] of the model after eliminationprocess.");
                }
        ...
    }

Line 1 to 4 get automatically created by the GH-wizard. Lines 6 and 7 are important: they make the classes available (i.e. Model, Param_Model, GH_Model, Element, ...) which reside in the namespaces “Karamba.Models” and “Karamba.GHopper.Models”. This allows to define the component input in lines 20 and 21. Objects that are used as component input or output need to be wrapped so that GH can handle them. In Karamba3D these wrapper classes are named after the class they wrap preceded by “Param_” and “GH_”. Lines 26 to 32 specify the output plugs. Supplement “TensionElim- Component.cs” with the above lines, compile the project and copy the resulting “TensionElim.gha” as before. Restart Rhino. Fig. 3.4.1 shows the component with input and output-plugs.

Last updated