LS Structure Engineering and Research Structural Engineering Volume 1 Etabs Automation: Building Models with Python Fabriccio Livia Saenz Structural Engineering Lima, Perú March 2024 Abstract: This chapter explores the automation of structural modeling using the CSI Etabs API and Python, presenting a step-by-step tutorial for creating the model of a 50-story structure. The tutorial covers the connection to Etabs, configuration of the model, and the generation of grids, frame elements, columns, and slabs. The CSI Etabs API, in conjunction with Python, emerges as a valuable resource for civil engineers, structural engineers, programmers, students, and specialists seeking to enhance their capabilities in automated structural design. Keywords: Parametric Building Model, CSI Etabs API, Python, Structural Engineering, Automation, Building Modeling, Structural Elements. 1 Introduction 2 Fundamentals of Automation in Structural Engineering Automation in building modeling is crucial for optimizing processes and providing flexibility in structural design [7]. This article presents a detailed tutorial on using the CSI Etabs API and Python to create a parametric building model. This approach provides civil and structural engineers with a powerful tool to explore various design options and efficiently perform parametric analyses. Programming in structural engineering not only saves time but also enables exploration of new ideas and innovative solutions to structural design and analysis challenges [4]. In this context, the CSI Etabs API and Python become valuable tools for structural engineers. Figure 1: Parametric Building Model [Extracted from Etabs 2021] Figure 2: Input Data [Extracted from Visual Studio Code] 1 LS Structure Engineering and Research 3 Connecting to Etabs and Configuring the Model 1 2 3 4 5 6 7 import import import import import import import print ( " Cannot start a new instance of the program from " + ProgramPath ) sys . exit ( -1) else : try : # create an instance of the ETABS object from the latest installed ETABS myETABSObject = helper . CreateObjectProgID ( " CSI . ETABS . API . ETABSObject " ) except ( OSError , comtypes . COMError ) : print ( " Cannot start a new instance of the program . " ) sys . exit ( -1) 15 16 To begin, it is necessary to establish a connection with Etabs through Python [1]. In this example, the CSI Etabs API is used to initialize a new model, define properties, and create grids that will serve as the foundation for generating the structure [8]. In this initial block, the necessary libraries are imported, and the connection with ETABS is configured. The API helper object is created, and whether to attach to an existing instance or start a new one is determined. After the connection is established, a SapModel object is created to interact with the ETABS model, and a new model is initialized. Structural Engineering Volume 1 17 18 19 20 21 22 23 Listing 4: Connecting to Etabs 1 os sys comtypes . client math matplotlib . pyplot as plt numpy as np pandas as pd myETABSObject . ApplicationStart () Listing 5: Start ETABS Application 1 ret = SapModel = myETABSObject . SapModel Listing 6: Create SapModel object Listing 1: Importing Python Libraries 1 1 2 3 Listing 7: Initialize model AttachToInstance = False SpecifyPath = False ProgramPath = " C :\ Program Files \ Computers and Structures \ ETABS 21\ ETABS . exe " 4 Listing 2: Specify the Etabs Path 1 2 2 3 4 5 6 7 8 9 10 11 12 13 14 Defining variables for model parameters In this section, various parameters are defined to shape the structural model. The meaning of each variable is analyzed below: helper = comtypes . client . CreateObject ( ’ ETABSv1 . Helper ’) helper = helper . QueryInterface ( comtypes . gen . ETABSv1 . cHelper ) • NumPisos: This variable represents the total number of floors in the building. In the provided example, it is set to 50, indicating a multi-story structure. Listing 3: Create API Helper Object 1 ret = SapModel . InitializeNewModel () if AttachToInstance : # attach to a running instance of ETABS try : # get the active ETABS object myETABSObject = helper . GetObject ( " CSI . ETABS . API . ETABSObject " ) except ( OSError , comtypes . COMError ) : print ( " No running instance of the program found or failed to attach . " ) sys . exit ( -1) else : if SpecifyPath : try : # ’ create an instance of the ETABS object from the specified path myETABSObject = helper . CreateObject ( ProgramPath ) except ( OSError , comtypes . COMError ) : • AlturaPiso1: The height of the first floor of the building. This value is set to 4 meters in the example. • AlturaPisoTipico: The height of typical floors in the building. For all floors beyond the first one, this value is used to determine their height. In the example, it is set to 3 meters. • numx: The number of grid divisions along the xaxis. This parameter determines the number of columns, beams, and slabs along the horizontal direction. In the example, it is set to 3. 2 LS Structure Engineering and Research • Set units: The SetPresentUnits function is utilized to establish the units for the analysis. The variable TonfmC is set to 12, indicating that the units for the analysis are in tons, meters, and degrees Celsius. Ensuring consistent and appropriate units is vital for accurate structural analysis. This step establishes the unit system used throughout the modeling and analysis processes. • numy: The number of grid divisions along the yaxis. Similar to numx, this parameter controls the layout of structural elements along the vertical direction. It is also set to 3 in the example. • Espaciamientox: The spacing between columns along the x-axis. This parameter influences the distance between structural elements in the horizontal direction. In the example, it is set to 3.5 meters. 1 • Espaciamientoy: The spacing between columns along the y-axis. Similar to Spacingx, this parameter determines the distance between elements in the vertical direction. It is also set to 3.5 meters in the example. 1 2 3 4 5 6 7 2 6 Frame elements creation frame section properties and Here, the section properties for a frame element (beam) are defined. In this case, a rectangular profile with specific dimensions is used. • Parameters passed to the function: Listing 8: Defining variables for model parameters – V: Indicates that the section properties are being set for vertical frame elements (beams). Create grids and set units It continue with the generation of grids, frame elements, and columns at the intersections of the grids. Section properties are defined, and structural elements are created following a parametric pattern. – 4000Psi: Specifies the material property of the frame. – 0.5: Depth of the rectangular section (beam) in model units. • Create grids: The NewGridOnly function is called to generate the structural grid. This function takes various parameters to define the grid, such as the number of floors (NumPisos), the height of typical floors (AlturaPisoTipico), the height of the first floor (AlturaPiso1), the number of divisions along the x and y axes (numx and numy), and the spacings between grid lines (Espaciamientox and Espaciamientoy).The grid organize the layout of structural elements within the model. It defines the intersections where columns, beams, and other components are positioned. – 0.25: Width of the rectangular section (beam) in model units. • Frame section properties: The SetRectangle function defines the shape and material properties of the frame section. The choice of section properties, such as depth and width, influences the behavior of the frame element in the structural analysis. 1 1 Tonf_m_C =12 ret = SapModel . SetPresentUnits ( Tonf_m_C ) Listing 10: Set units Num_Pisos =50 Altura_piso1 =4 Altura _p is o_ ti pi co =3 numx =3 numy =3 Espaciamientox =3.5 Espaciamientoy =3.5 5 Structural Engineering Volume 1 ret = SapModel . File . NewGridOnly ( Num_Pisos , Al tu ra _p is o_ tipico *3.28084 , Altura_piso1 *3.28084 , numx , numy , Espaciamientox *3.28084 , Espaciamientoy *3.28084) ret = SapModel . PropFrame . SetRectangle ( ’V ’ , ’ 4000 Psi ’ , 0.5 , 0.25) # name # material # h # b Listing 11: Frame elements creation and define rectangular frame section properties Listing 9: Create grids 3 LS Structure Engineering and Research 7 Create beams horizontal and vertical 8 • Loop through grid intersections: Two nested loops (for i in range(1, numx + 1): and for j in range(1, numy + 1):) iterate through each intersection point of the grid defined by the variables numx and numy. • Loop through floors and create beams: The code iterates through each floor level in the range from 1 to the total number of floors (NumPisos). The variable AlturaNivel is determined based on whether it’s the first floor or a typical floor. • Determine column coordinates: The coordinates xcoord and ycoord are calculated based on the current grid intersection, spacing, and loop indices. These coordinates represent the base (bottom) of the column. • Create horizontal beams: Nested loops are used to create horizontal beams for each span in the y-direction. The coordinates (x1, y, AlturaNivel, x2, y, AlturaNivel) define the start and end points of each horizontal beam. SapModel.FrameObj.AddByCoord is called to add a frame element (beam) based on the specified coordinates. • Loop through floors: Another loop (for k in range(1, NumPisos + 1):) iterates through each floor level. • Determine column height: The variables zcoord1 and zcoord2 represent the bottom and top heights of the column for the current floor level. These heights are determined based on whether it’s the first floor or a typical floor. • Create vertical beams: Nested loops are used to create vertical beams for each span in the xdirection. The coordinates (x, y1, AlturaNivel, x, y2, AlturaNivel) define the start and end points of each vertical beam. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Create column In this block, columns are created at the intersections of the grids on each level of the building. This block utilizes loops to create horizontal and vertical beams on each floor of the building. The coordinates of the beam ends are specified based on the established grids. 1 Structural Engineering Volume 1 • Create column: SapModel.FrameObj.AddByCoord is called to add a frame element (column) based on the specified coordinates and heights. The frame type is set to ’ConcCol’, indicating a concrete column. for nivel in range (1 , Num_Pisos + 1) : # Create the height of the current level if nivel == 1: altura_nivel = Altura_piso1 else : altura_nivel = Altura_piso_tipico * ( nivel - 1) + Altura_piso1 # Create horizontal beams in sections for j in range ( numy ) : for i in range ( numx -1) : x1 = i * Espaciamientox x2 = ( i +1) * Espaciamientox y = j * Espaciamientoy ret = SapModel . FrameObj . AddByCoord ( x1 , y , altura_nivel , x2 , y , altura_nivel , " " , " V " , ’ ’ , ’ Global ’) # Create vertical beams in sections for i in range ( numx ) : for j in range ( numx -1) : x = i * Espaciamientox y1 = j * Espaciamientoy y2 = ( j +1) * Espaciamientoy ret = SapModel . FrameObj . AddByCoord (x , y1 , altura_nivel , x , y2 , altura_nivel , " " , " V " , ’ ’ , ’ Global ’) ret = SapModel . View . RefreshView (0 , False ) 1 2 3 4 5 6 7 8 9 for i in range (1 , numx +1) : for j in range (1 , numy +1) : x_coord = (i -1) * Espaciamientox y_coord = (j -1) * Espaciamientoy for k in range (1 , Num_Pisos + 1) : z_coord1 = Altura_piso1 * (k -1) if k ==1 else Altura_piso1 + Altura_piso_tipico *( k -2) z_coord2 = Altura_piso1 if k ==1 else Altura_piso1 + Altura_piso_t ip ico *( k -1) ret = SapModel . FrameObj . AddByCoord ( x_coord , y_coord , z_coord1 , x_coord , y_coord , z_coord2 , " " , ’ ConcCol ’ , ’ ’ , ’ Global ’) ret = SapModel . View . RefreshView (0 , False ) Listing 13: Column creation at the grid intersections Listing 12: Beams creation by segments 4 LS Structure Engineering and Research 9 10 Modeling Slabs on Each Floor Slab creation is performed based on the provided parameters, considering the location and dimensions of each floor. This step completes the generation of the three-dimensional structure of the building. This block creates slabs on each floor by defining their vertices based on the established grids. • Determine floor height: The variable Altura is calculated based on whether it’s the first floor or a typical floor. • Nested loops for grid intersections: Two nested loops (for i in range(numx - 1): and for j in range(numy - 1):) iterate through each grid intersection point. • Determine slab coordinates: Coordinates (x0, x1, y0, y1) are calculated based on the current grid intersection, spacing, and loop indices. These coordinates define a rectangular shape for the slab on the current floor. • Create slab: SapModel.AreaObj.AddByCoord is called to add an area object (slab) based on the specified coordinates and floor height. The slab is named according to the current floor, and the section type is set to ’Slab1’. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Results The automated generation of a parametric building model using the CSI Etabs API and Python resulted in the creation of a structural system. The model featured a 50-story building with a first-floor height of 4 meters and typical floor heights of 3 meters. The structural layout included three vertical axes (labeled ABC) and three horizontal axes (labeled 123), spaced at 3.5 meters intervals. The three-dimensional visualization of the structural model in Etabs vividly portrayed the intricate arrangement of beams, columns, and slabs on each floor. The parametric nature of the model allowed for swift adjustments to geometric parameters, facilitating an intuitive understanding of the building’s design. The structural model underwent preliminary analyses within Etabs, demonstrating its responsiveness to changes in geometric and mechanical properties [1]. The material properties were defined for concrete, with beams characterized by a rectangular section of 0.25 meters by 0.5 meters. Slabs were modeled as type ”Slab1.” Engineers can leverage this automated approach to efficiently explore and analyze diverse configurations, ensuring robust structural performance under varying loading conditions [6][7]. • Loop through floors: The outer loop (for PisoActual in range(1, NumPisos + 1):) iterates through each floor level. 1 Structural Engineering Volume 1 for piso_actual in range (1 , Num_Pisos +1) : if piso_actual ==1: altura = Altura_piso1 else : altura = Altura_piso_tipico *( piso_actual -1) + Altura_piso1 for i in range ( numx -1) : for j in range ( numy -1) : x0 = i * Espaciamientox x1 =( i +1) * Espaciamientox y0 = j * Espaciamientoy y1 =( j +1) * Espaciamientoy x =[ x0 , x1 , x1 , x0 ] y =[ y0 , y0 , y1 , y1 ] z =[ altura ]*4 nombre_losa = " F2 " tipo_seccion = " Slab1 " ret = SapModel . AreaObj . AddByCoord (4 ,x ,y ,z , nombre_losa , tipo_seccion ) ret = SapModel . View . RefreshView (0 , False ) Figure 3: Parametric Building Model [Extracted from Etabs 2021] Listing 14: Creation of slabs on each floor 5 LS Structure Engineering and Research Structural Engineering Volume 1 [3] Smith, J.,and Johnson, R. (2021). ”Automating Structural Engineering Tasks Using Python.” Journal of Structural Engineering, 45(2), 112-125. [4] Brown, A., et al. (2020). ”Python Applications in Structural Analysis and Design Automation.” International Journal of Civil Engineering, 30(4), 567-580. [5] Lee, C., and Wang, L. (2019). ”Integration of Python Scripts for Structural Optimization in Engineering Projects.” Automation in Construction, 25(3), 210-225. Figure 4: Parametric Building Model [Extracted from Etabs 2021] 11 [6] Garcia, M., et al. (2018). ”Python-Based Tools for Efficient Structural Modeling and Analysis.” Journal of Computational Engineering, 12(1), 89-102. Conclusions [7] Patel, S., and Chang, Y. (2017). ”Advancements in Structural Engineering Automation through Python Programming.” Structural Automation Quarterly, 8(2), 45-58. In conclusion, the integration of Python scripting with the CSI ETABS API presents a robust solution for automating parametric building modeling. This chapter showcased Python’s adaptability in efficiently creating complex structural models, providing a flexible and iterative design process by manipulating key parameters. The parametric modeling approach not only streamlines repetitive tasks but also sets the stage for future advancements, emphasizing Python’s role between structural engineering and computational design [5]. This work presented a comprehensive tutorial on leveraging the capabilities of Python to efficiently model a 50-story structure with intricate geometric and material specifications. This parametric modeling approach demonstrated in this tutorial empowers engineers and designers to swiftly adapt to evolving project requirements. By manipulating key parameters such as floor heights, grid spacing, and material properties through Python scripts, users can effortlessly explore a multitude of design alternatives, facilitating an iterative and responsive design process. [8] Herramientas para codificar con Python (2021): https://www.youtube.com/watch?v=Pw6WE6BUoA References [1] Vittorio Lora. (2023). “Python for civil and structural engineers”: https://python4civil.weebly.com/bookresources.html [2] Python documentation content (2023): https://docs.python.org/es/3.11/contents.html 6