Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Area by Coord Method - ETABS API

Status
Not open for further replies.

fracture_point

Structural
Mar 7, 2019
58
I'm trying to write some code in Python that draws a slab in ETABS. However, API documentation is scarce for Python for this method. An example is given for VB:

Code:
 'add area object by coordinates
   ReDim x(5)
   ReDim y(5)
   ReDim z(5)
   x(0) = 50:   y(0) = 0
   x(1) = 100:  y(1) = 0
   x(2) = 150:  y(2) = 40
   x(3) = 100:  y(3) = 80
   x(4) = 50:   y(4) = 80
   x(5) = 0:    y(5) = 40
   ret = SapModel.AreaObj.AddByCoord(6, x, y, z, Name)

I don't quite know how to manipulate this for Python. The C# documentation shows:

Code:
 int AddByCoord(
	int NumberPoints,
	ref double[] X,
	ref double[] Y,
	ref double[] Z,
	ref string Name,
	string PropName = "Default",
	string UserName = "",
	string CSys = "Global"
)

Should I be passing arrays of x,y,z coordinates? Does anyone know how to create the equivalent code in Python?

Thanks!
 
Replies continue below

Recommended for you

Attached is the method in the comtypes.gen py file.

Python:
cAreaObj._methods_ = [
    COMMETHOD([dispid(1)], HRESULT, 'AddByCoord',
              ( ['in'], c_int, 'NumberPoints' ),
              ( ['in', 'out'], POINTER(_midlSAFEARRAY(c_double)), 'X' ),
              ( ['in', 'out'], POINTER(_midlSAFEARRAY(c_double)), 'Y' ),
              ( ['in', 'out'], POINTER(_midlSAFEARRAY(c_double)), 'Z' ),
              ( ['in', 'out'], POINTER(BSTR), 'Name' ),
              ( ['in', 'optional'], BSTR, 'PropName', 'Default' ),
              ( ['in', 'optional'], BSTR, 'UserName', '' ),
              ( ['in', 'optional'], BSTR, 'CSys', 'Global' ),
              ( ['out', 'retval'], POINTER(c_int), 'pRetVal' )),

Your require four input needs to be:

NumberPoints: int
X: list (of float type)
Y: list (of float type)
Z: list (of float type)

For a 4-noded shell elements, the X, Y & Z lists must have five elements, the values need to go [node1,node2,node3,node4,node1].

General finite elements rules apply, element won't be added if nodes aren't collinear and I think you might get into trouble if adding a 4-node element with a reflexive internal angle.

My preference is to add an area element by add by point method.

Python:
areaPts=()
areaPt1=SapModel.PointObj.AddCartesian(ptX1coord,ptY1coord,ptZ1coord)
areaPts+=(areaPt1[0],)
areaPt2=SapModel.PointObj.AddCartesian(ptX2coord,ptY2coord,ptZ2coord)
areaPts+=(areaPt2[0],)
areaPt3=SapModel.PointObj.AddCartesian(ptX3coord,ptY3coord,ptZ3coord)
areaPts+=(areaPt3[0],)
areaPt4=SapModel.PointObj.AddCartesian(ptX4coord,ptY4coord,ptZ4coord)
areaPts+=(areaPt4[0],)
nosPts=len(areaPts)
newArea=""
areaObj=SapModel.AreaObj.AddByPoint(nosPts,areaPts,newArea)

 
This python code did the trick for me, be sure to add the refresh view part of the code or else you won't see the area object you created.

Python:
x = [0,0,100,0]
y = [0,100,100,0]
z = [0,0,0,0]
Name = '12'
UserName = ''

PropName = "Slab1"
area = SapModel.AreaObj.AddByCoord(4, x, y, z, Name, PropName, UserName)
ret = SapModel.View.RefreshView(0, False)

S&T
 
rscassar, where is the comptypes.gen py file located?

Seems like there is a lot of good stuff in there as compared to just the .chm file that has been my only reference.


S&T
 
Thank you both for the info, I appreciate how active you both are!
 
It will be located with your site packages. If u are using anaconda spyder as a python environoment, go

>> help(comtypes)

At the bottom, it will give file locations "c:\users\XXXXXX\anaconda3\lib\site-packages\comtypes\__init__.py"

In that comtypes folder, there will be a gen folder. In the gen folder there will be few files depending on how my programs u access through comtypes. Open the one that says ETAB2018.py, in that it will reference the file it uses will be an obscure filename "from comtypes.gen import [highlight #FCE94F]_769D0CFD_A487_4251_A5D4_29A737893481_0_54_0[/highlight]".

This file will have all the classes and methods that you can use.


 
Do you guys have any advice on the following thing:

I am trying to get ETABS to draw slab area elements on each floor using Python. I have a list containing point data for each node's XYZ coords on a given story:

Code:
 [[[0.0, 0.0, 3.0], [0.0, 24.0, 3.0], [24.0, 24.0, 3.0], [24.0, 0.0, 3.0]], [[0.0, 0.0, 6.0], [0.0, 24.0, 6.0], [24.0, 24.0, 6.0], [24.0, 0.0, 6.0]], [[0.0, 0.0, 9.0], [0.0, 24.0, 9.0], [24.0, 24.0, 9.0], [24.0, 0.0, 9.0]]]]

I have the following code which loops through to create a floor on the first floor (3m):

Code:
 for i in range(len(slabCoordListTwo[0])):
    
        x.append(slabCoordListTwo[0][i][0])
        y.append(slabCoordListTwo[0][i][1])
        z.append(slabCoordListTwo[0][i][2])]

This creates the x,y,z array for the first story set of nodes, but I'm not sure how to nest another for loop to do this for each story.

Do you have any advice?

 
your nested list is 3 deep. Are your extra stories in slabCoordListTwo[1] and slabCoordListTwo[2] etc.

If they are you can add an extra step to the loop:

Code:
for i in range(len(slabCoordListTwo)):
    for j in range(len(slabCoordListTwo[i])):
        x.append(slabCoordListTwo[i][j][0])
        y.append(slabCoordListTwo[i][j][1])
        z.append(slabCoordListTwo[i][j][2])]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor