Matlab SAP - 2
Matlab SAP - 2
clear;
clc;
ModelDirectory = 'C:\CSiAPIexample';
if ~exist(ModelDirectory, 'dir')
mkdir(ModelDirectory);
end
ModelName = 'API_1-001.sdb';
a = NET.addAssembly(APIDLLPath);
helper = SAP2000v20.Helper;
helper = NET.explicitCast(helper,'SAP2000v20.cHelper');
if AttachToInstance
SapObject =
helper.GetObject('CSI.SAP2000.API.SapObject');
SapObject =
NET.explicitCast(SapObject,'SAP2000v20.cOAPI');
else
if SpecifyPath
SapObject = helper.CreateObject(ProgramPath);
else
SapObject =
helper.CreateObjectProgID('CSI.SAP2000.API.SapObject');
end
SapObject =
NET.explicitCast(SapObject,'SAP2000v20.cOAPI');
SapObject.ApplicationStart;
end
helper = 0;
SapModel =
NET.explicitCast(SapObject.SapModel,'SAP2000v20.cSapModel');
%% initialize model
ret = SapModel.InitializeNewModel;
File = NET.explicitCast(SapModel.File,'SAP2000v20.cFile');
ret = File.NewBlank;
PropMaterial =
NET.explicitCast(SapModel.PropMaterial,'SAP2000v20.cPropMater
ial');
ret = PropMaterial.SetMaterial('CONC',
SAP2000v20.eMatType.Concrete);
PropFrame =
NET.explicitCast(SapModel.PropFrame,'SAP2000v20.cPropFrame');
ModValue = NET.createArray('System.Double',8);
for i = 1 : 8
ModValue(i) = 1;
end
ModValue(1) = 1000;
ModValue(2) = 0;
ModValue(3) = 0;
ret = SapModel.SetPresentUnits(SAP2000v20.eUnits.kip_ft_F);
FrameObj =
NET.explicitCast(SapModel.FrameObj,'SAP2000v20.cFrameObj');
PointObj =
NET.explicitCast(SapModel.PointObj,'SAP2000v20.cPointObj');
Restraint = NET.createArray('System.Boolean',6);
for i = 1 : 4
Restraint(i) = true();
end
for i = 5 : 6
Restraint(i) = false();
end
for i = 1 : 2
Restraint(i) = true();
end
for i = 3 : 6
Restraint(i) = false();
end
[ret, PointName1, PointName2] =
FrameObj.GetPoints(FrameName2, PointName1, PointName2);
View = NET.explicitCast(SapModel.View,'SAP2000v20.cView');
LoadPatterns =
NET.explicitCast(SapModel.LoadPatterns,'SAP2000v20.cLoadPatte
rns');
ret = LoadPatterns.Add('1',
SAP2000v20.eLoadPatternType.Other, 1, true());
ret = LoadPatterns.Add('2',
SAP2000v20.eLoadPatternType.Other, 0, true());
ret = LoadPatterns.Add('3',
SAP2000v20.eLoadPatternType.Other, 0, true());
ret = LoadPatterns.Add('4',
SAP2000v20.eLoadPatternType.Other, 0, true());
ret = LoadPatterns.Add('5',
SAP2000v20.eLoadPatternType.Other, 0, true());
ret = LoadPatterns.Add('6',
SAP2000v20.eLoadPatternType.Other, 0, true());
ret = LoadPatterns.Add('7',
SAP2000v20.eLoadPatternType.Other, 0, true());
PointLoadValue = NET.createArray('System.Double',6);
for i = 1 : 6
PointLoadValue(i) = 0.0;
end
PointLoadValue(3) = -10;
for i = 1 : 6
PointLoadValue(i) = 0.0;
end
PointLoadValue(3) = -17.2;
PointLoadValue(5) = -54.4;
ret = SapModel.SetPresentUnits(SAP2000v20.eUnits.kip_in_F);
%% save model
ret = File.Save(ModelPath);
Analyze =
NET.explicitCast(SapModel.Analyze,'SAP2000v20.cAnalyze');
ret = Analyze.RunAnalysis();
SapResult = zeros(7,1,'double');
AnalysisResultsSetup =
NET.explicitCast(AnalysisResults.Setup,'SAP2000v20.cAnalysisR
esultsSetup');
for i = 1 : 7
NumberResults = 0;
Obj = NET.createArray('System.String',2);
Elm = NET.createArray('System.String',2);
ACase = NET.createArray('System.String',2);
StepType = NET.createArray('System.String',2);
StepNum = NET.createArray('System.Double',2);
U1 = NET.createArray('System.Double',2);
U2 = NET.createArray('System.Double',2);
U3 = NET.createArray('System.Double',2);
R1 = NET.createArray('System.Double',2);
R2 = NET.createArray('System.Double',2);
R3 = NET.createArray('System.Double',2);
ret =
AnalysisResultsSetup.DeselectAllCasesAndCombosForOutput;
ret =
AnalysisResultsSetup.SetCaseSelectedForOutput(int2str(i));
if i <= 4
SapResult(i) = U3(1);
else
SapResult(i) = U1(1);
end
end
%% close Sap2000
ret = SapObject.ApplicationExit(false());
File = 0;
PropMaterial = 0;
PropFrame = 0;
FrameObj = 0;
PointObj = 0;
View = 0;
LoadPatterns = 0;
Analyze = 0;
AnalysisResults = 0;
AnalysisResultsSetup = 0;
SapModel = 0;
SapObject = 0;
IndResult = zeros(7,1,'double');
IndResult(1) = -0.02639;
IndResult(2) = 0.06296;
IndResult(3) = 0.06296;
IndResult(4) = -0.2963;
IndResult(5) = 0.3125;
IndResult(6) = 0.11556;
IndResult(7) = 0.00651;
PercentDiff = zeros(7,1,'double');
for i = 1 : 7
end
%% display results
SapResult
IndResult
PercentDiff