Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

ETABS API- need some help for extract concrete frame quantties volume 2

Status
Not open for further replies.

Moam93

Civil/Environmental
May 1, 2020
14
0
0
AU
I am starting to use ETABS API with Python . I need to extract concrete quantites volume for frames elements (beams&columns). I believe I need to access to area of of all concrete elements and multiply by length or height ? I am not sure how to start with that in API . can somebody help or guide me with reference to learn more except for the etabs api docs ?

Thanks in advance
 
Replies continue below

Recommended for you

To use API, it's probably best to be using Python 3.0 or higher and you will require to import the modules comtypes. I recommend comtypes v1.1.7.

Also recommend using Anancoda spyder or similar for a python workspace.

1. run the python example in the help docs, this will link it to the CsiEtabsv1.tlb file in the installs folder.
2. after you have run this, it will setup a file in comtypes/gen folder. So next time you have your model open you will just need to run:

import comtypes;
EtabsObject=comtypes.client.GetActiveObject("CSI.ETABS.API.ETABSObject");
SapModel=EtabsObject.SapModel;

3. Then you want to create some lists and start going thru the data. The functions you will likely need to use as a minimum will be

SapModel.FrameObj.GetAllFrames()
SapModel.PropMaterial.GetNameList()

Most of the getters in SapModel.PropFrame and SapModel.PropMaterial

Let me know how you go, I might be able to help you more during the work week.
 
Thanks rscassar for your response .
after the reading the example , I maaaged to open the model and run it by API .
I will start to see those functions you mentioned and see how it works .
I let you know how it did go with me .

 
Hello rscassar,
I made a progress in the API script . I managed to get length of all columns and area ,but I have one problem for model.PropFrame.GetRectangle("ConcCol")
function . It only gets width ,depth of the name of section column in function . I want to get (width,depth) of all of them and to be in a tuple .
I tried to use get selected funtion . but it didn't work out for me . below is the code I done

{

import os
import sys
import comtypes.client


def get_all_frames(model):
""" Retrieves select data for all frame objects in the model."""

res = model.FrameObj.GetAllFrames()
total_frames = res[0]
z1=res[8]
z2=res[11]
length = tuple(x-y for x,y in zip(z2,z1))

print("Total frames",total_frames)
print("length",length)

def select_columns(model):
#"select all columns in model to use it later for section_area function "

select = model.FrameObj.GetSelected("ConcCol")
# columns_names=[0]

def get_section_area(model):
#""retrieves section area of frames ""
sec_area = model.PropFrame.GetRectangle("ConcCol")
width = sec_area[2]
depth = sec_area[3]
print("width",width)
print("depth",depth)



ProgramPath = r"C:\Program Files\Computers and Structures\ETABS 17\ETABS.exe"

ModelPath = r"C:\Users\Mostafa\Desktop\python_exercise\example.EDB"
helper = comtypes.client.CreateObject('ETABSv17.Helper')
helper = helper.QueryInterface(comtypes.gen.ETABSv17.cHelper)
#create API helper object
myETABSObject = helper.CreateObject(ProgramPath)

#start ETABS application
myETABSObject.ApplicationStart()
#create SapModel object
SapModel = myETABSObject.SapModel
#initialize model
ret = SapModel.InitializeNewModel()

#open an existing file
ret = SapModel.File.OpenFile(ModelPath)
#run model (this will create the analysis model)
ret = SapModel.Analyze.RunAnalysis()
# selected_objects=SapModel.SelectObj.GetSelected();
# (number_objects_selected,(object_enumeration),(object_id),return_value

result=get_all_frames(SapModel)

result2=select_columns(SapModel)

result3=get_section_area(SapModel)
}

the output is
Total frames 64
length (3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0)
width 375.0
depth 375.0


I need to get width and depth in tuples of all 64 frames . (not only section name in propframe function )

