This document is a MIDAS API example using Grasshopper(Rhino’s Parametric Modelling Tool).
1. Download Rhino Download an installing file from the Rhino official website.
Rhino - Rhinoceros 3D (rhino3d.com)
2. Install CPython Editor Grasshopper provides the following three Sctipt Editors.
Script Editor (Python, C#, VB)
Through the example in the link below, we will install the Script Editor, which can use the previously installed Python(CPython), and operate the MIDAS API.
MIDAS Civil/Gen with Python - MIDAS API - Confluence (atlassian.net)
Download the CPython editor in the link below.
GH_CPython | Food4Rhino
As above the figure, open the Grasshopper Libraries and copy or move downloaded files.
Then, register GH_CPython.gha by Drag&Drop.
3. Example This example implemented two examples.
Change the Geometry of Beam depending on R-value
Change the section shape and size
Used Python code in this example as below.
Geometry_R
## UPDATE NODE COORDINATES
##
import requests
import json
import math
## Localhost address of MIDAS/Civil
CIVIL_LOCALHOST = "http://127.0.0.1:10024"
## Input
R = _R
## Get node informations
getNode = requests.get(CIVIL_LOCALHOST + "/db/node", json={}).text
NODE = json.loads(getNode)["NODE"]
## Assign Node number as List
nodNb = list(NODE.keys())
## Calculation Elements Length
lenEl = []
i = 0
for i in range(len(nodNb)-1):
Xi = NODE[nodNb[i]]["X"]
Yi = NODE[nodNb[i]]["Y"]
Xj = NODE[nodNb[i+1]]["X"]
Yj = NODE[nodNb[i+1]]["Y"]
lenEl += [math.sqrt((Xj-Xi)**2+(Yj-Yi)**2)]
## Calculation Node Coordinates
Xrc = 0.0
Yrc = -R
i = 0
Theta = 0.0
AccLen = 0.0
if R==0:
for i in range(len(nodNb)-1):
AccLen += lenEl[i]
NODE[nodNb[i+1]]["X"] = AccLen
NODE[nodNb[i+1]]["Y"] = 0
else:
for i in range(len(nodNb)-1):
Theta += 2 * math.asin(lenEl[i]/(2*R))
NODE[nodNb[i+1]]["X"] = Xrc + math.sin(Theta)*R
NODE[nodNb[i+1]]["Y"] = Yrc + math.cos(Theta)*R
NODE = {
"Assign":NODE
}
requests.put(CIVIL_LOCALHOST + "/db/node", json=NODE)
Json_=json.dumps(NODE,sort_keys=True,indent=4)
Section_Properteis
## Section Properteis
##
import requests
import json
import math
## Localhost address of MIDAS/Civil
CIVIL_LOCALHOST = "http://127.0.0.1:10024"
## Input
var1 = _var1
var2 = _var2
var3 = _var3
var4 = _var4
var5 = _var5
var6 = _var6
var7 = _var7
var8 = _var8
## Get section informations
getSect = requests.get(CIVIL_LOCALHOST + "/db/sect", json={}).text
SECT = json.loads(getSect)["SECT"]
## Section properteis
secNb = list(SECT.keys())
if var1=="H":
secSh = "H"
secPr = [var2,var3,var4,var5,var6,var7]
elif var1=="T":
secSh = "T"
secPr = [var2,var3,var4,var5]
elif var1=="B":
secSh = "B"
secPr = [var2,var3,var4,var5,var6,var7]
elif var1=="P":
secSh = "P"
secPr = [var2,var4]
## Update Section Properteis
SECT[secNb[0]]["SECT_BEFORE"]["SECT_I"]["vSIZE"]=secPr
SECT[secNb[0]]["SECT_BEFORE"]["SHAPE"]=secSh
SECT[secNb[0]]["SECT_BEFORE"]["OFFSET_PT"]=var8
SECT = {
"Assign":SECT
}
requests.put(CIVIL_LOCALHOST + "/db/sect", json=SECT)
Json_=json.dumps(SECT,sort_keys=True,indent=4)
When the Python editor does not work
Check if the Request module is installed in the existing installed Python.
If it is installed, directly designate the Python.exe path as shown in the figure below.