Skip to main content

21 posts tagged with "Grasshopper"

View All Tags

Create custom C# component

Β· 4 min read
Marco Pellegrino
Nerd Structural Engineer

FEM-Design API is a dotnet library that can be run inside Grasshopper. Our toolbox is intensively develop and you get access to 99% of our functionality/methods.

However, there are cases where writing our own code reduce the amount of components to use and speed-up the maintenance of the code.

How do you do it? Well. I am here to get you covered. Let's start!

Our goal is to be able to create the object PeriodicDiagramRecord which can be found in FemDesign.Core.dll

record

FEM-Design Periodic excitation table

public PeriodicDiagramRecord(string name, double frequency, List<PeriodicCase> cases)

where PeriodicCase is:

public PeriodicCase(double factor, Shape phase, LoadCase LoadCase)

and Shape is:

public enum Shape
{
Cos,
Sin,
}

The step to follow will be described step by step below:

  • place an empty C# component on the canvas

step-1

  • right click on the component and select Manage Assemblies...

manage-assemblies

  • Add FemDesign.Core.dll. If you have install the API through package manager, look for the folder where Rhino install the plug-ins. (C:\Users\XXX\AppData\Roaming\McNeel\Rhinoceros\packages\7.0). Otherwise, you can download the .dll from GitHub.

reference-fem-design-core

  • Rename the input variable and specify the input type.

    name = Item Access - string
    frequency = Item Access - double
    cases = List Access - System.Object

  • Rename the output variable to periodicRecord

components

  • Double click on the C# component and write the code inside private void
var periodicCases = cases.Cast<FemDesign.Loads.PeriodicCase>().ToList();

var record = new FemDesign.Loads.PeriodicDiagramRecord(name, frequency, periodicCases);

PeriodicRecord = record;
  • On the top part of the code editor specify the library to use with using:
using FemDesign;
using FemDesign.Loads;

using System.Linq;

The code on your component should look like the following.

final-component

What the code is doing?

The following section is to specify which tools are necessary to do the job. Think of them as "softwares" that give you some functionalities.

using FemDesign;
using FemDesign.Loads;

using System.Linq;

The next section is where you create the object

var periodicCases = cases.Cast<FemDesign.Loads.PeriodicCase>().ToList();

var record = new FemDesign.Loads.PeriodicDiagramRecord(name, frequency, periodicCases);

PeriodicRecord = record;

name and frequency input variable can be use without any additional code as we have specified them as string and double respectively.

var record = new FemDesign.Loads.PeriodicDiagramRecord(name, frequency, cases);

However, in order to use our variable cases in the code, the object needs to be cast in the object type required by the method. If you remember, we specified the cases input variable as List of System.Object. The Cast method will do the action to cast the object to the right type.

var periodicCases = cases.Cast<FemDesign.Loads.PeriodicCase>().ToList();

You can now use the input and try to create a PeriodicDiagramRecord object.

periodic

You can create name as it is a string, frequency as it is a double. What about cases input?

cases is a FemDesign.Loads.PeriodicCase object and, therefore, you need to create a different component.

public PeriodicCase(double factor, Shape phase, LoadCase LoadCase)

Try to follow the step as you have done before.

periodic-case-comp

  • input type

    factor = Item Access - string
    shape = Item Access - System.Object loadCase = Item Access - System.Object

var oShape = (FemDesign.Loads.PeriodicCase.Shape) Enum.Parse(typeof(FemDesign.Loads.PeriodicCase.Shape), shape);
var periodicCase = new FemDesign.Loads.PeriodicCase(factor, oShape, (FemDesign.Loads.LoadCase) loadCase);

PeriodicCase = periodicCase;

LoadCase is something that it has already been implemented in Grasshopper so you can use the already made component without creating a new one.

workflow

Congratulations! You have finally created your own workflow to create a PeriodicExcitation object in Grasshopper :)

You can download the Grasshopper definition used in this tutorial from here πŸ‘‰Grasshopper Definition

Modify element with Python

Β· 2 min read
Marco Pellegrino
Nerd Structural Engineer

One use case where the API is leveraged is the modification of some of the properties of an object such as Slab, Bar, Axis ect ect.

The "Grasshopper way" to modify an object requires to create a new one starting from the properties of the deconstructed object and insert the new values where needed. The example below shows how to modify the thickness of a Slab.

construct-deconstruct

However, there is a better/improved/faster way to do modify properties. It only required few knowledge of programming and it is my favorite way to manipulate data inside the FEM-Design model.

Let's say that we want to modify the thickness of a slab and the identifier of a beam of an existing model.

The step to follow are:

  1. Create a python component
  2. Add the required input for your script. Zooming in the python component will allow you to add as many input as needed.
  3. Right click on the generated input in order to change the name and set the type.
  4. Write your code to modify the properties.

python

Bar example​