What do you think ?


 
The function model.PropFrame.GetRectangle("ConcCol") will only work for rectangular sections. You probably want to use a more general function PropFrame.GetSectProps(Name)

What you want to to is something like this:

Python:
#Get Frame Objects
frames = model.FrameObj.GetAllFrames()
#Get Frame Lengths
length = tuple(x-y for x,y in zip(z2,z1))
#Create an empty tuple and add frame Cross-sectional area
area=();
for frame_section in frames[2]:
    area+=(model.PropFrame.GetSectProps(frame_section)[0],)

If you look into the nested list your created "res", this should contain 21 lists list0=number of frames; list1=frame_name (a unique number for all frame objects), list2=frame_section.
 
If you want to get width and depth, you will need to get the frame_name & frame_section, then get the frame type enumerator, then match the enumerator to the section type:

This will loop thru all the frames and get the relevant data
Python:
all_frames=model.FrameObj.GetAllFrames();
for i in range(all_frames[0]):
    frame_name=all_frames[1][i];
    x0,y0,z0=all_frames[6][i],all_frames[7][i],all_frames[8][i];
    x1,y1,z1=all_frames[9][i],all_frames[10][i],all_frames[11][i];
    frame_section=all_frames[2][i];
    frame_type_enum=model.PropFrame.GetTypeOAPI(frame_section)[0];
    if(frame_type_enum==8):
        sect_type='rectangular';
        width,depth=model.PropFrame.GetRectangle(frame_section)[2:4];
    elif(frame_type_enum==9):
        sect_type='circular';
        width=model.PropFrame.GetCircle(frame_section)[2];
 
Hello all,

i'm new to Python and Etabs API. I'm trying to run the API example from CSi, but every time i'm running the code, i get the following error:

Etabs_API_nnefk8.jpg


I've tried to delete and reinstall the "comtypes" package but it doesn't help.

Any idea why does this error happen and how to fix it?

Thanks
 
Probably best to start a new thread with questions than to add to existing threads.

Can you please confirm the following:
- Which python development environment that you are using (eg. Spyder).
- Which version of Etabs you have installed.
- Which version of comtypes you have installed, you will find this in the comtypes\__init__.py file.
- In the etabs install folder, what .tlb files do you have. Looks like you are using etabs v17, are they 'CSiAPIv1.tlb' and 'ETABSv1.tlb'.
- In the comtypes/gen folder, there should be some files that have been generated, open these files in a text editor and do they reference these tlb files.

Try opening etabs and running this script.

Python:
import sys
import comtypes.client

try:
    myETABSObject = comtypes.client.GetActiveObject("CSI.ETABS.API.ETABSObject") 
except (OSError, comtypes.COMError):
    print("No running instance of the program found or failed to attach.")
    sys.exit(-1)
SapModel = myETABSObject.SapModel
 
Hi rscassar,

rscassar said:
- Which python development environment that you are using (eg. Spyder).
- Which version of Etabs you have installed.
- Which version of comtypes you have installed, you will find this in the comtypes\__init__.py file.
- In the etabs install folder, what .tlb files do you have. Looks like you are using etabs v17, are they 'CSiAPIv1.tlb' and 'ETABSv1.tlb'.
- In the comtypes/gen folder, there should be some files that have been generated, open these files in a text editor and do they reference these tlb files.

- i'm using PyCharm
- Etabs 17
- comtypes version 1.1.7
- there are 3 .tlb files "ETABS.tlb", "ETABS2016.tlb", and "ETABSv17.tlb"
- there is reference only to ETABSv17.tlb

rscassar said:
Try opening etabs and running this script.

After doing this i get the following Error:

Traceback (most recent call last):
File "C:/Users/Stefan/PycharmProjects/ETABS_API/TestFile.py", line 9, in <module>
SapModel = myETABSObject.SapModel
AttributeError: 'POINTER(IUnknown)' object has no attribute 'SapModel'

Process finished with exit code 1

Thanks for your help.
 
Status
Not open for further replies.
Back
Top