Scripting Guide v2
  • Welcome to Karamba3D Scripting Guide
  • Go to Scripting Guide 1.3.3
  • Go to Manual
  • 1. Introduction
    • 1.1: Scripting with Karamba3D
    • 1.2: What's New in Karamba3D 1.3.3 Regarding Scripting
  • 2. Scripting with Karamba3D inside Grasshopper
    • 2.1: Hello Karamba3D
    • 2.2: Data Retrieval from Models
    • 2.3: How to Create Structural Models
    • 2.4: How to Modify Structural Models
      • 2.4.1: Cross section Optimization
      • 2.4.2: Activation and Deactivation of Elements
    • 2.5: Data Export from Karamba3D
    • 2.6: The VB Script Component
    • 2.7: The IronPython Component
      • 2.7.1: Results Retrieval on Shells
      • 2.7.2: A Simplified ESO-Procedure on Shells
  • 3. How to create your own Karamba3D Grasshopper-component
    • 3.1: Setting up a Visual Studio Project for GH Plug-ins
    • 3.2: Basic Component Setup
    • 3.3: How to Reference Karamba3D Assemblies
    • 3.4: Input- and Output-Plugs
    • 3.5: Adding Functionality to a GH Component
  • Bibliography
Powered by GitBook
On this page

Was this helpful?

  1. 3. How to create your own Karamba3D Grasshopper-component

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;
using Karamba.Loads.Combinations;

namespace TensionElim {
    public class TensionElimComponent : GH_Component
    {
        public TensionElimComponent()
            : base("TensionElim", "TenElim",
                ".", "Karamba" , "Extra" )
                {
                }

                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.

Previous3.3: How to Reference Karamba3D AssembliesNext3.5: Adding Functionality to a GH Component

Last updated 3 years ago

Was this helpful?

Fig. 3.4.1: Second step: Custom component with input- and output-plugs but no functionality yet.