×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SAP2000 API using MATLAB - A Simple Question
6

SAP2000 API using MATLAB - A Simple Question

SAP2000 API using MATLAB - A Simple Question

(OP)
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)

 

RE: SAP2000 API using MATLAB - A Simple Question

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]

RE: SAP2000 API using MATLAB - A Simple Question

(OP)
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

RE: SAP2000 API using MATLAB - A Simple Question

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.
https://wiki.csiberkeley.com/display/kb/Command+line
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.
 

RE: SAP2000 API using MATLAB - A Simple Question

(OP)
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

RE: SAP2000 API using MATLAB - A Simple Question

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

https://wiki.csiberkeley.com/display/kb/Command+line.
 
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.
 

RE: SAP2000 API using MATLAB - A Simple Question

(OP)
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??

RE: SAP2000 API using MATLAB - A Simple Question

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
http://www.csiberkeley.com/sap2000/news-V15
Now you can launch several SAP2000V15.0.1 instances from Matlab but I'm using version 14.
 

RE: SAP2000 API using MATLAB - A Simple Question

(OP)
Dear osquro,
U R THE BEST! Thank you very much.

RE: SAP2000 API using MATLAB - A Simple Question

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.
 

RE: SAP2000 API using MATLAB - A Simple Question

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.


 

RE: SAP2000 API using MATLAB - A Simple Question

Thanks osquro

i will try

RE: SAP2000 API using MATLAB - A Simple Question

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.

RE: SAP2000 API using MATLAB - A Simple Question

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

RE: SAP2000 API using MATLAB - A Simple Question

Hey Existingbrdg,

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

RE: SAP2000 API using MATLAB - A Simple Question

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

RE: SAP2000 API using MATLAB - A Simple Question

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.  

RE: SAP2000 API using MATLAB - A Simple Question

(OP)
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.

RE: SAP2000 API using MATLAB - A Simple Question

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.

RE: SAP2000 API using MATLAB - A Simple Question

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.

RE: SAP2000 API using MATLAB - A Simple Question

Hi Osquro
I'm trying to run a long time analyzing the movements of a model of a building and set up SAP200, but it appears error 'Warning: ActiveX - Attempt to convert unsupported type SAFEARRAY failed - substituting NAN', and not how to solve it. I would greatly appreciate your help
Here I post a piece of code, dode think this error

 NumberResults = zeros (1.1, 'double');
  Obj = cellstr ('');
  Elm = cellstr ('');
 Cellstr ACase = ('');
 Cellstr StepType = ('');
 StepNum = zeros (1.1, 'double');
 Group = 2;
  U11 = zeros (1.1, 'double');
            U22 = zeros (1.1, 'double');
            U33 = zeros (1.1, 'double');
            R11 = zeros (1.1, 'double');
            R22 = zeros (1.1, 'double');
            R33 = zeros (1.1, 'double');

 After he indicated that I run the analysis and the type of load:
 I write this and I get the error mentioned.

 [ret, NumberResults, Obj, Elm, ACase, StepType, StepNum, U11, U22, U33, R11, R22, R33] = SapModel.Results.JointDispl ('Group1' Group, NumberResults, Obj, Elm, ACase, StepType, StepNum, U11, U22, U33, R11, R22, R33

RE: SAP2000 API using MATLAB - A Simple Question

I will run run code tonight. In the mean time, try this:
 - In the line: NumberResults = zeros (1.1, 'double'); all the arguments must be separated by comas (1, 1, 'double').
 - In the line: Obj = cellstr (''); use a space as an argument (' ')
 - Did you use the methods .DeselectAllCasesAndCombosForOutput and .SetCaseSelectedForOutput before retrieve results?

RE: SAP2000 API using MATLAB - A Simple Question

Hi Osquro

You did everything you told me, and I run, but is only an offset, the following is not me. I write the code:
 This is the callback to analyze Sap2000

[code]
ret = SapModel.File.Save('G:\PROYECTO SOPORTE\EDIFICIO 350.sdb');
        
       ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput;

        ret = SapModel.Results.Setup.SetCaseSelectedForOutput('DEAD');
         ret = SapModel.Analyze.CreateAnalysisModel
        ret = SapModel.Analyze.RunAnalysis()
 NumberResults = 0;
           Obj = {' '};
           Elm = {' '};
           LoadCase = {' '};
           StepType = {' '};
           StepNum = zeros(1,1,'double');
           U1 =zeros(1,1,'double');
         
           U2 =zeros(1,1,'double');
           
           U3 = zeros(1,1,'double');
        
           R1 = zeros(1,1,'double');
        
           R2 = zeros(1,1,'double');
    
           R3 = zeros(1,1,'double');
          
           ObjectElm = 0;
     
 
    for i=1:5151
       [ret,NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3] = SapModel.Results.JointDispl(num2str(i), ObjectElm, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3)

end


Muchas Gracias

RE: SAP2000 API using MATLAB - A Simple Question

Sorry, I don't get it. Dit it work?

RE: SAP2000 API using MATLAB - A Simple Question

Hi teffaSapMatlab. I am really sorry for my late reply. For some reason, I did not get the notification.
Actually, my problem was something else. I was trying to extract results for a load combination and it was showing the same error as yours. But when I changed my code to get the results for a specific load case, it worked.
I guess your problem is something different. My suggestion is to try extracting joint displacement results for a single node first, instead of using the 'for loop'. If you succeed, only then go for the loops. I have posted my code below. I hope it will help you customizing your one. Thanks.

CODE:

% Run model (this will create the analysis model)
ret = SapModel.Analyze.RunAnalysis();

% Roof Deflection of left column

[ret, PointName1, PointName2] = SapModel.FrameObj.GetPoints(FrameName2, PointName1, PointName2);

NumberResults = 0;
Obj = cellstr(' ');
Elm = cellstr(' ');
ACase = cellstr(' ');
StepType = cellstr(' ');
StepNum = zeros(1,1,'double');
U1 = zeros(1,1,'double');
U2 = zeros(1,1,'double');
U3 = zeros(1,1,'double');
R1 = zeros(1,1,'double');
R2 = zeros(1,1,'double');
R3 = zeros(1,1,'double');
ObjectElm = 0;
Def = zeros(1,1,'double');

ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput;

[ret, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3] = SapModel.Results.JointDispl(PointName2, ObjectElm, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3);

Def = U1;

%END


 

RE: SAP2000 API using MATLAB - A Simple Question

Hi Osquro. I am trying to get the design summary results for frame elements. I succeeded to obtain the beam results (using SapModel.DesignConcrete.GetSummaryResultsBeam). But for some reason I couldn't do the same in case of columns (using SapModel.DesignConcrete.GetSummaryResultsColumn). I got an error 'Error using Interface.SAP2000v15._cDesignConcrete/GetSummaryResultsColumn
Invoke Error, Dispatch Exception: Exception occurred.'
I have recently started using SAP API and I am a novice in Matlab. Would you please let me know what I am doing wrong? I have posted my code below. Thanks in advance. TC.

CODE

% Run model (this will create the analysis model)
ret = SapModel.Analyze.RunAnalysis();

% Start concrete design
ret = SapModel.DesignConcrete.StartDesign;

% Get summary result data

NumberItems = 0;
FrameName = cellstr(' ');
MyOption = 2;
Location = zeros(1,1,'double');
PMMCombo = cellstr(' ');
PMMArea = zeros(1,1,'double');
PMMRatio = zeros(1,1,'double');
VmajorCombo = cellstr(' ');
AVmajor = zeros(1,1,'double');
VminorCombo = cellstr(' ');
AVminor = zeros(1,1,'double');
ErrorSummary = cellstr(' ');
WarningSummary = cellstr(' ');
Object = 0;

[ret, NumberItems, FrameName, MyOption, Location, PMMCombo, PMMArea, PMMRatio, VmajorCombo, AVmajor, VminorCombo, AVminor, ErrorSummary, WarningSummary] = SapModel.DesignConcrete.GetSummaryResultsColumn('1', NumberItems, FrameName, MyOption, Location, PMMCombo, PMMArea, PMMRatio, VmajorCombo, AVmajor, VminorCombo, AVminor, ErrorSummary, WarningSummary, Object);

%END
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources