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!

SAP2000 API using MATLAB - A Simple Question 6

Status
Not open for further replies.

SinaPeugeot

Structural
May 30, 2010
37
Hi! I am really new to SAP2000 API and I am trying to use MATLAB to interact with SAP. I'm getting help from SAP2000 API documentation. I have built a model using SAP and saved it. Then I used the following code to open and analyze it using MATLAB interface. The problem is, I can't get any "Frame Force" results by API codes; and I get this error "No method 'FrameForce' with matching signature found for class 'Interface.Sap2000v12.cAnalysisResults'". I would REALLY appreciate any help:

feature('COM_SafeArraySingleDim', 1);
feature('COM_PassSafeArrayByRef', 1);
SapObject = actxserver('sap2000.SapObject');
SapObject.ApplicationStart;
ret = SapObject.SapModel.File.OpenFile('C:\....\1.sdb');
ret = SapObject.SapModel.Analyze.RunAnalysis();

ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput;
ret = SapObject.SapModel.Results.Setup.SetCaseSelectedForOutput('DEAD');

Element = NaN;
StepNum=NaN;
NumberResults = NaN;
Obj = cellstr(' ');
ObjSta=0.5;
Elm = cellstr(' ');
ElmSta=NaN;
LoadCase = cellstr(' ');
StepType= cellstr(' ');
P = zeros(1,1,'double');
V2 = zeros(1,1,'double');
V3 = zeros(1,1,'double');
M2 = zeros(1,1,'double');
M3 = zeros(1,1,'double');
T = zeros(1,1,'double');

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

 
Replies continue below

Recommended for you

Hi SinaPeugeot, try this,

Code:
feature('COM_SafeArraySingleDim', 1);
feature('COM_PassSafeArrayByRef', 1);
SapObject = actxserver('sap2000.SapObject');
SapObject.ApplicationStart;
ret = SapObject.SapModel.File.OpenFile('C:\temp\1.sdb');
ret = SapObject.SapModel.Analyze.RunAnalysis();

ret = SapObject.SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput;
ret = SapObject.SapModel.Results.Setup.SetCaseSelectedForOutput('DEAD');

Name = '38';
Element = 1; 
NumberResults = 0;
Obj = cellstr(' ');
ObjSta = zeros(1,1,'double');
Elm = cellstr(' ');
ElmSta = zeros(1,1,'double');
LoadCase = cellstr(' ');
StepType= cellstr(' ');
StepNum = zeros(1,1,'double');
P = zeros(1,1,'double');
V2 = zeros(1,1,'double');
V3 = zeros(1,1,'double');
T = zeros(1,1,'double');
M2 = zeros(1,1,'double');
M3 = zeros(1,1,'double');

[ret, NumberResults, Obj, ObjSta, Elm, ElmSta, LoadCase, StepType, StepNum, P, V2, V3, T, M2, M3] = SapObject.SapModel.Results.FrameForce(Name, Element, NumberResults, Obj, ObjSta, Elm, ElmSta, LoadCase, StepType, StepNum, P, V2, V3, T, M2, M3);
[code]
 
Thanks osquro
I know you are a pro in several fields of structural engineering. The problem was something else, I figured it out several days ago, and completed my code. But I have a new question now: Is there any way to analyze a SAP2000 model, using MATLAB API but without launching SAP2000's GUI. I have to do a lot of analysis (a few thousands) and I think that the GUI is slowing down the process. I would really appreciate any help which could speed up the analysis.
Many thanks in advance
 
Hi SinaPeugeot,

I'm just an enthusiast.

Some tips to speed up your analyses according to my experience:

- To run a few hundreds of models using 100% of all your CPU's cores and threads is better to use several batch files calling SAP2000 from command line a lot of times each.
Models were previously created with MATLAB and SAP200 API.
Results are read and processed later with MATLAB and SAP2000 API.

- In large linear models (more than 10 MB) the bootleneck could be hard-drive reading/writing process. Several GB of RAM can be converted to a temporary simulated hard-drive disk with sotfware like RAMDISK by DATARAM.

- Use Advanced or MT Solver option.
 
Thanks again osquro, But I have some more questions!
The exact thing that I want to do is to "Analyze ONE model ONE time, do some changes in the model using MATLAB-SAP2000 API, and analyze it AGAIN" this loop is repeated for a few thousand times. I don't understand the method you suggested about using Batch files and Command-line. Could you PLZ explain a little bit more? Do you mean using Windows RUN, when u say "Command-Line" or something else?
I really don't want to take more of ur time, but its very important to me.
Many thanks in advance
 
Hi SinaPeugeot,

Instead of creating one model, you can create and save hundreds of models. These models are then analyzed in SAP2000 using command line. To do this, create one or several batch files (a batch file is a text file with extension .bat) according to


Content of batch file looks like this.

SAP2000.exe E:\SAP\Structure_1.SDB /RP1 S2 /C
SAP2000.exe E:\SAP\Structure_2.SDB /RP1 S2 /C
SAP2000.exe E:\SAP\Structure_3.SDB /RP1 S2 /C



Obviously, path and command line options are different in your case.

