(EN) MIDAS Civil with Python

This document is a manual for executing the MIDAS Civil API with Python.

 

1. Setting a Python Development Environment

1.1 Python Install download

Download an installing file from the Python official website.

Welcome to Python.org

Python official website

* You can find various OS installers besides the Window.

 

1.2 Install Python

Install Python.

Python installation window

These editors offer a convenient developing environment for users.

Recommended Code Editors for Python

(This manual is written using Visual Studio Code.)

 

1.3 Install additional module

You can control MIDAS/Civil API only when installing the Request Module in Python.

The Request Module can be installed as follows.

When you cannot see the under a terminal window, use Menu-Terminal-New Terminal, then run the Terminal window. Copy and Paste under the text, and press the Enter key.

py -3 -m pip install requests

 

 

2. Operating MIDAS/Civil API using Python

Let’s see how MIDAS/Civil API works with simple examples.

2.1 Operating MIDAS/Civil API

To communicate with the API, Civil is executable as follows.

 

  • Python Code

import subprocess import time p = subprocess.Popen([r"C:\\CivilBuild-API\\CVLw.exe", "/API"]) ## wait until civil api process ready time.sleep(10)

The user can change the MIDAS/Civil file path depending on their work environment.

 

2.2 Open MIDAS/Civil API documnent

We are opening a saved file after executing MIDAS/Civil API.

 

  • Python Code

import requests CIVIL_API_URL = "http://127.0.0.1:10024" ## DOC.OPEN requests.post(CIVIL_API_URL + "/doc/open", json={"Argument":"C:\\FSM 1Cells Box.mcb"})

The user can change the MIDAS/Civil file path depending on their work environment.

The user can find an URL in the APIServer.exe when executing MIDAS/Civil through API.

 

2.3 MIDAS/Civil API - Run the Analysis and Close program

Now, run the analysis with opened MIDAS/Civil file and close the Civil.

 

  • Python Code

 

3. Command for operating

3.1 DOC Command

DOC command controls documents such as create/open/close files

 

  • Open file: “/doc/open”

 

  • Open New: “/doc/new”

 

  • Close file: “/doc/close”

 

  • Run analysis: “/doc/anal”

 

  • Save file: “/doc/save”

 

  • Save as: “/doc/saveas”

 

  • Json data(file) Import : “/doc/import”

 

  • Json data(file) Export : “/doc/export”

 

3.2 DB Command

DB Command requests the data name. Each Data name is embodied GET/POST/PUT/DELETE methods.

  • GET DB Method: inquiry opened file data.

 

Example1: This example code calls all Nodes information from the opened file and prints specific Node information.

 

Example2: The following code calls only specific Node information from the opened file.

 

  • Post DB Method: Add data to the opened file. If the key-value exists, then it will get an error.

 

The following example adds a specific Node to the opened file and prints that Node information.

 

  • Put DB Method: Change data to the opened file. If you request the key value that does not exist, it will get an error.

The following example changes the coordinates of a specific node.

 

  • Delete DB Method: Delete the opened file data. If you request the key value that does not exist, it will get an error.

Example1: Delete the specific Node, and print that deleted Node information.

 

Example2: Delete all Nodes.

 

3.3 POST Command

Post Command is post-process operators after analysis.

 

  • Call result table: “/doc/table”

When you call the results table, you can use this data in both ways - saved/ w/o saved file. The first example shows when you save the file, and the second example shows without the saved file.

Example 1: This example calls the analyzed results from the opened document and saves them in JSON format. (The yellow box indicated saved file path.)

 

Example 2: Call the analyzed results from the opened file, and print the first node results. (The results would be the same as the right upper “Data” results.)

 

3.4 VIEW Command

View Command takes images in Post-process.

 

  • Diagram call: “/view/capture”

This example shows how to call the Diagram and save it where you want to.