hello
I have a problem in this code.
it is base on the example code of Sap2000v20 in matlab.
I want to get the "modal result". but it seems there are some problem.
please help me.
thanks
%% clean-up the workspace & command window
clear;
clc;
%%set the following flag to true to attach to an existing instance of the program otherwise a new instance of the program will be started
AttachToInstance = false(); % true(); %
%% set the following flag to true to manually specify the path to SAP2000.exe
%% this allows for a connection to a version of SAP2000 other than the latest installation
%% otherwise the latest installed version of SAP2000 will be launched
SpecifyPath = false(); % true(); %
%% if the above flag is set to true, specify the path to SAP2000 below
%ProgramPath = 'C:\Program Files\Computers and Structures\SAP2000 20\SAP2000.exe';
%% full path to API dll
%% set it to the installation folder
APIDLLPath = 'C:\Program Files\Computers and Structures\SAP2000 20\SAP2000v20.dll';
%% full path to the model
%% set it to the desired path of your model
%ModelDirectory = 'C:\CSiAPIexample';
%if ~exist(ModelDirectory, 'dir')
% mkdir(ModelDirectory);
%end
%ModelName = 'API_1-001.sdb';
%ModelPath = strcat(ModelDirectory, filesep, ModelName);
%% create API helper object
a = NET.addAssembly(APIDLLPath);
helper = SAP2000v20.Helper;
helper = NET.explicitCast(helper,'SAP2000v20.cHelper');
if AttachToInstance
%% attach to a running instance of Sap2000
SapObject = helper.GetObject('CSI.SAP2000.API.SapObject');
SapObject = NET.explicitCast(SapObject,'SAP2000v20.cOAPI');
else
if SpecifyPath
%% create an instance of the SapObject from the specified path
SapObject = helper.CreateObject(ProgramPath);
else
%% create an instance of the SapObject from the latest installed SAP2000
SapObject = helper.CreateObjectProgID('CSI.SAP2000.API.SapObject');
end
SapObject = NET.explicitCast(SapObject,'SAP2000v20.cOAPI');
%% start Sap2000 application
SapObject.ApplicationStart;
end
helper = 0;
%% create SapModel object
SapModel = NET.explicitCast(SapObject.SapModel,'SAP2000v20.cSapModel');
%% initialize model
ret = SapModel.InitializeNewModel;
%% create new blank model
File = NET.explicitCast(SapModel.File,'SAP2000v20.cFile');
%%open an existing file
FileName = 'D:/test/s.sdb';
ret = File.OpenFile(FileName);
%% run model (this will create the analysis model)
Analyze = NET.explicitCast(SapModel.Analyze,'SAP2000v20.cAnalyze');
%ret = Analyze.SetRunCaseFlag('MODAL',false,true);
ret = Analyze.SetRunCaseFlag('MODAL', true);
ret = Analyze.RunAnalysis;
NumberResultsp = 0;
LoadCasep = cellstr(' ');
StepTypep = cellstr(' ');
StepNump = zeros(1,1,'double');
Period = zeros(1,1,'double');
Frequencyp = zeros(1,1,'double');
CircFreqp = zeros(1,1,'double');
EigenValuep = zeros(1,1,'double');
%modal result
AnalysisResults = NET.explicitCast(SapModel.Results,'SAP2000v20.cAnalysisResults');
Setup = NET.explicitCast(AnalysisResults.Setup,'SAP2000v20.cAnalysisResultsSetup');
[ret,NumberResultsp, LoadCasep, StepTypep, StepNump, Period, Frequencyp, CircFreqp, EigenValuep] = AnalysisResults.ModalPeriod(NumberResultsp, LoadCasep, StepTypep, StepNump, Period, Frequencyp, CircFreqp, EigenValuep)
%Open Lock
ret = SapModel.SetModelIsLocked(false);