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
  1. 2. Scripting with Karamba3D inside Grasshopper
  2. 2.8: The Python 3 Component

2.8.1: Hello Karamba3D

Previous2.8: The Python 3 ComponentNext2.8.2: Data Retrieval from Models

Last updated 6 months ago

In order to get started with Python3 scripting in Grasshopper place a "Python 3 Script"-component on the canvas. Details regarding its functionality can be found .

When Karamba3D is installed in your Grasshopper the following code retrieves properties of a Karamba3D model:

import Karamba

model = Model_in;

if not isinstance(model, Karamba.Models.Model):
    raise Exception("The input is not of type 'Model'")

print(f"Number of Elements: {model.elems.Count}")
print(f"Number of Materials: {model.materials.Count}")
print(f"Number of Cross sections: {model.crosecs.Count}")

The source code is explained in .

section 2.1
here
13KB
HelloKaramba3D_Py3.gh
Fig. 2.8.1.1: A minimal K3D-model for retrieving the number of elements, materials and cross sections via Python 3.