import copy

import clr
clr.AddReferenceToFileAndPath(r"C:\Users\Marco\AppData\Roaming\Grasshopper\Libraries\FemDesign\FemDesign.Core.dll")
#You must reference the FemDesign.Core.dll using the location on your machine


new_bar = copy.deepcopy(x)
new_bar.Identifier = identifier

One of common mistake when modifying object in Grasshopper is NOT doing the copy of the object that we want to modify. The copy will kind of detach the original object from the new one so that the modification will not be upstream.

After the copy, we need to find the properties to modify navigating through the object with the use of character .

new_bar.Identifier = identifier is selecting the Identifier of the new_bar and it is setting the identifier to it.

Slab example​

import copy

import clr
clr.AddReferenceToFileAndPath(r"C:\Users\Marco\AppData\Roaming\Grasshopper\Libraries\FemDesign\FemDesign.Core.dll")
#You must reference the FemDesign.Core.dll using the location on your machine

new_slab = copy.deepcopy(x)

new_slab.SlabPart.Thickness[0].Value = tck

The slab example is basically the same but, due to a different data structure, we need to select a list item and set the value to it.

You will end up in really clean workflow which will not scare people and easy to maintain :)

gh-workflow

You can download the Grasshopper definition used in this tutorial from here πŸ‘‰Grasshopper Definition

2L sections

Β· One min read
Marco Pellegrino
Nerd Structural Engineer

grasshopper

Double sections such as 2L are widely use in steel structures but, unfortunately, FEM-Design does not ship these kind of geometries out of the box.

However, with some few steps and the API, you can create a custom library that you can use over and over again.

Let's try to summarise the steps first.

  1. Select all the LE shape sections from the Database

step_1

  1. Apply a mirror transformation to the section surfaces. In our case, I have applied a mirror at a specific distance which represent the space between the L shapes.

step_2

  1. Construct a custom section specifying GroupName, TypeName and SizeName. The input will be used by #FEM-Design as shown in the picture below.

step_3

group

You can now import your brand new pool of sections in FEM-Design!

I have already talked about custom section and you might be interested in reading this blog post.

You can download the Grasshopper definition used in this tutorial from here πŸ‘‰Grasshopper Definition

Iterative analysis

Β· 2 min read
Marco Pellegrino
Nerd Structural Engineer

grasshopper

One of the most fascinating topics in the application of parametric design in engineering is optimization. It's hard to find an engineer who works with Grasshopper and hasn't tried their hand at optimizing using Galapagos. This process can often be quite straightforward as we can obtain real-time outputs like mass, deflection, and utilization by adjusting various parameters.

So, how do we go about it? The following example should help illustrate the setup:

  • the analysis (static analysis)
  • the design settings (check, auto-design, apply changes)
  • the design parameters (utilisation)

Design settings and parameters​

grasshopper

Design parameters are currently linked to a text file. The cfg.xml file template can be found in the plug-in folder installed by Package Manager in %AppData%\McNeel\Rhinoceros\packages\7.0\FemDesign\

The file has several parameters that you can modify as you pleased. In case of steel bars, you can use something like the following:

<?xml version="1.0" encoding="UTF-8"?>
<configs>
<CONFIG fIgnoreAnnexForShearStrength="false" StripeWidth="1" type="CCMSCONFIG"></CONFIG>
<CONFIG type="CCCOCONFIG"></CONFIG>

<!-- EUROCODE STEEL CONFIG -->
<CONFIG sInteraction="0" type="ECSTCONFIG"></CONFIG>

<!-- DESIGN PARAMETERS STEEL BAR -->
<CONFIG LimitUtilization="0.8" type="CCDESPARAMBARST" vSection_itemcnt="24"></CONFIG>

<!-- EUROCODE CALCULATION PARAMETERS STEEL BAR -->
<CONFIG aBucklingCurve_fx1="-1" aBucklingCurve_fx2="-1" aBucklingCurve_ltb="-1" aBucklingCurve_ltt="-1" aBucklingCurve_tf="-1" CheckResistanceOnly="1" class4Ignored="1" convergencyratio="1" fLatTorBuckGen="1" fLatTorBuckGenSpecForI="0" maxIterStep="50" plasticIgnored="0" rStep="0.5" s2ndOrder="1" type="ECCALCPARAMBARST" UseEqation6_41="0"></CONFIG>
</configs>

FEM-Design will be instructed to apply those settings and the design will reflect the parameters.

You can download the Grasshopper definition used in this tutorial from here πŸ‘‰Grasshopper Definition

πŸ“ Download FEM-Design API
🌍 Documentation

Leverage interaction surface

Β· One min read
Marco Pellegrino
Nerd Structural Engineer

grasshopper

While preparing a webinar regarding FEM-Design API by StruSoft together with Isak Bjârhag, we have got the idea to showcase how the engineers can use our tool to optimise the selection of a cross section with the help of some grasshopper spaghetti 🍝

The outcome was really fascinating as I have never seen several interaction surface together and I have never noticed the effect of the parameters on the final capacity πŸ‘€

Visualisation is definitely a key aspect. Our eyes are not been "constructed" to understand a lot of numbers together

You can download the Grasshopper definition used in this tutorial from here πŸ‘‰Grasshopper Definition

πŸ“ Download FEM-Design API
🌍 Community

Export results to csv

Β· One min read
Marco Pellegrino
Nerd Structural Engineer

grasshopper

FEM-Design API is mostly developed to give users access to most of the model data. We believe that users should not be constrained by our idea of engineering, but they should have the freedom to manipulate the data in a way that works best for them!

FEM-Design, the main software, has a really pleasant user interface that exports all the results with good logic.

However, the API will give you the freedom to nest/manipulate the data in any way you want and export it with a small script. In the picture above, I have shown how straightforward it is to save some data to a text file.

You can download the Grasshopper definition used in this tutorial from here πŸ‘‰Grasshopper Definition

πŸ“ Download FEM-Design API
πŸ“° Newsletter
🌍 Community

Dev meeting 22.7.0

Β· One min read
Marco Pellegrino
Nerd Structural Engineer

grasshopper

We hope that everyone enjoyed our recent webinar and we are delighted to provide you with access to all the content!

Download the Grasshopper definitions used in the meeting from here πŸ‘‰Grasshopper Definition
Download the pdf presentation used in the meeting from here πŸ‘‰pdf presentation

Below, you can find a quick preview of what it has been discuss.

grasshopper grasshopper grasshopper grasshopper grasshopper grasshopper grasshopper

πŸ“ Download FEM-Design API
πŸ“° Newsletter
πŸ™‹ Community

Any geometry to slab

Β· One min read
Marco Pellegrino
Nerd Structural Engineer

grasshopper

I recently came across an interesting case from one of our users who was trying to analyse a free-form surface.

FEM-Design is mostly use for slab and wall (both geometry are flat) but the user needs the software to calculate something different. Something that it is nowadays called "free-form"!

How can we overcome the issue?

Discretization is the key concept! What you can do, it is to subdivide the surface in several small triangles and feed FEM-Design with those.

grasshopper

You can download the Grasshopper definition used in this tutorial from here πŸ‘‰Grasshopper Definition

πŸ“ Download FEM-Design API
πŸ“ Download StruSoft Trial Version
πŸ“° Newsletter
πŸ™‹ Help

Hex Dome

Β· One min read
Marco Pellegrino
Nerd Structural Engineer

grasshopper

I want to share some insights on optimizing the direction of CLT Panel wit FEM-Design API by StruSoft. 🧐

When designing CLT panels, one of the key considerations is ensuring that the panel is placed in the right direction to enhance the slab's strength and durability.

But how can we make such models without becoming crazy? 🀯 FEM-Design API has the solution for you.

Do you think that the structure that I have shown is pure theory? πŸ™„ Have a look at Format Engineers.

PS: Have you noticed the n-gon planar panels? πŸ€“

You can download the Grasshopper definition used in this tutorial from here πŸ‘‰Grasshopper Definition

πŸ“ Download FEM-Design API
πŸ“ Download StruSoft Trial Version
πŸ™‹ Help

Topology optimisation

Β· 2 min read
Marco Pellegrino
Nerd Structural Engineer
Isak BjΓΆrhag
Business Development Manager

preview

It’s time for some topology optimization! More specifically multivariable optimization of a parametric timber truss. πŸ€“

In this example I have created a timber truss with 4 variables that describe the shape of it. This is a very practical way of going about a topology optimization since you can limit the possible shapes due to production limitations to achieve an optimized structure that doesn’t look like a warped alien spaceship πŸš€ 😊

This parametrization gave approximately 100 000 different shapes which is too many to try them all (brute force). Instead, I used Grasshopper and Galapagos to utilize some machine learning to reduce the time to find an optimal solution.

Watch the video

I also utilized the design groups in the FEM-Design API so that all truss elements had the same section as well as the above and below beam. I also instructed FEM-Design to carry out an auto design of each shape to obtain viable solutions with below 100% utilization of the cross sections. I opted to optimize with regard to timber weight to minimize material, but you can create another fitness function to optimize for price, deflection, CO2 emissions or why not a combination of them all.

πŸ”₯ If you are interested in this type of workflow don’t miss our upcoming free webinar on the topic, register here: https://lnkd.in/deG2pEh3

🌟 Free trial of FEM-Design and the API: https://lnkd.in/dVMqMszZ

Watch the video πŸ‘‡

Watch the video

πŸ“ Download FEM-Design API
πŸ“ Download StruSoft Trial Version
🌟 Community
πŸ™‹ Help