Later you can use Matlab to SAP2000 API to open .sdb files and read results.
 
Thank you very much, I understood the batch file thing know!
I just have a final question; I can ensure you that it is THE FINAL QUESTION:
I created the batch file, and analyzed a model using it, BUT the problem is that the SAP2000 GUI still comes up! So there is actually no difference between directly analyzing a model using MATLAB-SAP2000 API or using a BATCH file! Am I correct on this?? Does the SAP2000 GUI comes up, even if we call SAP2000 engine from a BATCH file??
 
Hi SinaPeugeot,

You can hide SAP2000 GUI from Matlab:
Visible = SapObject.Visible

You can also use the advanced solver:
SolverType = 1; % 0 = Standard 1 = Advanced
Force32BitSolver = false();
ret = SapModel.Analyze.SetSolverOption(SolverType, Force32BitSolver);

Running SAP2000 from one batch file is not faster than running SAP2000 from Matlab. I think the problem is not GUI. The power is in "parallel proccesing".

Check your CPU running one analysis from one batch file. If your CPU not at 100% of its capacity, use several batch files to run several SAP2000 instances at the same time.
For example:
Batch file 1 runs analyses from 1 to 10
Batch file 2 runs analyses from 11 to 20
Batch file 3 runs analyses from 21 to 30
...
...

According to this link
Now you can launch several SAP2000V15.0.1 instances from Matlab but I'm using version 14.
 
Dear osquro and SinaPeugeot
Your dialogue is very intersting, I am new in Matlab i dont have your experience in the topic their why am asking your help in sort of simular thing because i’ve a restrictive sources, the thing is that i’m working on Sap2000 and i wanna treat theresult with matlab, the treated result will be displacements function with time history functions. Your help will be really appreciate.
 
cherifdj,

1. Explore the file SAP2000_API_Documentation.chm located on SAP2000 instalation folder.
2. Test Example code for Matlab.
3. Try to translate required VBA Examples (provided with all the functions). Be careful with syntax.

We will help you with the details.


 
Hey guys,

I am using VBA to access SAP 2000 API and it works just fine for most of my code. I wrote about 700 lines. I am trying to write a code which after linear TH analysis, implements gap elements where the stress has exceeded capacity and then runs non-linear TH analysis iteratively every time introducing gap elements where the stress exceeds capacity.
I am facing the following problems:
1) The function 'Changeconnectivity' for the area element doesn't seem to work. I am positive I am sending the right parameters to the function yet it always returns 1 instead of a zero.
2) to get around the above problem, I deleted the area element and reconstructed a new one using 'addbypoint' which only works once. i.e it deletes and introduces a new element with different connectivity only once. But I have to use it multiple number of times.

Could any of you guys please check to see if you can use the 'changeconnectivity' function properly or could implement second way more than once. Your help will be highly appreciated.
Thanks.
 
Hey guys

I have a little problem in SAP2000 API. I could not find a command to get the nonlinear results. Especially the hinge states in a nonlinear time history analysis.
Can you help me with this?

Thanks
 
Hey Existingbrdg,

What do you mean hinge states? can you be a little more clear..
 
Hi Ranny

I am trying to perform a non-linear time history analysis. I defined some hinges on columns. And I need to know the frame hinge states.
I mean, I need to get results which demonstrate if they are in IO, life safety, or Collapse prevention region. I need also the demands on the hinges and plastic deformations.

I really appreciate your help
 
Hi,
Happy Holidays. I am new to MATLAB and SAP2000 API. I am also facing difficulty in extracting Frame Forces. I was getting an error similar to SinaPeugeot i.e. "No method FrameForce' with matching signature found for class 'Interface.Sap2000v15.cAnalysisResults'" (FYI I am using SAP2000 v15). I have made the changes suggested by osquro in the second message. Now I am getting several warnings i.e. 'ActiveX - attempt to convert unsupported SAFEARRAY type failed - substituting NAN'. As a result, no results are being stored in P,V2,V3 etc. I would really appreciate if anyone could help me with this. Thanks in advance.
 
Hey Kazi003
First of all there is a problem with SAP2000 v15 API so I don't suggest using it at all. If u use SAP2000 v14 I think a simple hint would solve your problem. Just try different methods of defining a "string" variable. for example try ColumnNames={''} or char(ColumnNames) and ... for the variable ColumnNames. I am positive that the problem is related to this.
 
Thank you so much for your kind reply SinaPeugeot. I later found out that my problem was something else. I have no other options but to use v15 at the moment. Thanks for your suggestions.
Anyway, I can see that you also succeeded to run the analysis from command line. I am also trying out this feature as I will be doing structural optimization later on and I will have to run hundreds of analyses in order to obtain an optimized design. The problem is, I could only open an existing model but I could not run the analysis or perform design checks from command line. I have gone through the link osquro has provided and it seems pretty straight forward. I am probably doing something wrong. I would really appreciate if you could give me some suggestions. Thank you once again for your time.
 
Hi
What happens is that I have the same problem Kazzi003, I run the code for error: 'ActiveX - Attempt to convert unsupported type SAFEARRAY failed - substituting NAN'. I wonder how you solved the problem in the code. Please.

Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor