Scripting Guide 3.1.4
  • Welcome to Karamba3D Scripting Guide
  • 1. Introduction
    • 1.1: Scripting with Karamba3D
    • 1.2: Basics
  • 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
    • 2.8: The Python 3 Component
      • 2.8.1: Hello Karamba3D
      • 2.8.2: Data Retrieval from Models
      • 2.8.3: How to Create Structural Models
      • 2.8.4: How to Modify Structural Models
        • 2.8.4.1: Cross section Optimization
        • 2.8.4.2: Activation and Deactivation of Elements
  • 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
  • Independence from Grasshopper
  • Karamba3D's Geometry Types
  • Managing Karamba3D Models: Static Classes and Factories
  1. 1. Introduction

1.2: Basics

Previous1.1: Scripting with Karamba3DNext2.1: Hello Karamba3D

Last updated 6 months ago

Independence from Grasshopper

Karamba3D can operate independently of Grasshopper and Rhino. The provides an overview of its namespaces:

  • Namespaces under Karamba.GHopper These are linked to Grasshopper functionality and are contained within the karamba.gha file. They connect Karamba3D’s C# API to Grasshopper.

  • Other Namespaces All remaining namespaces reside within the karambaCommon.dll file and can be utilized without relying on Grasshopper or RhinoCommon.dll. This allows for standalone use of Karamba3D’s core functionalities.

Karamba3D's Geometry Types

The Karamba.Geometry namespace defines the geometry types used in Karamba3D. These types generally mirror Grasshopper's geometry types but without the "D" suffix. For example:

  • Grasshopper’s Vector3D corresponds to Karamba3D’s Vector3.

Type Conversion Utilities

  • Karamba.GHopper.Utilities.FromGH This static class provides methods for converting Grasshopper-wrapped types (e.g., GH_Vector) to Karamba3D types.

  • Karamba.GHopper.Utilities.ToGH This static class provides methods for converting from Karamba3D to Grasshopper-wrapped types.

  • Karamba.GHopper.Geometry Namespace This namespace includes the ToKarambaCommon and ToRhino classes. Thes extends Grasshopper and Karamba3D geometry classes with the Convert method. This method enables bi-directional type conversion between Grasshopper and Karamba3D geometry types.

Managing Karamba3D Models: Static Classes and Factories

Most Karamba3D components visible in Grasshopper are backed by static classes within karambaCommon.dll. These static classes perform the core computations. While it is possible to manage Karamba3D models directly using these classes, this approach ties scripts to their specific interface definitions, which may change over time.

Factory-Based Approach for Stability

To provide a more stable API, a factory hierarchy has been implemented under the KarambaCommon.Factories namespace. This approach is recommended for setting up and managing Karamba3D models.

  • Access via the Toolkit Class The Toolkit class serves as an entry point to the factory system, offering a more robust and user-friendly method to create and manage Karamba3D models. It also provides sensible default values for many arguments, simplifying setup.

Current and Future Features

  • Not all Karamba3D features are currently accessible through the Toolkit.

  • The Toolkit will be expanded in future versions and is the preferred method for interacting with Karamba3D.

Learning Resources

For examples of how to use the Toolkit and factory system, refer to the Karamba3D unit-test project: . These test cases demonstrate practical usage of the API and provide valuable insights for developers.

API documentation
https://github.com/karamba3d/K3D_tests