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.3: How to Create Structural Models

Previous2.8.2: Data Retrieval from ModelsNext2.8.4: How to Modify Structural Models

Last updated 6 months ago

The detailed account of the equivalent C# example can be found in . Here the Python 3 sourcecode and the Grasshopper definition:

from Karamba.Utilities import MessageLogger
from Karamba.Geometry import *
import Karamba.Loads
from System.Collections.Generic import List
from System import String

import KarambaCommon

logger = MessageLogger()
k3d = KarambaCommon.Toolkit()

p0 = Point3(0, 0, 0)
p1 = Point3(0, 0, 5)
L0 = Line3(p0, p1)

bending = True
limitDist = 0.005
elems, nodes = k3d.Part.LineToBeam(L0, "B1", None, logger)

cond = [True, True, True, True, True, True]
support = k3d.Support.Support(0, cond)
supports = [ support ]

pload = k3d.Load.PointLoad(1, Vector3(0, 0, -10), Vector3())
ploads = [ pload ]

# for Karamba3D Version <= 3.1.41119
model, info, mass, cog, info, runtimeWarning = k3d.Model.AssembleModel(
    elems, 
    supports, 
    List[Karamba.Loads.Load](ploads))

# for Karamba3D Version > 3.1.41119
# model, info, mass, cog, info, runtimeWarning = k3d.Model.AssembleModel(
#     elems, 
#     supports, 
#     ploads)    

# for Karamba3D Version <= 3.1.41119
loadCases = List[String](["LC0"])

# for Karamba3D Version > 3.1.41119
# loadCases = ["LC0"]

model_analysed, maxDisp, outForce, outEnergy, Warning = k3d.Algorithms.Analyze(model, loadCases)

ucf = Karamba.Utilities.UnitsConversionFactory.Conv();
cm = ucf.cm();
print(f"max disp: {cm.toUnit(maxDisp[0])}" + cm.unitB);

Model_out = Karamba.GHopper.Models.GH_Model(model_analysed);

section 2.3
24KB
ModelCreation_Py3.gh