Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

SAP2000 OAPI 1

Status
Not open for further replies.

CuriousBearcat

Structural
Feb 23, 2024
25
0
1
US
Hello fellow engineers,
I am trying to use SAP2000 OAPI for automating simple modeling and analysis tasks in SAP2000. So far, I have made some considerable progress and would like to share my knowledge as well as ask for guidance whenever I need to. With that purpose, I would love to know your experiences and knowledge working with SAP2000 OAPI, any helpful tips/suggestions and what are some things you use it for?
Looking forward to responses and to connect with people interested in this area.
 
Replies continue below

Recommended for you

Sticksandtriangles,

Great to get a reply from you. I think the commands are 99% the same between ETABs and SAP2000 so that will be helpful. I followed you on GitHub too. Have you used Python or VBA for your applications? I am trying to select area elements that lie within a certain coordinate range and I find that even though the selection box I create using the code below includes the node coordinates of the elements I need, it sometimes misses selection of the edge elements. Have you ever faced this problem before? Again, thanks for your response earlier - and let me know if there's anything I can help you with if needed.

ret=SapModel.SelectObj.CoordinateRange(-0.5,15,25,100.5,13.5,21,Line=False,Area=True,Point=False,CSys=coord) #15 because one panel line lied between 10 ft to 15 ft and was not included it both parts
ret=SapObject.SapModel.AreaObj.SetLoadUniform('1',"TRIAL",-25,Dir=3,Replace=True,CSys="Local",ItemType=2)


-Just a curious engineer
 
I'm mostly a C# person nowadays, dabble a bit in python for getting things up and running that need to be down and dirty.
I have never coded in VBA before, need to learn it eventually.

I have not used the SapModel.SelectObj.CoordinateRange() function before.

Can you throw a sample SAP2000 file and corresponding code up on github? I could try to troubleshoot. Maybe a few screenshots of the issue as well.
 
@sticksandtriangles, I was able to figure that out after some trial and error, the area object selection works best if the area element thickness is also considered. I was creating a selection box that did not include the edges of the shell (accounting for thickness) but once I changed that it works perfectly. Something like this:
[tt]ret=SapModel.SelectObj.CoordinateRange(-0.5,12.5,-0.5,25,13.5,16.5,Line=False,Area=True,Point=False,CSys=coord)[/tt][tt][/tt]

Here the -0.5 and +0.5 account for thickness (a bit over that).

On another note, I am trying to add Wind Load Pattern for ASCE 7-22. I do not think the API supports that yet, can you please tell me if I am wrong, whenever you get a chance? If I am correct, do you know how I can mitigate this issue somehow? Thank you!

P.S. I was able to add ASCE 7-16 load pattern but not the latest code.



-Just a curious engineer
 
Glad to hear it CuriousBearcat.

You should be able to add windload patterns through the database table methods. How did you achieve the 7-16 patterns? Database tables?
It seems like database tables are the go to method nowadays for modifing ETABs/SAP models.

See this post for an example:


And my github has a few examples of how to work with and modify database tables.


S&T -
 
@sticksandtraingles:

I added the wind load patterns using the following code. I could not find a function for ASCE 7-22 Wind load pattern. Do you think it will be easier to implement using database table methods?

[tt]LTYPE_WIND= 6
SapModel.LoadPatterns.Add("WIND-X", LTYPE_WIND)
SapObject.SapModel.LoadPatterns.AutoWind.SetASCE716(Name="WIND-X",ExposureFrom=2,DirAngle=0,Cpw=0.8,Cpl=0.8,ASCECase=1,ASCEe1=0.15,ASCEe2=0.15,UserZ=False,TopZ=H,BottomZ=0,WindSpeed=150,ExposureType=2,Kzt=1,GustFactor=0.85,Kd=0.85,UserExposure=False)[/tt]

On another note, I have noticed that Python is a bit inefficient for larger projects. I know my project is on a small scale currently but will grow larger steadily and certainly in future. I am trying to see if I can switch to Rust in place of Python for my project. It is much more efficient and easy to manage than Python for larger projects, especially when I have the program evaluating hundreds of models in a single run. The only problem I am facing is to connect it with SAP2000 OAPI. If I can somehow get that resolved, I will be ecstatic. Thank you for all your help and guidance.


-Just a curious engineer
 
I uploaded the code on github.

Python:
TableKey2 = 'Load Pattern Definitions - Auto Wind - ASCE 7-22'


ret = SapModel.LoadPatterns.Add("My Sample Wind", 6)
ret2 = SapModel.LoadPatterns.Add("My Sample Wind2", 6)

TableVersion = 0
FieldsKeysIncluded = ['Name', 'IsAuto', 'Exposure','TopStory','BotStory','Parapet','ParapetHt','UserCp','UserCpw',
'UserCplx','UserCpwy','UserCply','ASCECase','e1','e2','WindSpeed','ExpType','GrdElevFact','kzt','GustFact','Kd',
'SolidGross', 'Set', 'WidthType', 'Angle', 'Story', 'Diaphragm', 'Width', 'Depth', 'X', 'Y']
NumberRecords = 2
Data = ["My Sample Wind", "No", "Diaphragms", "Story1", "Base", "No", None, "No",
        None, None, None, None, "Create All", "0.15", "0.15", "100", "C", "1", "1", "0.85", "0.85",
        None, None, None, None, None, None, None, None, None, None]
Data2 = ["My Sample Wind2", "No", "Diaphragms", "Story1", "Base", "No", None, "No",
        None, None, None, None, "Create All", "0.15", "0.15", "100", "C", "1", "1", "0.85", "0.85",
        None, None, None, None, None, None, None, None, None, None]

megadata = Data.copy()
megadata.extend(Data2)


MyNewWind = SapModel.DatabaseTables.SetTableForEditingArray(TableKey2,TableVersion,FieldsKeysIncluded, NumberRecords, megadata)

This code adds these two lines into the load patterns.

test_asce_722_rzb3uf.png


Edit: I see my error, it didn't take the ASCE 7-22 inputs.
 
Thanks a lot for trying this sticksandstones. I guess SAP's API does not have any connection to its ASCE 7-22 Auto Wind Load Case. So I gave up on trying to use it. However when assigning wind loads, I still use ASCE 7-16. And since I am giving the Cp values for areas manually, it should give me the same results as ASCE 7-22. Because the equations have been the same between the two codes - just the Cp values have changed. Took me three days to come to this now obvious conclusion. This is the function I use to assign Cp values to area elements:

[pre]SapObject.SapModel.AreaObj.SetLoadWindPressure_1(Name="WIND-X", LoadPat="WIND-X", MyType=1, cp=1.1, DistributionType=3, ItemType=2)[/pre]

And the required area elements can be conveniently selected by: [pre]SapModel.SelectObj.CoordinateRange(0,B,(num_panels_2h*new_x),(total_panels*new_x),h,H,Line=False,Area=True,Point=False,CSys=coord)
[/pre]
P.S.: My code has increased exponentially in size for this project. I might try to use user functions in Python to club portions of code for a specific purpose such as selecting areas or assigning load patterns.

-Just a curious engineer
 
Just a heads up, I've given up on this, I bet it's something they need to come back to. Seems like adding loads based on code updates are bit difficult for the API development team.

I also went to the SAP2000 API and they have different functions available than in the ETABs API.

These SetASCE716 functions are not available in the ETABs API.

sapapi_bfcejs.png




S&T -
 
Thanks for trying this sticksandtriangles, I could not resolve this either. The only way I see to resolve this now is to write some code to change the input file manually. Or wait until they make a function to do this more easily.

-Just a curious engineer
 
On another topic, I have run into a problem with post-processing results. I am trying to find out how the [tt]FrameForce[/tt] function works. Below is the code I am using to obtain moments:

[tt]M3=[][/tt]
[tt][NumberResults, Obj, ObjSta, Elm, ElmSta, LoadCase, StepType, StepNum, P, V2, V3, T, M2, M3,ret]=SapModel.Results.FrameForce('1', ObjectElm, NumberResults, Obj, ObjSta, Elm, ElmSta, LoadCase, StepType, StepNum, P, V2, V3, T, M2, M3)[/tt]

I obtain a list of moments for the Frame #1. When I rerun the same block of code a different load combination, I get a list with an altogether different size. It appears as if the moment values for the latter load combination got appended to the new list with moments for the former load combination - but I could be wrong in my interpretation. Can I please get an explanation on the working of this function? I tried to dive deep into the documentation but it did not help.



-Just a curious engineer
 
Status
Not open for further replies.
Back
Top