├── .gitattributes
├── .gitignore
├── README.md
├── SAP.API.Initial
    ├── App.config
    ├── ConsoleUtilities.cs
    ├── ExternalReferences
    │   ├── SAP2000v19.dll
    │   └── SAP2000v20.dll
    ├── Program.cs
    ├── Properties
    │   └── AssemblyInfo.cs
    ├── SAP.API.Initial.csproj
    ├── SAP.API.Initial.csproj.user
    ├── SAPModel.cs
    ├── SapExample.cs
    ├── SapFrameDistLoad.cs
    ├── SapFrameElement.cs
    ├── SapFrameResult.cs
    ├── SapJointRestraint.cs
    ├── SapLoadPattern.cs
    ├── SapMaterial.cs
    ├── SapModel.cs
    ├── SapPoint.cs
    ├── SapPointLoad.cs
    ├── SapPointResult.cs
    ├── SapRecangularSection.cs
    └── packages.config
└── SAP.API.sln
/.gitattributes:
--------------------------------------------------------------------------------
 1 | ###############################################################################
 2 | # Set default behavior to automatically normalize line endings.
 3 | ###############################################################################
 4 | * text=auto
 5 | 
 6 | ###############################################################################
 7 | # Set default behavior for command prompt diff.
 8 | #
 9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs     diff=csharp
14 | 
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following 
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln       merge=binary
26 | #*.csproj    merge=binary
27 | #*.vbproj    merge=binary
28 | #*.vcxproj   merge=binary
29 | #*.vcproj    merge=binary
30 | #*.dbproj    merge=binary
31 | #*.fsproj    merge=binary
32 | #*.lsproj    merge=binary
33 | #*.wixproj   merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj   merge=binary
36 | #*.wwaproj   merge=binary
37 | 
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg   binary
44 | #*.png   binary
45 | #*.gif   binary
46 | 
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | # 
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the 
52 | # entries below.
53 | ###############################################################################
54 | #*.doc   diff=astextplain
55 | #*.DOC   diff=astextplain
56 | #*.docx  diff=astextplain
57 | #*.DOCX  diff=astextplain
58 | #*.dot   diff=astextplain
59 | #*.DOT   diff=astextplain
60 | #*.pdf   diff=astextplain
61 | #*.PDF   diff=astextplain
62 | #*.rtf   diff=astextplain
63 | #*.RTF   diff=astextplain
64 | 
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
  1 | ## Ignore Visual Studio temporary files, build results, and
  2 | ## files generated by popular Visual Studio add-ons.
  3 | ##
  4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
  5 | 
  6 | # User-specific files
  7 | *.suo
  8 | *.user
  9 | *.userosscache
 10 | *.sln.docstates
 11 | 
 12 | # User-specific files (MonoDevelop/Xamarin Studio)
 13 | *.userprefs
 14 | 
 15 | # Build results
 16 | [Dd]ebug/
 17 | [Dd]ebugPublic/
 18 | [Rr]elease/
 19 | [Rr]eleases/
 20 | x64/
 21 | x86/
 22 | bld/
 23 | [Bb]in/
 24 | [Oo]bj/
 25 | [Ll]og/
 26 | 
 27 | # Visual Studio 2015 cache/options directory
 28 | .vs/
 29 | # Uncomment if you have tasks that create the project's static files in wwwroot
 30 | #wwwroot/
 31 | 
 32 | # MSTest test Results
 33 | [Tt]est[Rr]esult*/
 34 | [Bb]uild[Ll]og.*
 35 | 
 36 | # NUNIT
 37 | *.VisualState.xml
 38 | TestResult.xml
 39 | 
 40 | # Build Results of an ATL Project
 41 | [Dd]ebugPS/
 42 | [Rr]eleasePS/
 43 | dlldata.c
 44 | 
 45 | # .NET Core
 46 | project.lock.json
 47 | project.fragment.lock.json
 48 | artifacts/
 49 | **/Properties/launchSettings.json
 50 | 
 51 | *_i.c
 52 | *_p.c
 53 | *_i.h
 54 | *.ilk
 55 | *.meta
 56 | *.obj
 57 | *.pch
 58 | *.pdb
 59 | *.pgc
 60 | *.pgd
 61 | *.rsp
 62 | *.sbr
 63 | *.tlb
 64 | *.tli
 65 | *.tlh
 66 | *.tmp
 67 | *.tmp_proj
 68 | *.log
 69 | *.vspscc
 70 | *.vssscc
 71 | .builds
 72 | *.pidb
 73 | *.svclog
 74 | *.scc
 75 | 
 76 | # Chutzpah Test files
 77 | _Chutzpah*
 78 | 
 79 | # Visual C++ cache files
 80 | ipch/
 81 | *.aps
 82 | *.ncb
 83 | *.opendb
 84 | *.opensdf
 85 | *.sdf
 86 | *.cachefile
 87 | *.VC.db
 88 | *.VC.VC.opendb
 89 | 
 90 | # Visual Studio profiler
 91 | *.psess
 92 | *.vsp
 93 | *.vspx
 94 | *.sap
 95 | 
 96 | # TFS 2012 Local Workspace
 97 | $tf/
 98 | 
 99 | # Guidance Automation Toolkit
100 | *.gpState
101 | 
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 | 
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 | 
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 | 
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 | 
116 | # Visual Studio code coverage results
117 | *.coverage
118 | *.coveragexml
119 | 
120 | # NCrunch
121 | _NCrunch_*
122 | .*crunch*.local.xml
123 | nCrunchTemp_*
124 | 
125 | # MightyMoose
126 | *.mm.*
127 | AutoTest.Net/
128 | 
129 | # Web workbench (sass)
130 | .sass-cache/
131 | 
132 | # Installshield output folder
133 | [Ee]xpress/
134 | 
135 | # DocProject is a documentation generator add-in
136 | DocProject/buildhelp/
137 | DocProject/Help/*.HxT
138 | DocProject/Help/*.HxC
139 | DocProject/Help/*.hhc
140 | DocProject/Help/*.hhk
141 | DocProject/Help/*.hhp
142 | DocProject/Help/Html2
143 | DocProject/Help/html
144 | 
145 | # Click-Once directory
146 | publish/
147 | 
148 | # Publish Web Output
149 | *.[Pp]ublish.xml
150 | *.azurePubxml
151 | # TODO: Comment the next line if you want to checkin your web deploy settings
152 | # but database connection strings (with potential passwords) will be unencrypted
153 | *.pubxml
154 | *.publishproj
155 | 
156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
157 | # checkin your Azure Web App publish settings, but sensitive information contained
158 | # in these scripts will be unencrypted
159 | PublishScripts/
160 | 
161 | # NuGet Packages
162 | *.nupkg
163 | # The packages folder can be ignored because of Package Restore
164 | **/packages/*
165 | # except build/, which is used as an MSBuild target.
166 | !**/packages/build/
167 | # Uncomment if necessary however generally it will be regenerated when needed
168 | #!**/packages/repositories.config
169 | # NuGet v3's project.json files produces more ignorable files
170 | *.nuget.props
171 | *.nuget.targets
172 | 
173 | # Microsoft Azure Build Output
174 | csx/
175 | *.build.csdef
176 | 
177 | # Microsoft Azure Emulator
178 | ecf/
179 | rcf/
180 | 
181 | # Windows Store app package directories and files
182 | AppPackages/
183 | BundleArtifacts/
184 | Package.StoreAssociation.xml
185 | _pkginfo.txt
186 | 
187 | # Visual Studio cache files
188 | # files ending in .cache can be ignored
189 | *.[Cc]ache
190 | # but keep track of directories ending in .cache
191 | !*.[Cc]ache/
192 | 
193 | # Others
194 | ClientBin/
195 | ~$*
196 | *~
197 | *.dbmdl
198 | *.dbproj.schemaview
199 | *.jfm
200 | *.pfx
201 | *.publishsettings
202 | orleans.codegen.cs
203 | 
204 | # Since there are multiple workflows, uncomment next line to ignore bower_components
205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
206 | #bower_components/
207 | 
208 | # RIA/Silverlight projects
209 | Generated_Code/
210 | 
211 | # Backup & report files from converting an old project file
212 | # to a newer Visual Studio version. Backup files are not needed,
213 | # because we have git ;-)
214 | _UpgradeReport_Files/
215 | Backup*/
216 | UpgradeLog*.XML
217 | UpgradeLog*.htm
218 | 
219 | # SQL Server files
220 | *.mdf
221 | *.ldf
222 | *.ndf
223 | 
224 | # Business Intelligence projects
225 | *.rdl.data
226 | *.bim.layout
227 | *.bim_*.settings
228 | 
229 | # Microsoft Fakes
230 | FakesAssemblies/
231 | 
232 | # GhostDoc plugin setting file
233 | *.GhostDoc.xml
234 | 
235 | # Node.js Tools for Visual Studio
236 | .ntvs_analysis.dat
237 | node_modules/
238 | 
239 | # Typescript v1 declaration files
240 | typings/
241 | 
242 | # Visual Studio 6 build log
243 | *.plg
244 | 
245 | # Visual Studio 6 workspace options file
246 | *.opt
247 | 
248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
249 | *.vbw
250 | 
251 | # Visual Studio LightSwitch build output
252 | **/*.HTMLClient/GeneratedArtifacts
253 | **/*.DesktopClient/GeneratedArtifacts
254 | **/*.DesktopClient/ModelManifest.xml
255 | **/*.Server/GeneratedArtifacts
256 | **/*.Server/ModelManifest.xml
257 | _Pvt_Extensions
258 | 
259 | # Paket dependency manager
260 | .paket/paket.exe
261 | paket-files/
262 | 
263 | # FAKE - F# Make
264 | .fake/
265 | 
266 | # JetBrains Rider
267 | .idea/
268 | *.sln.iml
269 | 
270 | # CodeRush
271 | .cr/
272 | 
273 | # Python Tools for Visual Studio (PTVS)
274 | __pycache__/
275 | *.pyc
276 | 
277 | # Cake - Uncomment if you are using it
278 | # tools/**
279 | # !tools/packages.config
280 | 
281 | # Telerik's JustMock configuration file
282 | *.jmconfig
283 | 
284 | # BizTalk build output
285 | *.btp.cs
286 | *.btm.cs
287 | *.odx.cs
288 | *.xsd.cs
289 | 
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SAPWrappers
2 | SAP API Wrapper with C#
3 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/App.config:
--------------------------------------------------------------------------------
1 | 
2 | 
3 |      
4 |         
5 |     
6 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/ConsoleUtilities.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | using System.Collections.Generic;
 3 | using System.Linq;
 4 | using System.Runtime.InteropServices;
 5 | using System.Text;
 6 | using System.Threading.Tasks;
 7 | 
 8 | namespace SAP.API.Initial
 9 | {
10 |     public static class ConsoleUtilities
11 |     {
12 | 
13 |         public static void Header(this string s, ConsoleColor forecolor, ConsoleColor backColor)
14 |         {
15 |             int x = 0;
16 |             int y = 0;
17 |             int txtSize = s.Count();
18 |             int height = 10;
19 |             //top
20 |             for (int i = 0; i < Console.WindowWidth; i++)
21 |             {
22 |                 Console.SetCursorPosition(x + i, y);
23 |                 Console.WriteLine("*");
24 |             }
25 |             //bottom
26 |             for (int i = 0; i < Console.WindowWidth; i++)
27 |             {
28 |                 Console.SetCursorPosition(x + i, y + height);
29 |                 Console.WriteLine("*");
30 |             }
31 |             //right
32 |             for (int i = 0; i < height; i++)
33 |             {
34 |                 Console.SetCursorPosition(x, y + i);
35 |                 Console.WriteLine("*");
36 |             }
37 |             //left
38 |             for (int i = 0; i < height; i++)
39 |             {
40 |                 Console.SetCursorPosition(x + Console.WindowWidth - 1, y + i);
41 |                 Console.WriteLine("*");
42 |             }
43 | 
44 | 
45 |             Console.ForegroundColor = forecolor;
46 |             Console.BackgroundColor = backColor;
47 |             Console.SetCursorPosition(Console.WindowWidth / 2 - txtSize / 2, y + height / 2);
48 | 
49 |             Console.WriteLine(s);
50 |             Console.ResetColor();
51 |             Console.SetCursorPosition(x, y + height + 1);
52 |         }
53 |         public static void Print(this string s, ConsoleColor foreColor)
54 |         {
55 |             Console.ForegroundColor = foreColor;
56 |             Console.WriteLine(s);
57 |             Console.ResetColor();
58 |         }
59 |         public static void PrintCenter(this string s, ConsoleColor foreColor = ConsoleColor.White)
60 |         {
61 |             Console.ForegroundColor = foreColor;
62 |             Console.SetCursorPosition(Console.WindowWidth / 2 - s.Count() / 2, Console.CursorTop);
63 |             Console.WriteLine(s);
64 |             Console.ResetColor();
65 |         }
66 |         public static void PrintAtPosition(this string s, [Optional]int x, [Optional]int y, ConsoleColor foreColor)
67 |         {
68 |             if (y == 0 && x != 0)
69 |             {
70 |                 Console.SetCursorPosition(x, Console.CursorTop);
71 | 
72 |             }
73 |             else if (x == 0 && y != 0)
74 |             {
75 |                 Console.SetCursorPosition(Console.CursorLeft, y);
76 |             }
77 |             else if (x != 0 && y != 0)
78 |             {
79 |                 Console.SetCursorPosition(x, y);
80 |             }
81 |             Console.ForegroundColor = foreColor;
82 |             Console.WriteLine(s);
83 |             Console.ResetColor();
84 |         }
85 |        
86 |     }
87 | }
88 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/ExternalReferences/SAP2000v19.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CEI-ITI-Intake38/SAP2000Wrappers/79541dcf3ff33f752f089428c88a097f14828308/SAP.API.Initial/ExternalReferences/SAP2000v19.dll
--------------------------------------------------------------------------------
/SAP.API.Initial/ExternalReferences/SAP2000v20.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CEI-ITI-Intake38/SAP2000Wrappers/79541dcf3ff33f752f089428c88a097f14828308/SAP.API.Initial/ExternalReferences/SAP2000v20.dll
--------------------------------------------------------------------------------
/SAP.API.Initial/Program.cs:
--------------------------------------------------------------------------------
  1 | using System;
  2 | using System.Collections.Generic;
  3 | using System.Linq;
  4 | using System.Text;
  5 | using System.Threading.Tasks;
  6 | using SAP2000v20;
  7 | 
  8 | 
  9 | namespace SAP.API.Initial
 10 | {
 11 |     class Program
 12 |     {
 13 |         static void Main(string[] args)
 14 |         {
 15 |             int choise;
 16 |             Console.WriteLine("For SapAPI tutorial type: 1 ");
 17 |             Console.WriteLine("For SapAPI Wrapper  type: 2 ");
 18 |             Console.WriteLine("type (1 or 2) :  ");
 19 |             choise = Convert.ToInt32(Console.ReadLine().ToString());
 20 | 
 21 |             switch (choise)
 22 |             {
 23 |                 case 1:
 24 |                     RunSapTutorial();
 25 |                     break;
 26 |                 case 2:
 27 |                     RunWrapperCode();
 28 |                     break;
 29 |                 default:
 30 |                     break;
 31 |             }
 32 |             
 33 |         }
 34 | 
 35 |         static void RunWrapperCode()
 36 |         {
 37 |             #region Wrapper Code
 38 | 
 39 | 
 40 | 
 41 |             Console.Write("Enter the number of spans in X direction : ");
 42 |             int nSpanX = Convert.ToInt32(Console.ReadLine());
 43 |             Console.Write("Enter the value of span in X direction : ");
 44 |             double spanX = Convert.ToDouble(Console.ReadLine());
 45 | 
 46 |             Console.Write("Enter the number of spans in Y direction : ");
 47 |             int nSpanY = Convert.ToInt32(Console.ReadLine());
 48 |             Console.Write("Enter the value of span in Y direction : ");
 49 |             double spanY = Convert.ToDouble(Console.ReadLine());
 50 | 
 51 |             Console.Write("Enter the number of stories : ");
 52 |             int nStory = Convert.ToInt32(Console.ReadLine());
 53 |             Console.Write("Enter the value of story height : ");
 54 |             double storyHeight = Convert.ToDouble(Console.ReadLine());
 55 | 
 56 |             Console.Write("Do you want to display sap windows (0 For No) (any integer for Yes): ");
 57 |             bool showSap = Convert.ToBoolean(Convert.ToInt32(Console.ReadLine()));
 58 | 
 59 | 
 60 |             //setting model origin
 61 |             double originX = 0;
 62 |             double originY = 0;
 63 |             double originZ = 0;
 64 | 
 65 | 
 66 |             Console.WriteLine("Opening Sap Application ...... ");
 67 |             Console.WriteLine(".............................. ");
 68 | 
 69 | 
 70 |             //setting file path and file name
 71 |             string filePath = "C:\\CSiAPIexample";
 72 |             string fileName = "trial1";
 73 | 
 74 |             //initializing the model
 75 |             SapModel model = new SapModel(filePath, showSap, fileName);
 76 |             model.Initialize();
 77 | 
 78 |             //setting Sap units
 79 |             model.SapObjectModel.SetPresentUnits(eUnits.Ton_m_C);
 80 | 
 81 | 
 82 |             //creating material
 83 |             SapMaterial material1 = new SapMaterial(model.SapObjectModel, "FCU25", MaterialType.CONCRETE);
 84 |             material1.SetConcreteMaterial(2500);
 85 |             material1.SetIsotropic(2200000, 0.2, 9.900E-06);
 86 |             material1.SetWeight(2.5);
 87 | 
 88 |             //creating two sections
 89 |             SapRecangularSection B30x60 = new SapRecangularSection(model.SapObjectModel, material1, "B30x60", 0.30, 0.60, "this is a new rec section", "", -1);
 90 |             SapRecangularSection C30x30 = new SapRecangularSection(model.SapObjectModel, material1, "C30x30", 0.30, 0.30, "this is a new rec section", "", -1);
 91 | 
 92 |             //creating points 
 93 |             SapPoint[,,] points = new SapPoint[nSpanX + 1, nSpanY + 1, nStory + 1];
 94 |             for (int zStep = 0; zStep < nStory + 1; zStep++)
 95 |             {
 96 |                 for (int xStep = 0; xStep < nSpanX + 1; xStep++)
 97 |                 {
 98 |                     for (int yStep = 0; yStep < nSpanY + 1; yStep++)
 99 |                     {
100 |                         points[xStep, yStep, zStep] = new SapPoint(model.SapObjectModel, originX + xStep * spanX, originY + yStep * spanY, originZ + zStep * storyHeight);
101 |                     }
102 |                 }
103 |             }
104 | 
105 | 
106 |             //creating columns
107 |             SapFrameElement[,,] columns = new SapFrameElement[nSpanX + 1, nSpanY + 1, nStory];
108 |             for (int zStep = 0; zStep < nStory; zStep++)
109 |             {
110 |                 for (int xStep = 0; xStep < nSpanX + 1; xStep++)
111 |                 {
112 |                     for (int yStep = 0; yStep < nSpanY + 1; yStep++)
113 |                     {
114 |                         columns[xStep, yStep, zStep] = new SapFrameElement(model.SapObjectModel, points[xStep, yStep, zStep], points[xStep, yStep, zStep + 1], C30x30, $"col{xStep},{yStep},{zStep}", $"col{xStep},{yStep},{zStep}");
115 |                     }
116 |                 }
117 |             }
118 | 
119 |             //creating beams in X direction
120 |             SapFrameElement[,,] xBeams = new SapFrameElement[nSpanX, nSpanY + 1, nStory];
121 |             for (int zStep = 0; zStep < nStory; zStep++)
122 |             {
123 |                 for (int xStep = 0; xStep < nSpanX; xStep++)
124 |                 {
125 |                     for (int yStep = 0; yStep < nSpanY + 1; yStep++)
126 |                     {
127 |                         xBeams[xStep, yStep, zStep] = new SapFrameElement(model.SapObjectModel, points[xStep, yStep, zStep + 1], points[xStep + 1, yStep, zStep + 1], B30x60, $"xBeam{xStep},{yStep},{zStep}", $"xBeam{xStep},{yStep},{zStep}");
128 |                     }
129 |                 }
130 |             }
131 | 
132 |             //creating beams in Y direction
133 |             SapFrameElement[,,] yBeams = new SapFrameElement[nSpanX + 1, nSpanY, nStory];
134 |             for (int zStep = 0; zStep < nStory; zStep++)
135 |             {
136 |                 for (int xStep = 0; xStep < nSpanX + 1; xStep++)
137 |                 {
138 |                     for (int yStep = 0; yStep < nSpanY; yStep++)
139 |                     {
140 |                         yBeams[xStep, yStep, zStep] = new SapFrameElement(model.SapObjectModel, points[xStep, yStep, zStep + 1], points[xStep, yStep + 1, zStep + 1], B30x60, $"yBeam{xStep},{yStep},{zStep}", $"yBeam{xStep},{yStep},{zStep}");
141 |                     }
142 |                 }
143 |             }
144 | 
145 |             //setting base points as hinged
146 |             for (int xStep = 0; xStep < nSpanX + 1; xStep++)
147 |             {
148 |                 for (int yStep = 0; yStep < nSpanY + 1; yStep++)
149 |                 {
150 |                     points[xStep, yStep, 0].SetRestraint(Restrains.Pinned);
151 |                 }
152 |             }
153 | 
154 | 
155 | 
156 |             //adding load patterns D and L and setting last element as true to create corresponding load case
157 |             List loadPatternlist = new List();
158 |             SapLoadPattern deadLoadPattern = new SapLoadPattern(model.SapObjectModel, "D", LoadPatternType.Dead, 1, true);
159 |             loadPatternlist.Add(deadLoadPattern);
160 |             SapLoadPattern liveLoadPattern = new SapLoadPattern(model.SapObjectModel, "L", LoadPatternType.Live, 0, true);
161 |             loadPatternlist.Add(liveLoadPattern);
162 | 
163 |             //creating distributed loads
164 |             SapFrameDistLoad deadDistLoad = new SapFrameDistLoad(deadLoadPattern, 1, 2, 0, 1, -2, -2);
165 |             SapFrameDistLoad liveDistLoad = new SapFrameDistLoad(liveLoadPattern, 1, 2, 0, 1, -1.5, -1.5);
166 | 
167 |             //assigning loads to beams
168 |             foreach (var beam in xBeams)
169 |             {
170 |                 beam.AddDistributedLoad(deadDistLoad);
171 |                 beam.AddDistributedLoad(liveDistLoad);
172 |             }
173 |             foreach (var beam in yBeams)
174 |             {
175 |                 beam.AddDistributedLoad(deadDistLoad);
176 |                 beam.AddDistributedLoad(liveDistLoad);
177 |             }
178 | 
179 |             //adding earth quake load pattern
180 |             SapLoadPattern QuakeLoadPattern = new SapLoadPattern(model.SapObjectModel, "Qx", LoadPatternType.Quake, 0, true);
181 |             loadPatternlist.Add(QuakeLoadPattern);
182 | 
183 |             //creating point load in x direction
184 |             SapPointLoad QxPointLoad = new SapPointLoad(QuakeLoadPattern, new double[] { 10, 0, 0, 0, 0, 0 }, true);
185 | 
186 |             //assigning point load to points on the left of the building
187 |             for (int zStep = 1; zStep < nStory + 1; zStep++)
188 |             {
189 |                 for (int yStep = 0; yStep < nSpanY + 1; yStep++)
190 |                 {
191 |                     points[0, yStep, zStep].AddPointLoad(QxPointLoad);
192 |                 }
193 |             }
194 | 
195 | 
196 | 
197 |             model.RefreshView(0, false);
198 |             Console.WriteLine("Running Analysis ....");
199 |             model.RunAnalysis();
200 | 
201 | 
202 |             Console.WriteLine("Reading Results ....");
203 |             //reading the results 
204 |             foreach (var loadpattern in loadPatternlist)
205 |             {
206 |                 model.SapObjectModel.Results.Setup.DeselectAllCasesAndCombosForOutput();
207 |                 model.SapObjectModel.Results.Setup.SetCaseSelectedForOutput(loadpattern.Name, true);
208 | 
209 |                 foreach (var column in columns)
210 |                 {
211 |                     column.FrameResults.Add(new SapFrameResult(model.SapObjectModel, column.Label));
212 |                 }
213 |                 foreach (var beam in xBeams)
214 |                 {
215 |                     beam.FrameResults.Add(new SapFrameResult(model.SapObjectModel, beam.Label));
216 |                 }
217 |                 foreach (var beam in yBeams)
218 |                 {
219 |                     beam.FrameResults.Add(new SapFrameResult(model.SapObjectModel, beam.Label));
220 |                 }
221 |                 foreach (var point in points)
222 |                 {
223 |                     point.PointResults.Add(new SapPointResult(model.SapObjectModel, point.Name));
224 |                 }
225 | 
226 |             }
227 | 
228 | 
229 | 
230 |             Console.WriteLine("Finished , press any key to exit ");
231 |             Console.ReadLine();
232 | 
233 |             model.Close(true);
234 | 
235 |             #endregion
236 |         }
237 | 
238 |         static void RunSapTutorial()
239 |         {
240 |             #region SapTutorial
241 | 
242 |             //set the following flag to true to attach to an existing instance of the program
243 | 
244 |             //otherwise a new instance of the program will be started
245 | 
246 |             bool AttachToInstance;
247 | 
248 |             AttachToInstance = false;
249 | 
250 | 
251 | 
252 |             //set the following flag to true to manually specify the path to SAP2000.exe
253 | 
254 |             //this allows for a connection to a version of SAP2000 other than the latest installation
255 | 
256 |             //otherwise the latest installed version of SAP2000 will be launched
257 | 
258 |             bool SpecifyPath;
259 | 
260 |             SpecifyPath = false;
261 | 
262 | 
263 | 
264 |             //if the above flag is set to true, specify the path to SAP2000 below
265 | 
266 |             string ProgramPath;
267 | 
268 |             ProgramPath = "C:\\Program Files (x86)\\Computers and Structures\\SAP2000 19\\SAP2000.exe";
269 | 
270 | 
271 | 
272 |             //full path to the model
273 | 
274 |             //set it to the desired path of your model
275 | 
276 |             string ModelDirectory = "C:\\CSiAPIexample";
277 | 
278 |             try
279 |             {
280 |                 System.IO.Directory.CreateDirectory(ModelDirectory);
281 |             }
282 |             catch (Exception ex)
283 |             {
284 |                 Console.WriteLine("Could not create directory: " + ModelDirectory);
285 |             }
286 | 
287 |             string ModelName = "API_1-001.sdb";
288 |             string ModelPath = ModelDirectory + System.IO.Path.DirectorySeparatorChar + ModelName;
289 | 
290 | 
291 | 
292 |             //dimension the SapObject as cOAPI type
293 |             cOAPI mySapObject = null;
294 | 
295 | 
296 |             //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero)
297 |             int ret = 0;
298 | 
299 | 
300 |             // AttachToInstance -- initialized to False
301 |             if (AttachToInstance)
302 |             {
303 |                 //attach to a running instance of SAP2000
304 | 
305 |                 try
306 |                 {
307 |                     //get the active SapObject
308 |                     mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject");
309 |                 }
310 |                 catch (Exception ex)
311 |                 {
312 |                     Console.WriteLine("No running instance of the program found or failed to attach.");
313 |                     return;
314 |                 }
315 | 
316 |             }
317 |             else
318 |             {
319 |                 //create API helper object
320 |                 cHelper myHelper;
321 | 
322 |                 try
323 |                 {
324 |                     myHelper = new Helper();
325 |                 }
326 |                 catch (Exception ex)
327 |                 {
328 |                     Console.WriteLine("Cannot create an instance of the Helper object");
329 |                     return;
330 |                 }
331 | 
332 | 
333 |                 // SpecifyPath -- initialized to False
334 |                 if (SpecifyPath)
335 |                 {
336 |                     //'create an instance of the SapObject from the specified path
337 |                     try
338 |                     {
339 |                         //create SapObject
340 |                         mySapObject = myHelper.CreateObject(ProgramPath);
341 |                     }
342 |                     catch (Exception ex)
343 |                     {
344 |                         Console.WriteLine("Cannot start a new instance of the program from " + ProgramPath);
345 |                         return;
346 |                     }
347 | 
348 |                 }
349 |                 else
350 |                 {
351 |                     //'create an instance of the SapObject from the latest installed SAP2000
352 |                     try
353 |                     {
354 |                         //create SapObject
355 |                         mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject");
356 |                     }
357 |                     catch (Exception ex)
358 |                     {
359 |                         Console.WriteLine("Cannot start a new instance of the program.");
360 |                         return;
361 |                     }
362 | 
363 |                 }
364 | 
365 |                 //start SAP2000 application
366 |                 ret = mySapObject.ApplicationStart();
367 | 
368 |             }
369 | 
370 | 
371 | 
372 |             //create SapModel object
373 |             cSapModel mySapModel;
374 |             mySapModel = mySapObject.SapModel;
375 | 
376 | 
377 | 
378 |             //initialize model
379 |             //ret = mySapModel.InitializeNewModel((eUnits.kN_mm_C));
380 |             ret = mySapModel.InitializeNewModel((eUnits.kip_in_F));
381 | 
382 | 
383 | 
384 |             //create new blank model
385 |             ret = mySapModel.File.NewBlank();
386 | 
387 | 
388 | 
389 |             //define material property
390 |             ret = mySapModel.PropMaterial.SetMaterial("CONC", eMatType.Concrete, -1, "", "");
391 | 
392 | 
393 | 
394 |             //assign isotropic mechanical properties to material
395 |             ret = mySapModel.PropMaterial.SetMPIsotropic("CONC", 3600, 0.2, 0.0000055, 0);
396 | 
397 | 
398 | 
399 |             //define rectangular frame section property
400 |             ret = mySapModel.PropFrame.SetRectangle("R1", "CONC", 12, 12, -1, "", "");
401 | 
402 | 
403 | 
404 |             //define frame section property modifiers
405 |             double[] ModValue = new double[8];
406 |             int i;
407 |             for (i = 0; i <= 7; i++)
408 |             {
409 |                 ModValue[i] = 1;
410 |             }
411 | 
412 |             ModValue[0] = 1000;
413 |             ModValue[1] = 0;
414 |             ModValue[2] = 0;
415 | 
416 |             ret = mySapModel.PropFrame.SetModifiers("R1", ref ModValue);
417 | 
418 | 
419 | 
420 |             //switch to k-ft units
421 |             ret = mySapModel.SetPresentUnits(eUnits.kip_ft_F);
422 | 
423 | 
424 | 
425 |             //add frame object by coordinates
426 |             string[] FrameName = new string[3];
427 |             string temp_string1 = FrameName[0];
428 |             string temp_string2 = FrameName[0];
429 | 
430 |             // ret = mySapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, ref temp_string1, "R1"/*Property*/, "1"/*Label*/, "Global");
431 |             FrameName[0] = temp_string1;
432 | 
433 |             //  ret = mySapModel.FrameObj.AddByCoord(0, 0, 10, 8, 0, 16, ref temp_string1, "R1", "2", "Global");
434 |             FrameName[1] = temp_string1;
435 | 
436 |             ret = mySapModel.FrameObj.AddByCoord(-4, 0, 10, 0, 0, 10, ref temp_string1, "R1", "3", "Global");
437 |             FrameName[2] = temp_string1;
438 |             string framename = "";
439 |             SapMaterial s = new SapMaterial(mySapModel, "ff", MaterialType.CONCRETE);
440 |             SapRecangularSection srs = new SapRecangularSection(mySapModel, s, "fouad", 12, 25, "", "", -1);
441 |             SapFrameElement sfm = new SapFrameElement(mySapModel, 0, 0, 0, 0, 0, 10, "ah", "");
442 |             SapPoint point1 = new SapPoint(mySapModel, 0, 0, 10);
443 |             SapPoint point2 = new SapPoint(mySapModel, 8, 0, 16);
444 |             SapFrameElement sfm2 = new SapFrameElement(mySapModel, point1, point2, "", "fo2sh");
445 |             SapLoadPattern loadpattern = new SapLoadPattern(mySapModel, "m", LoadPatternType.Other, 0, true);
446 |             SapFrameDistLoad distload = new SapFrameDistLoad(loadpattern, 1, 2, 0, 1, 2, 2);
447 |             sfm2.AddDistributedLoad(distload);
448 |             point2.SetRestraint(Restrains.Fixed);
449 |             SapPointLoad pload = new SapPointLoad(loadpattern, new double[] { 1, 2, 3, 4, 5, 6 }, true);
450 |             point2.AddPointLoad(pload);
451 |             //sfm.Point1.SetRestraint(Restrains.Fixed);
452 |             //assign point object restraint at base
453 |             string[] PointName = new string[2];
454 |             bool[] Restraint = new bool[6];
455 |             for (i = 0; i <= 3; i++)
456 |             {
457 |                 Restraint[i] = true;
458 |             }
459 |             for (i = 4; i <= 5; i++)
460 |             {
461 |                 Restraint[i] = false;
462 |             }
463 | 
464 |             ret = mySapModel.FrameObj.GetPoints(FrameName[0], ref temp_string1, ref temp_string2);
465 |             PointName[0] = temp_string1;
466 |             PointName[1] = temp_string2;
467 | 
468 |             ret = mySapModel.PointObj.SetRestraint(PointName[0], ref Restraint, 0);
469 | 
470 | 
471 | 
472 |             //assign point object restraint at top
473 |             for (i = 0; i <= 1; i++)
474 |             {
475 |                 Restraint[i] = true;
476 |             }
477 |             for (i = 2; i <= 5; i++)
478 |             {
479 |                 Restraint[i] = false;
480 |             }
481 | 
482 |             ret = mySapModel.FrameObj.GetPoints(FrameName[1], ref temp_string1, ref temp_string2);
483 |             PointName[0] = temp_string1;
484 |             PointName[1] = temp_string2;
485 | 
486 |             ret = mySapModel.PointObj.SetRestraint(PointName[1], ref Restraint, 0);
487 | 
488 | 
489 | 
490 |             //refresh view, update (initialize) zoom
491 |             bool temp_bool = false;
492 |             ret = mySapModel.View.RefreshView(0, temp_bool);
493 | 
494 | 
495 | 
496 |             //add load patterns
497 |             temp_bool = true;
498 |             ret = mySapModel.LoadPatterns.Add("1", eLoadPatternType.Other, 1, temp_bool);
499 |             ret = mySapModel.LoadPatterns.Add("2", eLoadPatternType.Other, 0, temp_bool);
500 |             ret = mySapModel.LoadPatterns.Add("3", eLoadPatternType.Other, 0, temp_bool);
501 |             ret = mySapModel.LoadPatterns.Add("4", eLoadPatternType.Other, 0, temp_bool);
502 |             ret = mySapModel.LoadPatterns.Add("5", eLoadPatternType.Other, 0, temp_bool);
503 |             ret = mySapModel.LoadPatterns.Add("6", eLoadPatternType.Other, 0, temp_bool);
504 |             ret = mySapModel.LoadPatterns.Add("7", eLoadPatternType.Other, 0, temp_bool);
505 | 
506 | 
507 | 
508 |             //assign loading for load pattern 2
509 |             ret = mySapModel.FrameObj.GetPoints(FrameName[2], ref temp_string1, ref temp_string2);
510 |             PointName[0] = temp_string1;
511 |             PointName[1] = temp_string2;
512 |             double[] PointLoadValue = new double[6];
513 |             PointLoadValue[2] = -10;
514 |             ret = mySapModel.PointObj.SetLoadForce(PointName[0], "2", ref PointLoadValue, false, "Global", 0);
515 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[2], "2", 1, 10, 0, 1, 1.8, 1.8, "Global", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
516 | 
517 | 
518 | 
519 |             //assign loading for load pattern 3
520 |             ret = mySapModel.FrameObj.GetPoints(FrameName[2], ref temp_string1, ref temp_string2);
521 |             PointName[0] = temp_string1;
522 |             PointName[1] = temp_string2;
523 |             PointLoadValue = new double[6];
524 |             PointLoadValue[2] = -17.2;
525 |             PointLoadValue[4] = -54.4;
526 |             ret = mySapModel.PointObj.SetLoadForce(PointName[1], "3", ref PointLoadValue, false, "Global", 0);
527 | 
528 | 
529 | 
530 | 
531 |             //assign loading for load pattern 4
532 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "4", 1, 11, 0, 1, 2, 2, "Global", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
533 | 
534 | 
535 | 
536 |             //assign loading for load pattern 5
537 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[0], "5", 1, 2, 0, 1, 2, 2, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
538 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "5", 1, 2, 0, 1, -2, -2, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
539 | 
540 | 
541 | 
542 |             //assign loading for load pattern 6
543 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[0], "6", 1, 2, 0, 1, 0.9984, 0.3744, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
544 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "6", 1, 2, 0, 1, -0.3744, 0, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
545 | 
546 | 
547 | 
548 |             //assign loading for load pattern 7
549 |             ret = mySapModel.FrameObj.SetLoadPoint(FrameName[1], "7", 1, 2, 0.5, -15, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
550 | 
551 | 
552 | 
553 |             //switch to k-in units
554 |             ret = mySapModel.SetPresentUnits(eUnits.kip_in_F);
555 | 
556 | 
557 | 
558 |             //save model
559 |             ret = mySapModel.File.Save(ModelPath);
560 | 
561 | 
562 | 
563 |             //run model (this will create the analysis model)
564 |             ret = mySapModel.Analyze.RunAnalysis();
565 | 
566 | 
567 | 
568 |             //initialize for SAP2000 results
569 |             double[] SapResult = new double[7];
570 |             ret = mySapModel.FrameObj.GetPoints(FrameName[1], ref temp_string1, ref temp_string2);
571 | 
572 |             PointName[0] = temp_string1;
573 |             PointName[1] = temp_string2;
574 | 
575 | 
576 | 
577 |             //get SAP2000 results for load patterns 1 through 7           
578 |             int NumberResults = 0;
579 |             string[] Obj = new string[1];
580 |             string[] Elm = new string[1];
581 |             string[] LoadCase = new string[1];
582 |             string[] StepType = new string[1];
583 |             double[] StepNum = new double[1];
584 | 
585 |             double[] U1 = new double[1];
586 |             double[] U2 = new double[1];
587 |             double[] U3 = new double[1];
588 |             double[] R1 = new double[1];
589 |             double[] R2 = new double[1];
590 |             double[] R3 = new double[1];
591 | 
592 |             for (i = 0; i <= 6; i++)
593 |             {
594 |                 ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput();
595 |                 ret = mySapModel.Results.Setup.SetCaseSelectedForOutput(System.Convert.ToString(i + 1), System.Convert.ToBoolean(-1));
596 | 
597 |                 if (i <= 3)
598 |                 {
599 |                     ret = mySapModel.Results.JointDispl(PointName[1], eItemTypeElm.ObjectElm, ref NumberResults, ref Obj, ref Elm, ref LoadCase, ref StepType, ref StepNum, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3);
600 |                     U3.CopyTo(U3, 0);
601 |                     SapResult[i] = U3[0];
602 |                 }
603 |                 else
604 |                 {
605 |                     ret = mySapModel.Results.JointDispl(PointName[0], eItemTypeElm.ObjectElm, ref NumberResults, ref Obj, ref Elm, ref LoadCase, ref StepType, ref StepNum, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3);
606 |                     U1.CopyTo(U1, 0);
607 |                     SapResult[i] = U1[0];
608 |                 }
609 | 
610 |             }
611 | 
612 | 
613 | 
614 |             //close SAP2000
615 | 
616 |             mySapObject.ApplicationExit(false);
617 |             mySapModel = null;
618 |             mySapObject = null;
619 | 
620 | 
621 | 
622 |             //fill SAP2000 result strings
623 |             string[] SapResultString = new string[7];
624 |             for (i = 0; i <= 6; i++)
625 |             {
626 |                 SapResultString[i] = string.Format("{0:0.00000}", SapResult[i]);
627 |                 ret = (string.Compare(SapResultString[i], 1, "-", 1, 1, true));
628 |                 if (ret != 0)
629 |                 {
630 |                     SapResultString[i] = " " + SapResultString[i];
631 |                 }
632 | 
633 |             }
634 | 
635 | 
636 | 
637 |             //fill independent results
638 |             double[] IndResult = new double[7];
639 |             string[] IndResultString = new string[7];
640 |             IndResult[0] = -0.02639;
641 |             IndResult[1] = 0.06296;
642 |             IndResult[2] = 0.06296;
643 |             IndResult[3] = -0.2963;
644 |             IndResult[4] = 0.3125;
645 |             IndResult[5] = 0.11556;
646 |             IndResult[6] = 0.00651;
647 |             for (i = 0; i <= 6; i++)
648 |             {
649 | 
650 |                 IndResultString[i] = string.Format("{0:0.00000}", IndResult[i]);
651 |                 ret = (string.Compare(IndResultString[i], 1, "-", 1, 1, true));
652 |                 if (ret != 0)
653 |                 {
654 |                     IndResultString[i] = " " + IndResultString[i];
655 |                 }
656 | 
657 |             }
658 | 
659 | 
660 | 
661 |             //fill percent difference
662 |             double[] PercentDiff = new double[7];
663 |             string[] PercentDiffString = new string[7];
664 |             for (i = 0; i <= 6; i++)
665 |             {
666 |                 PercentDiff[i] = (SapResult[i] / IndResult[i]) - 1;
667 |                 PercentDiffString[i] = string.Format("{0:0%}", PercentDiff[i]);
668 |                 ret = (string.Compare(PercentDiffString[i], 1, "-", 1, 1, true));
669 |                 if (ret != 0)
670 |                 {
671 |                     PercentDiffString[i] = " " + PercentDiffString[i];
672 |                 }
673 | 
674 |             }
675 | 
676 | 
677 | 
678 |             //display message box comparing results
679 |             string msg = "";
680 |             msg = msg + "LC  Sap2000  Independent  %Diff\r\n";
681 |             for (i = 0; i <= 5; i++)
682 |             {
683 |                 msg = msg + string.Format("{0:0}", i + 1) + "    " + SapResultString[i] + "   " + IndResultString[i] + "       " + PercentDiffString[i] + "\r\n";
684 |             }
685 | 
686 | 
687 |             msg = msg + string.Format("{0:0}", i + 1) + "    " + SapResultString[i] + "   " + IndResultString[i] + "       " + PercentDiffString[i];
688 |             Console.WriteLine(msg);
689 |             Console.ReadKey();
690 | 
691 |             #endregion
692 |         }
693 |     }
694 | }
695 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
 1 | using System.Reflection;
 2 | using System.Runtime.CompilerServices;
 3 | using System.Runtime.InteropServices;
 4 | 
 5 | // General Information about an assembly is controlled through the following
 6 | // set of attributes. Change these attribute values to modify the information
 7 | // associated with an assembly.
 8 | [assembly: AssemblyTitle("SAP.API.Initial")]
 9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SAP.API.Initial")]
13 | [assembly: AssemblyCopyright("Copyright ©  2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 | 
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components.  If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 | 
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("8d9d80d8-c20c-4236-ab5a-e99ad2af8c98")]
24 | 
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | //      Major Version
28 | //      Minor Version
29 | //      Build Number
30 | //      Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SAP.API.Initial.csproj:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 |   
 4 |   
 5 |     Debug
 6 |     AnyCPU
 7 |     {8D9D80D8-C20C-4236-AB5A-E99AD2AF8C98}
 8 |     Exe
 9 |     SAP.API.Initial
10 |     SAP.API.Initial
11 |     v4.5.2
12 |     512
13 |     true
14 |   
15 |   
16 |     AnyCPU
17 |     true
18 |     full
19 |     false
20 |     bin\Debug\
21 |     DEBUG;TRACE
22 |     prompt
23 |     4
24 |   
25 |   
26 |     AnyCPU
27 |     pdbonly
28 |     true
29 |     bin\Release\
30 |     TRACE
31 |     prompt
32 |     4
33 |   
34 |   
35 |     
36 |       ExternalReferences\SAP2000v19.dll
37 |     
38 |     
39 |       ExternalReferences\SAP2000v20.dll
40 |     
41 |     
42 |     
43 |     
44 |     
45 |     
46 |     
47 |     
48 |     
49 |   
50 |   
51 |     
52 |     
53 |     
54 |     
55 |     
56 |     
57 |     
58 |     
59 |     
60 |     
61 |     
62 |     
63 |     
64 |     
65 |   
66 |   
67 |     
68 |   
69 |   
70 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SAP.API.Initial.csproj.user:
--------------------------------------------------------------------------------
1 | 
2 | 
3 |   
4 |     ProjectFiles
5 |   
6 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SAPModel.cs:
--------------------------------------------------------------------------------
  1 | using System;
  2 | using System.Collections.Generic;
  3 | using System.Linq;
  4 | using System.Text;
  5 | using System.Threading.Tasks;
  6 | using SAP2000v20;
  7 | namespace SAP.API.Initial
  8 | {
  9 |     public enum SapUnits
 10 |     {
 11 |         lb_in_F = 1,
 12 |         lb_ft_F = 2,
 13 |         kip_in_F = 3,
 14 |         kip_ft_F = 4,
 15 |         kN_mm_C = 5,
 16 |         kN_m_C = 6,
 17 |         kgf_mm_C = 7,
 18 |         kgf_m_C = 8,
 19 |         N_mm_C = 9,
 20 |         N_m_C = 10,
 21 |         Ton_mm_C = 11,
 22 |         Ton_m_C = 12,
 23 |         kN_cm_C = 13,
 24 |         kgf_cm_C = 14,
 25 |         N_cm_C = 15,
 26 |         Ton_cm_C = 16
 27 |     }
 28 |     class SapModel
 29 |     {
 30 |         public bool AttachToInstance { get; set; }
 31 | 
 32 |         public bool SpecifyPath { get; set; }
 33 |         public string ModelDirectory { get; set; }
 34 |         public string ModelName { get; set; }
 35 |         public string ModelPath { get; set; }
 36 |         public cSapModel SapObjectModel { get; set; }
 37 |         private cOAPI sapObjectAPI;
 38 | 
 39 |         #region Constructors
 40 |         public SapModel(string ModelDirectory, bool visible = false,string ModelName = "Untitled-API")
 41 |         {
 42 |             this.ModelDirectory = ModelDirectory;
 43 |             this.ModelName = ModelName;
 44 | 
 45 |             //set the following flag to true to attach to an existing instance of the program
 46 |             //otherwise a new instance of the program will be started
 47 | 
 48 |             AttachToInstance = false;
 49 | 
 50 |             //set the following flag to true to manually specify the path to SAP2000.exe
 51 | 
 52 |             //this allows for a connection to a version of SAP2000 other than the latest installation
 53 | 
 54 |             //otherwise the latest installed version of SAP2000 will be launched
 55 | 
 56 |             SpecifyPath = false;
 57 | 
 58 |             //if the above flag is set to true, specify the path to SAP2000 below
 59 | 
 60 |             string ProgramPath;
 61 | 
 62 |             ProgramPath = "C:\\Program Files (x86)\\Computers and Structures\\SAP2000 20\\SAP2000.exe";
 63 | 
 64 |             //full path to the model
 65 | 
 66 |             //set it to the desired path of your model
 67 | 
 68 |             try
 69 | 
 70 |             {
 71 | 
 72 |                 System.IO.Directory.CreateDirectory(ModelDirectory);
 73 | 
 74 |             }
 75 | 
 76 |             catch (Exception ex)
 77 | 
 78 |             {
 79 | 
 80 |                 Console.WriteLine("Could not create directory: " + ModelDirectory);
 81 | 
 82 |             }
 83 | 
 84 | 
 85 | 
 86 |              ModelPath = ModelDirectory + System.IO.Path.DirectorySeparatorChar + ModelName;
 87 | 
 88 | 
 89 | 
 90 |             //dimension the SapObject as cOAPI type
 91 | 
 92 |              sapObjectAPI = null;
 93 | 
 94 | 
 95 | 
 96 |             //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero)
 97 | 
 98 |             int ret = 0;
 99 | 
100 | 
101 | 
102 |             if (AttachToInstance)
103 | 
104 |             {
105 |                 //attach to a running instance of SAP2000
106 |                 try
107 | 
108 |                 {
109 |                     //get the active SapObject
110 |                     sapObjectAPI = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject");
111 |                 }
112 | 
113 |                 catch (Exception ex)
114 | 
115 |                 {
116 |                     Console.WriteLine("No running instance of the program found or failed to attach.");
117 |                     return;
118 |                 }
119 |             }
120 | 
121 |             else
122 | 
123 |             {
124 |                 //create API helper object
125 |                 cHelper myHelper;
126 |                 try
127 | 
128 |                 {
129 |                     myHelper = new Helper();
130 |                 }
131 | 
132 |                 catch (Exception ex)
133 | 
134 |                 {
135 | 
136 |                     Console.WriteLine("Cannot create an instance of the Helper object");
137 | 
138 |                     return;
139 | 
140 |                 }
141 | 
142 | 
143 | 
144 |                 if (SpecifyPath)
145 | 
146 |                 {
147 |                     //'create an instance of the SapObject from the specified path
148 |                     try
149 | 
150 |                     {
151 |                         //create SapObject
152 | 
153 |                         sapObjectAPI = myHelper.CreateObject(ProgramPath);
154 |                     }
155 | 
156 |                     catch (Exception ex)
157 | 
158 |                     {
159 |                         Console.WriteLine("Cannot start a new instance of the program from " + ProgramPath);
160 |                         return;
161 |                     }
162 | 
163 |                 }
164 | 
165 |                 else
166 | 
167 |                 {
168 | 
169 |                     //'create an instance of the SapObject from the latest installed SAP2000
170 | 
171 |                     try
172 | 
173 |                     {
174 |                         //create SapObject
175 | 
176 |                         sapObjectAPI = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject");
177 | 
178 |                     }
179 | 
180 |                     catch (Exception ex)
181 | 
182 |                     {
183 |                         Console.WriteLine("Cannot start a new instance of the program.");
184 | 
185 |                         return;
186 |                     }
187 |                 }
188 |                 //start SAP2000 application
189 |                 
190 |                 ret = sapObjectAPI.ApplicationStart((eUnits)SapUnits.N_m_C,visible,"FileName");
191 |                // mySapObject.Hide();
192 |             }
193 | 
194 |             //create SapModel object
195 |             SapObjectModel = sapObjectAPI.SapModel;
196 |         }
197 | 
198 | 
199 |         #endregion
200 |         #region Methods
201 |         
202 |         public int Initialize(SapUnits sapUnits=SapUnits.N_m_C)
203 |         {   
204 |             //initialize model
205 |             SapObjectModel.InitializeNewModel((eUnits)sapUnits);
206 |             //create new blank model
207 |            return  SapObjectModel.File.NewBlank();
208 |             
209 |         }
210 |         public int RefreshView(int window=0,bool zoom=false)
211 |         {
212 |             return SapObjectModel.View.RefreshView(window, zoom);
213 |         }
214 | 
215 |         public void RunAnalysis()
216 |         {
217 |             SapObjectModel.File.Save(ModelPath);
218 |             SapObjectModel.Analyze.RunAnalysis();
219 |         }
220 | 
221 |         public void Close(bool FileSave=true)
222 |         {
223 |             if (FileSave)
224 |             {
225 |                 SapObjectModel.File.Save(ModelPath);
226 |             }
227 |             
228 |             sapObjectAPI.ApplicationExit(FileSave);
229 |             SapObjectModel = null;
230 |             sapObjectAPI = null;
231 |         }
232 |         #endregion
233 |     }
234 | }
235 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapExample.cs:
--------------------------------------------------------------------------------
  1 | using System;
  2 | using System.Collections.Generic;
  3 | using System.Linq;
  4 | using System.Text;
  5 | using System.Threading.Tasks;
  6 | using SAP2000v20;
  7 | 
  8 | namespace SAP.API.Initial
  9 | {
 10 |     class SapExample
 11 |     {
 12 |         public static void SapExampleMain()
 13 |         {
 14 |             //set the following flag to true to attach to an existing instance of the program
 15 | 
 16 |             //otherwise a new instance of the program will be started
 17 | 
 18 |             bool AttachToInstance;
 19 | 
 20 |             AttachToInstance = false;
 21 | 
 22 | 
 23 | 
 24 |             //set the following flag to true to manually specify the path to SAP2000.exe
 25 | 
 26 |             //this allows for a connection to a version of SAP2000 other than the latest installation
 27 | 
 28 |             //otherwise the latest installed version of SAP2000 will be launched
 29 | 
 30 |             bool SpecifyPath;
 31 | 
 32 |             SpecifyPath = false;
 33 | 
 34 | 
 35 | 
 36 |             //if the above flag is set to true, specify the path to SAP2000 below
 37 | 
 38 |             string ProgramPath;
 39 | 
 40 |             ProgramPath = "C:\\Program Files (x86)\\Computers and Structures\\SAP2000 19\\SAP2000.exe";
 41 | 
 42 | 
 43 | 
 44 |             //full path to the model
 45 | 
 46 |             //set it to the desired path of your model
 47 | 
 48 |             string ModelDirectory = "C:\\CSiAPIexample";
 49 | 
 50 |             try
 51 |             {
 52 |                 System.IO.Directory.CreateDirectory(ModelDirectory);
 53 |             }
 54 |             catch (Exception ex)
 55 |             {
 56 |                 Console.WriteLine("Could not create directory: " + ModelDirectory);
 57 |             }
 58 | 
 59 |             string ModelName = "API_1-001.sdb";
 60 |             string ModelPath = ModelDirectory + System.IO.Path.DirectorySeparatorChar + ModelName;
 61 | 
 62 | 
 63 | 
 64 |             //dimension the SapObject as cOAPI type
 65 |             cOAPI mySapObject = null;
 66 | 
 67 | 
 68 |             //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero)
 69 |             int ret = 0;
 70 | 
 71 | 
 72 |             // AttachToInstance -- initialized to False
 73 |             if (AttachToInstance)
 74 |             {
 75 |                 //attach to a running instance of SAP2000
 76 | 
 77 |                 try
 78 |                 {
 79 |                     //get the active SapObject
 80 |                     mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject");
 81 |                 }
 82 |                 catch (Exception ex)
 83 |                 {
 84 |                     Console.WriteLine("No running instance of the program found or failed to attach.");
 85 |                     return;
 86 |                 }
 87 | 
 88 |             }
 89 |             else
 90 |             {
 91 |                 //create API helper object
 92 |                 cHelper myHelper;
 93 | 
 94 |                 try
 95 |                 {
 96 |                     myHelper = new Helper();
 97 |                 }
 98 |                 catch (Exception ex)
 99 |                 {
100 |                     Console.WriteLine("Cannot create an instance of the Helper object");
101 |                     return;
102 |                 }
103 | 
104 | 
105 |                 // SpecifyPath -- initialized to False
106 |                 if (SpecifyPath)
107 |                 {
108 |                     //'create an instance of the SapObject from the specified path
109 |                     try
110 |                     {
111 |                         //create SapObject
112 |                         mySapObject = myHelper.CreateObject(ProgramPath);
113 |                     }
114 |                     catch (Exception ex)
115 |                     {
116 |                         Console.WriteLine("Cannot start a new instance of the program from " + ProgramPath);
117 |                         return;
118 |                     }
119 | 
120 |                 }
121 |                 else
122 |                 {
123 |                     //'create an instance of the SapObject from the latest installed SAP2000
124 |                     try
125 |                     {
126 |                         //create SapObject
127 |                         mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject");
128 |                     }
129 |                     catch (Exception ex)
130 |                     {
131 |                         Console.WriteLine("Cannot start a new instance of the program.");
132 |                         return;
133 |                     }
134 | 
135 |                 }
136 | 
137 |                 //start SAP2000 application
138 |                 ret = mySapObject.ApplicationStart();
139 | 
140 |             }
141 | 
142 | 
143 | 
144 |             //create SapModel object
145 |             cSapModel mySapModel;
146 |             mySapModel = mySapObject.SapModel;
147 | 
148 | 
149 | 
150 |             //initialize model
151 |             //ret = mySapModel.InitializeNewModel((eUnits.kN_mm_C));
152 |             ret = mySapModel.InitializeNewModel((eUnits.kip_in_F));
153 | 
154 | 
155 | 
156 |             //create new blank model
157 |             ret = mySapModel.File.NewBlank();
158 | 
159 | 
160 | 
161 |             //define material property
162 |             ret = mySapModel.PropMaterial.SetMaterial("CONC", eMatType.Concrete, -1, "", "");
163 | 
164 | 
165 | 
166 |             //assign isotropic mechanical properties to material
167 |             ret = mySapModel.PropMaterial.SetMPIsotropic("CONC", 3600, 0.2, 0.0000055, 0);
168 | 
169 | 
170 | 
171 |             //define rectangular frame section property
172 |             ret = mySapModel.PropFrame.SetRectangle("R1", "CONC", 12, 12, -1, "", "");
173 | 
174 | 
175 | 
176 |             //define frame section property modifiers
177 |             double[] ModValue = new double[8];
178 |             int i;
179 |             for (i = 0; i <= 7; i++)
180 |             {
181 |                 ModValue[i] = 1;
182 |             }
183 | 
184 |             ModValue[0] = 1000;
185 |             ModValue[1] = 0;
186 |             ModValue[2] = 0;
187 | 
188 |             ret = mySapModel.PropFrame.SetModifiers("R1", ref ModValue);
189 | 
190 | 
191 | 
192 |             //switch to k-ft units
193 |             ret = mySapModel.SetPresentUnits(eUnits.kip_ft_F);
194 | 
195 | 
196 | 
197 |             //add frame object by coordinates
198 |             string[] FrameName = new string[3];
199 |             string temp_string1 = FrameName[0];
200 |             string temp_string2 = FrameName[0];
201 | 
202 |            // ret = mySapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, ref temp_string1, "R1"/*Property*/, "1"/*Label*/, "Global");
203 |             FrameName[0] = temp_string1;
204 | 
205 |           //  ret = mySapModel.FrameObj.AddByCoord(0, 0, 10, 8, 0, 16, ref temp_string1, "R1", "2", "Global");
206 |             FrameName[1] = temp_string1;
207 | 
208 |             ret = mySapModel.FrameObj.AddByCoord(-4, 0, 10, 0, 0, 10, ref temp_string1, "R1", "3", "Global");
209 |             FrameName[2] = temp_string1;
210 |             string framename = "";
211 |             SapMaterial s = new SapMaterial(mySapModel, "ff",MaterialType.CONCRETE);
212 |             SapRecangularSection srs = new SapRecangularSection(mySapModel, s, "fouad", 12, 25, "", "", -1);
213 |             SapFrameElement sfm = new SapFrameElement(mySapModel, 0, 0, 0, 0, 0, 10, "ah", "");
214 |             SapPoint point1 = new SapPoint(mySapModel, 0, 0, 10);
215 |             SapPoint point2 = new SapPoint(mySapModel, 8, 0, 16);
216 |             SapFrameElement sfm2 = new SapFrameElement(mySapModel, point1, point2, "", "fo2sh");
217 |             SapLoadPattern loadpattern = new SapLoadPattern(mySapModel,"m", LoadPatternType.Other, 0, true);
218 |             SapFrameDistLoad distload = new SapFrameDistLoad(loadpattern, 1, 2, 0,1, 2, 2);
219 |             sfm2.AddDistributedLoad(distload);
220 |             point2.SetRestraint(Restrains.Fixed);
221 |             SapPointLoad pload = new SapPointLoad(loadpattern, new double[] { 1, 2, 3, 4, 5, 6 }, true);
222 |             point2.AddPointLoad(pload);
223 |             //sfm.Point1.SetRestraint(Restrains.Fixed);
224 |             //assign point object restraint at base
225 |             string[] PointName = new string[2];
226 |             bool[] Restraint = new bool[6];
227 |             for (i = 0; i <= 3; i++)
228 |             {
229 |                 Restraint[i] = true;
230 |             }
231 |             for (i = 4; i <= 5; i++)
232 |             {
233 |                 Restraint[i] = false;
234 |             }
235 | 
236 |             ret = mySapModel.FrameObj.GetPoints(FrameName[0], ref temp_string1, ref temp_string2);
237 |             PointName[0] = temp_string1;
238 |             PointName[1] = temp_string2;
239 | 
240 |             ret = mySapModel.PointObj.SetRestraint(PointName[0], ref Restraint, 0);
241 | 
242 | 
243 | 
244 |             //assign point object restraint at top
245 |             for (i = 0; i <= 1; i++)
246 |             {
247 |                 Restraint[i] = true;
248 |             }
249 |             for (i = 2; i <= 5; i++)
250 |             {
251 |                 Restraint[i] = false;
252 |             }
253 | 
254 |             ret = mySapModel.FrameObj.GetPoints(FrameName[1], ref temp_string1, ref temp_string2);
255 |             PointName[0] = temp_string1;
256 |             PointName[1] = temp_string2;
257 | 
258 |             ret = mySapModel.PointObj.SetRestraint(PointName[1], ref Restraint, 0);
259 | 
260 | 
261 | 
262 |             //refresh view, update (initialize) zoom
263 |             bool temp_bool = false;
264 |             ret = mySapModel.View.RefreshView(0, temp_bool);
265 | 
266 | 
267 | 
268 |             //add load patterns
269 |             temp_bool = true;
270 |             ret = mySapModel.LoadPatterns.Add("1", eLoadPatternType.Other, 1, temp_bool);
271 |             ret = mySapModel.LoadPatterns.Add("2", eLoadPatternType.Other, 0, temp_bool);
272 |             ret = mySapModel.LoadPatterns.Add("3", eLoadPatternType.Other, 0, temp_bool);
273 |             ret = mySapModel.LoadPatterns.Add("4", eLoadPatternType.Other, 0, temp_bool);
274 |             ret = mySapModel.LoadPatterns.Add("5", eLoadPatternType.Other, 0, temp_bool);
275 |             ret = mySapModel.LoadPatterns.Add("6", eLoadPatternType.Other, 0, temp_bool);
276 |             ret = mySapModel.LoadPatterns.Add("7", eLoadPatternType.Other, 0, temp_bool);
277 | 
278 | 
279 | 
280 |             //assign loading for load pattern 2
281 |             ret = mySapModel.FrameObj.GetPoints(FrameName[2], ref temp_string1, ref temp_string2);
282 |             PointName[0] = temp_string1;
283 |             PointName[1] = temp_string2;
284 |             double[] PointLoadValue = new double[6];
285 |             PointLoadValue[2] = -10;
286 |             ret = mySapModel.PointObj.SetLoadForce(PointName[0], "2", ref PointLoadValue, false, "Global", 0);
287 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[2], "2", 1, 10, 0, 1, 1.8, 1.8, "Global", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
288 | 
289 | 
290 | 
291 |             //assign loading for load pattern 3
292 |             ret = mySapModel.FrameObj.GetPoints(FrameName[2], ref temp_string1, ref temp_string2);
293 |             PointName[0] = temp_string1;
294 |             PointName[1] = temp_string2;
295 |             PointLoadValue = new double[6];
296 |             PointLoadValue[2] = -17.2;
297 |             PointLoadValue[4] = -54.4;
298 |             ret = mySapModel.PointObj.SetLoadForce(PointName[1], "3", ref PointLoadValue, false, "Global", 0);
299 |             
300 | 
301 | 
302 | 
303 |             //assign loading for load pattern 4
304 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "4", 1, 11, 0, 1, 2, 2, "Global", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
305 | 
306 | 
307 | 
308 |             //assign loading for load pattern 5
309 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[0], "5", 1, 2, 0, 1, 2, 2, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
310 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "5", 1, 2, 0, 1, -2, -2, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
311 | 
312 | 
313 | 
314 |             //assign loading for load pattern 6
315 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[0], "6", 1, 2, 0, 1, 0.9984, 0.3744, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
316 |             ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "6", 1, 2, 0, 1, -0.3744, 0, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
317 | 
318 | 
319 | 
320 |             //assign loading for load pattern 7
321 |             ret = mySapModel.FrameObj.SetLoadPoint(FrameName[1], "7", 1, 2, 0.5, -15, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0);
322 | 
323 | 
324 | 
325 |             //switch to k-in units
326 |             ret = mySapModel.SetPresentUnits(eUnits.kip_in_F);
327 | 
328 | 
329 | 
330 |             //save model
331 |             ret = mySapModel.File.Save(ModelPath);
332 | 
333 | 
334 | 
335 |             //run model (this will create the analysis model)
336 |             ret = mySapModel.Analyze.RunAnalysis();
337 | 
338 | 
339 | 
340 |             //initialize for SAP2000 results
341 |             double[] SapResult = new double[7];
342 |             ret = mySapModel.FrameObj.GetPoints(FrameName[1], ref temp_string1, ref temp_string2);
343 | 
344 |             PointName[0] = temp_string1;
345 |             PointName[1] = temp_string2;
346 | 
347 | 
348 | 
349 |             //get SAP2000 results for load patterns 1 through 7           
350 |             int NumberResults = 0;
351 |             string[] Obj = new string[1];
352 |             string[] Elm = new string[1];
353 |             string[] LoadCase = new string[1];
354 |             string[] StepType = new string[1];
355 |             double[] StepNum = new double[1];
356 | 
357 |             double[] U1 = new double[1];
358 |             double[] U2 = new double[1];
359 |             double[] U3 = new double[1];
360 |             double[] R1 = new double[1];
361 |             double[] R2 = new double[1];
362 |             double[] R3 = new double[1];
363 | 
364 |             for (i = 0; i <= 6; i++)
365 |             {
366 |                 ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput();
367 |                 ret = mySapModel.Results.Setup.SetCaseSelectedForOutput(System.Convert.ToString(i + 1), System.Convert.ToBoolean(-1));
368 | 
369 |                 if (i <= 3)
370 |                 {
371 |                     ret = mySapModel.Results.JointDispl(PointName[1], eItemTypeElm.ObjectElm, ref NumberResults, ref Obj, ref Elm, ref LoadCase, ref StepType, ref StepNum, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3);
372 |                     U3.CopyTo(U3, 0);
373 |                     SapResult[i] = U3[0];
374 |                 }
375 |                 else
376 |                 {
377 |                     ret = mySapModel.Results.JointDispl(PointName[0], eItemTypeElm.ObjectElm, ref NumberResults, ref Obj, ref Elm, ref LoadCase, ref StepType, ref StepNum, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3);
378 |                     U1.CopyTo(U1, 0);
379 |                     SapResult[i] = U1[0];
380 |                 }
381 | 
382 |             }
383 | 
384 | 
385 | 
386 |             //close SAP2000
387 | 
388 |             mySapObject.ApplicationExit(false);
389 |             mySapModel = null;
390 |             mySapObject = null;
391 | 
392 | 
393 | 
394 |             //fill SAP2000 result strings
395 |             string[] SapResultString = new string[7];
396 |             for (i = 0; i <= 6; i++)
397 |             {
398 |                 SapResultString[i] = string.Format("{0:0.00000}", SapResult[i]);
399 |                 ret = (string.Compare(SapResultString[i], 1, "-", 1, 1, true));
400 |                 if (ret != 0)
401 |                 {
402 |                     SapResultString[i] = " " + SapResultString[i];
403 |                 }
404 | 
405 |             }
406 | 
407 | 
408 | 
409 |             //fill independent results
410 |             double[] IndResult = new double[7];
411 |             string[] IndResultString = new string[7];
412 |             IndResult[0] = -0.02639;
413 |             IndResult[1] = 0.06296;
414 |             IndResult[2] = 0.06296;
415 |             IndResult[3] = -0.2963;
416 |             IndResult[4] = 0.3125;
417 |             IndResult[5] = 0.11556;
418 |             IndResult[6] = 0.00651;
419 |             for (i = 0; i <= 6; i++)
420 |             {
421 | 
422 |                 IndResultString[i] = string.Format("{0:0.00000}", IndResult[i]);
423 |                 ret = (string.Compare(IndResultString[i], 1, "-", 1, 1, true));
424 |                 if (ret != 0)
425 |                 {
426 |                     IndResultString[i] = " " + IndResultString[i];
427 |                 }
428 | 
429 |             }
430 | 
431 | 
432 | 
433 |             //fill percent difference
434 |             double[] PercentDiff = new double[7];
435 |             string[] PercentDiffString = new string[7];
436 |             for (i = 0; i <= 6; i++)
437 |             {
438 |                 PercentDiff[i] = (SapResult[i] / IndResult[i]) - 1;
439 |                 PercentDiffString[i] = string.Format("{0:0%}", PercentDiff[i]);
440 |                 ret = (string.Compare(PercentDiffString[i], 1, "-", 1, 1, true));
441 |                 if (ret != 0)
442 |                 {
443 |                     PercentDiffString[i] = " " + PercentDiffString[i];
444 |                 }
445 | 
446 |             }
447 | 
448 | 
449 | 
450 |             //display message box comparing results
451 |             string msg = "";
452 |             msg = msg + "LC  Sap2000  Independent  %Diff\r\n";
453 |             for (i = 0; i <= 5; i++)
454 |             {
455 |                 msg = msg + string.Format("{0:0}", i + 1) + "    " + SapResultString[i] + "   " + IndResultString[i] + "       " + PercentDiffString[i] + "\r\n";
456 |             }
457 | 
458 | 
459 |             msg = msg + string.Format("{0:0}", i + 1) + "    " + SapResultString[i] + "   " + IndResultString[i] + "       " + PercentDiffString[i];
460 |             Console.WriteLine(msg);
461 |             Console.ReadKey();
462 |         }
463 |     }
464 | }
465 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapFrameDistLoad.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | using System.Collections.Generic;
 3 | using System.Linq;
 4 | using System.Text;
 5 | using System.Threading.Tasks;
 6 | 
 7 | namespace SAP.API.Initial
 8 | {
 9 |     class SapFrameDistLoad
10 |     {
11 |         #region Member Variables
12 | 
13 |         SapLoadPattern loadPattern;
14 |         int type;
15 |         int direction;
16 |         double distance1;
17 |         double distance2;
18 |         double value1;
19 |         double value2;
20 | 
21 | 
22 | 
23 |         #endregion
24 | 
25 |         #region Properties
26 |         internal SapLoadPattern LoadPattern { get => loadPattern; set => loadPattern = value; }
27 |         public int Type { get => type; set => type = value; }
28 |         public int Direction { get => direction; set => direction = value; }
29 |         public double Distance1 { get => distance1; set => distance1 = value; }
30 |         public double Distance2 { get => distance2; set => distance2 = value; }
31 |         public double Value1 { get => value1; set => value1 = value; }
32 |         public double Value2 { get => value2; set => value2 = value; }
33 | 
34 |         #endregion
35 | 
36 |         #region Constructors
37 |         public SapFrameDistLoad(SapLoadPattern _loadPattern,int _type,int _direction,double _distance1,double _distance2,double _value1,double _value2)
38 |         {
39 |             loadPattern = _loadPattern;
40 |             type = _type;
41 |             direction = _direction;
42 |             distance1 = _distance1;
43 |             distance2 = _distance2;
44 |             value1 = _value1;
45 |             value2 = _value2;
46 |         }
47 |         #endregion
48 | 
49 |         #region Methods
50 | 
51 | 
52 |         #endregion
53 | 
54 |         #region Static Methods
55 | 
56 | 
57 |         #endregion
58 |     }
59 | }
60 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapFrameElement.cs:
--------------------------------------------------------------------------------
  1 | using SAP2000v20;
  2 | using System;
  3 | using System.Collections.Generic;
  4 | using System.Linq;
  5 | using System.Text;
  6 | using System.Threading.Tasks;
  7 | 
  8 | namespace SAP.API.Initial
  9 | {
 10 |     class SapFrameElement
 11 |     {
 12 |         #region MembVariables
 13 |         SapPoint point1;
 14 |         SapPoint point2;
 15 |         SapRecangularSection rectsection;
 16 |         string label;
 17 |         string name;
 18 |         List distibutedLoads;
 19 |         List frameResults;
 20 |         cSapModel mymodel;
 21 |         #endregion
 22 |         #region Prop
 23 |         public SapPoint Point1 { get => point1; set => point1 = value; }
 24 |         public SapPoint Point2 { get => point2; set => point2 = value; }
 25 |         public string Label { get => label; set => label = value; }
 26 |         public string Name { get => name; set => name = value; }
 27 |         internal SapRecangularSection Rectsection { get => rectsection; set => rectsection = value; }
 28 |         
 29 |         public cSapModel Mymodel { get => mymodel; set => mymodel = value; }
 30 |         internal List DistibutedLoads { get => distibutedLoads; set => distibutedLoads = value; }
 31 |         internal List FrameResults { get => frameResults; set => frameResults = value; }
 32 |         #endregion
 33 |         #region Constructors
 34 |         public SapFrameElement(cSapModel mymodel ,SapPoint point1,SapPoint point2,SapRecangularSection rectsection,string label,string framename)
 35 |         {
 36 |             this.mymodel = mymodel;
 37 |             this.point1 = point1;
 38 |             this.point2 = point2;
 39 |             this.rectsection = rectsection;
 40 |             this.label = label;
 41 |             this.name = framename;
 42 |             this.distibutedLoads = new List();
 43 |             this.frameResults = new List();
 44 |             this.mymodel.FrameObj.AddByPoint(this.point1.Name, this.point2.Name,ref this.label, this.rectsection.Name, this.name);
 45 |         }
 46 |         public SapFrameElement(cSapModel mymodel, SapPoint point1, SapPoint point2, string label, string framename)
 47 |         {
 48 |             this.mymodel = mymodel;
 49 |             this.point1 = point1;
 50 |             this.point2 = point2;
 51 |             this.label = label;
 52 |             this.name = framename;
 53 |             this.distibutedLoads = new List();
 54 |             this.frameResults = new List();
 55 |             this.mymodel.FrameObj.AddByPoint(this.point1.Name, this.point2.Name, ref this.label, this.name);
 56 |         }
 57 |         public SapFrameElement(cSapModel mymodel,double x11,double y11,double z11,double x22,double y22,double z22,string framename,SapRecangularSection rectsection,string label)
 58 |         {
 59 |             this.mymodel = mymodel;
 60 |             point1.X = x11;
 61 |             point1.Y = y11;
 62 |             point1.Z = z11;
 63 |             point2.X = x22;
 64 |             point2.Y = y22;
 65 |             point2.Z = z22;
 66 |             this.rectsection = rectsection;
 67 |             this.label = label;
 68 |             this.name = framename;
 69 |             this.distibutedLoads = new List();
 70 |             this.frameResults = new List();
 71 |             this.mymodel.FrameObj.AddByCoord(x11, y11, z11, x22, y22, z22, ref this.label, this.rectsection.Name, this.name);
 72 |             string temp1="", temp2="";
 73 |             this.mymodel.FrameObj.GetPoints(this.name, ref temp1, ref temp2);
 74 |             point1.Name = temp1;
 75 |             point2.Name = temp2;
 76 |         }
 77 |         public SapFrameElement(cSapModel mymodel, double x11, double y11, double z11, double x22, double y22, double z22, string framename, string label)
 78 |         {
 79 |             this.mymodel = mymodel;
 80 |             point1 = new SapPoint(this.mymodel,x11,y11,z11);
 81 |             point2 = new SapPoint(this.mymodel,x22,y22,z22);
 82 |             this.label = label;
 83 |             this.name = framename;
 84 |             this.distibutedLoads = new List();
 85 |             this.frameResults = new List();
 86 |             this.mymodel.FrameObj.AddByCoord(x11, y11, z11, x22, y22, z22, ref this.label, this.name);
 87 |             string temp1 = "", temp2 = "";
 88 |             this.mymodel.FrameObj.GetPoints(this.name, ref temp1, ref temp2);
 89 |             point1.Name = temp1;
 90 |             point2.Name = temp2;
 91 |         }
 92 |         #endregion
 93 |         #region Methods
 94 |         public void AddDistributedLoad(SapFrameDistLoad distibutedload)
 95 |         {
 96 |             this.distibutedLoads.Add(distibutedload);
 97 |            int check= this.mymodel.FrameObj.SetLoadDistributed(this.label, distibutedload.LoadPattern.Name, distibutedload.Type, distibutedload.Direction, distibutedload.Distance1, distibutedload.Distance2, distibutedload.Value1, distibutedload.Value2,"Local",System.Convert.ToBoolean(-1),System.Convert.ToBoolean(-1),0);
 98 | 
 99 |         }
100 | 
101 |         #endregion
102 |     }
103 | }
104 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapFrameResult.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | using System.Collections.Generic;
 3 | using System.Linq;
 4 | using System.Text;
 5 | using System.Threading.Tasks;
 6 | using SAP2000v20;
 7 | 
 8 | namespace SAP.API.Initial
 9 | {
10 |     class SapFrameResult
11 |     {
12 | 
13 |         #region Member Variables
14 |         cSapModel sapModel;
15 |         string frameName;
16 |         int numberOfResults = 0;
17 |         string[] frameObjName = new string[0];
18 |         double[] frameObjStation = new double[0];
19 |         string[] frameElmName = new string[0];
20 |         double[] frameElmStation = new double[0];
21 |         string[] loadCase = new string[0];
22 |         string[] stepType = new string[0];
23 |         double[] stepNum = new double[0];
24 |         double[] p = new double[0];
25 |         double[] v2 = new double[0];
26 |         double[] v3 = new double[0];
27 |         double[] t = new double[0];
28 |         double[] m2 = new double[0];
29 |         double[] m3 = new double[0];
30 |         
31 |         #endregion
32 | 
33 |         #region Properties
34 |         public int NumberOfResults { get => numberOfResults; set => numberOfResults = value; }
35 |         public string[] FrameObjName { get => frameObjName; set => frameObjName = value; }
36 |         public string[] FrameElmName { get => frameElmName; set => frameElmName = value; }
37 |         public string[] LoadCase { get => loadCase; set => loadCase = value; }
38 |         public string[] StepType { get => stepType; set => stepType = value; }
39 |         public double[] StepNum { get => stepNum; set => stepNum = value; }
40 |         
41 |         public cSapModel SapModel { get => sapModel; set => sapModel = value; }
42 |         public string FrameName { get => frameName; set => frameName = value; }
43 |         public double[] P { get => p; set => p = value; }
44 |         public double[] V2 { get => v2; set => v2 = value; }
45 |         public double[] V3 { get => v3; set => v3 = value; }
46 |         public double[] T { get => t; set => t = value; }
47 |         public double[] M2 { get => m2; set => m2 = value; }
48 |         public double[] M3 { get => m3; set => m3 = value; }
49 |         #endregion
50 | 
51 |         #region Constructors
52 |         public SapFrameResult(cSapModel _sapModel, string _frameName)
53 |         {
54 |             sapModel = _sapModel;
55 |             frameName = _frameName;
56 |             int check = SapModel.Results.FrameForce(frameName, eItemTypeElm.ObjectElm, ref numberOfResults, ref frameObjName, ref frameObjStation, ref frameElmName, ref frameElmStation, ref loadCase, ref stepType, ref stepNum, ref p, ref v2, ref v3, ref t, ref m2, ref m3);
57 |         }
58 | 
59 | 
60 |         #endregion
61 | 
62 |         #region Methods
63 | 
64 | 
65 |         #endregion
66 | 
67 |         #region Static Methods
68 | 
69 | 
70 |         #endregion
71 |     }
72 | }
73 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapJointRestraint.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | using System.Collections.Generic;
 3 | using System.Linq;
 4 | using System.Text;
 5 | using System.Threading.Tasks;
 6 | using SAP.API.Initial;
 7 | namespace SAP.API.Initial
 8 | {
 9 |     public enum Restrains
10 |     {
11 |         Fixed,
12 |         Pinned,
13 |         Roller,
14 |         NoRestraint
15 |     }
16 |   public  class SapJointRestraint
17 |     {
18 |         private bool[] restrains;
19 | 
20 |         public bool[] Restrains
21 |         {
22 |             get { return restrains; }
23 |             set { restrains= value; }
24 |         }
25 | 
26 |         #region Constructions
27 | 
28 |         public SapJointRestraint(Restrains RestrainType)
29 |         {
30 |             restrains = new bool[6];
31 |             switch (RestrainType)
32 |             {
33 |                 case Initial.Restrains.Fixed:
34 |                     for (int i = 0; i <6; i++)
35 |                     {
36 |                         restrains[i] = true;
37 |                     }
38 |                     break;
39 | 
40 |                 case Initial.Restrains.Pinned:
41 |                     for (int i = 0; i < 3; i++)
42 |                     {
43 |                         restrains[i] = true;
44 |                     }
45 |                     break;
46 |                 case Initial.Restrains.Roller:
47 |                     //set constrains to Z-Axis
48 |                     restrains[2] = true;
49 |                     break;
50 |                 case Initial.Restrains.NoRestraint:
51 | 
52 |                     break;
53 |                 default:
54 |                     break;
55 |             }
56 |             
57 | 
58 |         }
59 |         public void SetRestraint(bool U1,bool U2,bool U3,bool R1,bool R2,bool R3)
60 |         {
61 |             restrains[0] = U1;
62 |             restrains[1] = U2;
63 |             restrains[2] = U3;
64 |             restrains[3] = R1;
65 |             restrains[4] = R2;
66 |             restrains[5] = R3;
67 |         }
68 |         #endregion
69 | 
70 | 
71 |        
72 |     }
73 | }
74 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapLoadPattern.cs:
--------------------------------------------------------------------------------
  1 | using System;
  2 | using System.Collections.Generic;
  3 | using System.Linq;
  4 | using System.Text;
  5 | using System.Threading.Tasks;
  6 | using SAP2000v20;
  7 | 
  8 | namespace SAP.API.Initial
  9 | {
 10 |     public enum LoadPatternType
 11 |     {
 12 |         Dead = 1,
 13 |         SuperDead = 2,
 14 |         Live = 3,
 15 |         ReduceLive = 4,
 16 |         Quake = 5,
 17 |         Wind = 6,
 18 |         Snow = 7,
 19 |         Other = 8,
 20 |         Move = 9,
 21 |         Temperature = 10,
 22 |         Rooflive = 11,
 23 |         Notional = 12,
 24 |         PatternLive = 13,
 25 |         Wave = 14,
 26 |         Braking = 15,
 27 |         Centrifugal = 16,
 28 |         Friction = 17,
 29 |         Ice = 18,
 30 |         WindOnLiveLoad = 19,
 31 |         HorizontalEarthPressure = 20,
 32 |         VerticalEarthPressure = 21,
 33 |         EarthSurcharge = 22,
 34 |         DownDrag = 23,
 35 |         VehicleCollision = 24,
 36 |         VesselCollision = 25,
 37 |         TemperatureGradient = 26,
 38 |         Settlement = 27,
 39 |         Shrinkage = 28,
 40 |         Creep = 29,
 41 |         WaterloadPressure = 30,
 42 |         LiveLoadSurcharge = 31,
 43 |         LockedInForces = 32,
 44 |         PedestrianLL = 33,
 45 |         Prestress = 34,
 46 |         Hyperstatic = 35,
 47 |         Bouyancy = 36,
 48 |         StreamFlow = 37,
 49 |         Impact = 38,
 50 |         Construction = 39,
 51 |         DeadWearing = 40,
 52 |         DeadWater = 41,
 53 |         DeadManufacture = 42,
 54 |         EarthHydrostatic = 43,
 55 |         PassiveEarthPressure = 44,
 56 |         ActiveEarthPressure = 45,
 57 |         PedestrianLLReduced = 46,
 58 |         SnowHighAltitude = 47,
 59 |         EuroLm1Char = 48,
 60 |         EuroLm1Freq = 49,
 61 |         EuroLm2 = 50,
 62 |         EuroLm3 = 51,
 63 |         EuroLm4 = 52,
 64 |         SeaState = 53,
 65 |         Permit = 54,
 66 |         MoveFatigue = 55,
 67 |         MoveFatiguePermit = 56,
 68 |         MoveDeflection = 57
 69 |     }
 70 |    public class SapLoadPattern
 71 |     {
 72 |         #region Member Variables
 73 | 
 74 |         string name;
 75 |         double selfWtMultiplier;
 76 |         bool addAnalysisCase;
 77 |         cSapModel sapModel;
 78 | 
 79 | 
 80 |         #endregion
 81 | 
 82 |         #region Properties
 83 |         public string Name { get => name; set => name = value; }
 84 |         public double SelfWtMultiplier { get => selfWtMultiplier; set => selfWtMultiplier = value; }
 85 |         public bool AddAnalysisCase { get => addAnalysisCase; set => addAnalysisCase = value; }
 86 | 
 87 |         #endregion
 88 | 
 89 |         #region Constructors
 90 |         public SapLoadPattern(cSapModel _sapModel,string _name, LoadPatternType _loadPatternType, double _selfWtMultiplier,bool _addAnalysisCase)
 91 |         {
 92 |             sapModel = _sapModel;
 93 |             selfWtMultiplier = _selfWtMultiplier;
 94 |             addAnalysisCase = _addAnalysisCase;
 95 |             name = _name;
 96 |             sapModel.LoadPatterns.Add(name, (eLoadPatternType)_loadPatternType, selfWtMultiplier, addAnalysisCase);
 97 |         }
 98 | 
 99 |         #endregion
100 | 
101 |         #region Methods
102 | 
103 | 
104 |         #endregion
105 | 
106 |         #region Static Methods
107 | 
108 | 
109 |         #endregion
110 |     }
111 | }
112 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapMaterial.cs:
--------------------------------------------------------------------------------
 1 | using SAP2000v20;
 2 | using System;
 3 | using System.Collections.Generic;
 4 | using System.Linq;
 5 | using System.Text;
 6 | using System.Threading.Tasks;
 7 | 
 8 | namespace SAP.API.Initial
 9 | {
10 |   public  enum MaterialType
11 |     {
12 |         STEEL = 1,
13 | 
14 |         CONCRETE = 2,
15 | 
16 |         NODESIGN = 3,
17 | 
18 |         ALUMINUM = 4,
19 | 
20 |         COLDFORMED = 5,
21 | 
22 |         REBAR = 6,
23 | 
24 |         TENDON = 7
25 | 
26 | 
27 |     }
28 |     enum SapColor
29 |     {
30 |         Default = -1,
31 |     }
32 |     class SapMaterial
33 |     {
34 |         #region Member Veriabels
35 | 
36 |            
37 |             private string name;
38 |             private  SapColor color;
39 | 
40 |         #endregion
41 | 
42 |         #region Properties
43 | 
44 | 
45 |         public string Name
46 |         {
47 |             get { return name; }
48 |             set { name = value; }
49 |         }
50 |         public SapColor Color { get => color; set => color = value; }
51 |         public cSapModel SapModel { get; set; }
52 | 
53 | 
54 |         #endregion
55 | 
56 |         #region Constructors
57 | 
58 | 
59 |         public SapMaterial(cSapModel sapModel, string name, MaterialType type, SapColor color = SapColor.Default)
60 |         {
61 |             this.SapModel = sapModel;
62 |             this.name = name;
63 |             SetMaterial(name, type, color);
64 |         }
65 |         
66 |         #endregion
67 | 
68 |         #region Methods
69 | 
70 |         public void SetMaterial(string name, MaterialType type, SapColor color = SapColor.Default)
71 |         {
72 |             SapModel.PropMaterial.SetMaterial(name, (eMatType)type, (int)color);
73 |         }
74 |         public void SetSteelMaterial(double Fy, double Fu, double EFy, double EFu)
75 |         {
76 | 
77 |             SapModel.PropMaterial.SetOSteel_1(name, Fy, Fu, EFy, EFu, 1, 2, 0.02, 0.1, 0.2, -0.1);
78 | 
79 | 
80 |         }
81 |         public void SetConcreteMaterial(double Fc, bool IsLightWeight = false, double FcsFactor = 0)
82 |         {
83 |             int check= SapModel.PropMaterial.SetOConcrete_1(name, Fc, IsLightWeight, FcsFactor, 1, 2, 0.0022, 0.0052, -0.1);
84 |         }
85 | 
86 |         public void SetIsotropic(double E, double U, double A)
87 |         {
88 |             int check = SapModel.PropMaterial.SetMPIsotropic(name, E, U, A);
89 |         }
90 |         public void SetWeight(double value )
91 |         {
92 |             int check = SapModel.PropMaterial.SetWeightAndMass(name, 1, value);
93 |         }
94 |         #endregion
95 |     }
96 | }
97 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapModel.cs:
--------------------------------------------------------------------------------
  1 | using System;
  2 | using System.Collections.Generic;
  3 | using System.Linq;
  4 | using System.Text;
  5 | using System.Threading.Tasks;
  6 | using SAP2000v20;
  7 | namespace SAP.API.Initial
  8 | {
  9 |     public enum SapUnits
 10 |     {
 11 |         lb_in_F = 1,
 12 |         lb_ft_F = 2,
 13 |         kip_in_F = 3,
 14 |         kip_ft_F = 4,
 15 |         kN_mm_C = 5,
 16 |         kN_m_C = 6,
 17 |         kgf_mm_C = 7,
 18 |         kgf_m_C = 8,
 19 |         N_mm_C = 9,
 20 |         N_m_C = 10,
 21 |         Ton_mm_C = 11,
 22 |         Ton_m_C = 12,
 23 |         kN_cm_C = 13,
 24 |         kgf_cm_C = 14,
 25 |         N_cm_C = 15,
 26 |         Ton_cm_C = 16
 27 |     }
 28 |     class SapModel
 29 |     {
 30 |         public bool AttachToInstance { get; set; }
 31 | 
 32 |         public bool SpecifyPath { get; set; }
 33 |         public string ModelDirectory { get; set; }
 34 |         public string ModelName { get; set; }
 35 |         public string ModelPath { get; set; }
 36 |         public cSapModel SapObjectModel { get; set; }
 37 |         private cOAPI sapObjectAPI;
 38 | 
 39 |         #region Constructors
 40 |         public SapModel(string ModelDirectory, bool visible = false,string ModelName = "Untitled-API")
 41 |         {
 42 |             this.ModelDirectory = ModelDirectory;
 43 |             this.ModelName = ModelName;
 44 | 
 45 |             //set the following flag to true to attach to an existing instance of the program
 46 |             //otherwise a new instance of the program will be started
 47 | 
 48 |             AttachToInstance = false;
 49 | 
 50 |             //set the following flag to true to manually specify the path to SAP2000.exe
 51 | 
 52 |             //this allows for a connection to a version of SAP2000 other than the latest installation
 53 | 
 54 |             //otherwise the latest installed version of SAP2000 will be launched
 55 | 
 56 |             SpecifyPath = false;
 57 | 
 58 |             //if the above flag is set to true, specify the path to SAP2000 below
 59 | 
 60 |             string ProgramPath;
 61 | 
 62 |             ProgramPath = "C:\\Program Files (x86)\\Computers and Structures\\SAP2000 20\\SAP2000.exe";
 63 | 
 64 |             //full path to the model
 65 | 
 66 |             //set it to the desired path of your model
 67 | 
 68 |             try
 69 | 
 70 |             {
 71 | 
 72 |                 System.IO.Directory.CreateDirectory(ModelDirectory);
 73 | 
 74 |             }
 75 | 
 76 |             catch (Exception ex)
 77 | 
 78 |             {
 79 | 
 80 |                 Console.WriteLine("Could not create directory: " + ModelDirectory);
 81 | 
 82 |             }
 83 | 
 84 | 
 85 | 
 86 |              ModelPath = ModelDirectory + System.IO.Path.DirectorySeparatorChar + ModelName;
 87 | 
 88 | 
 89 | 
 90 |             //dimension the SapObject as cOAPI type
 91 | 
 92 |              sapObjectAPI = null;
 93 | 
 94 | 
 95 | 
 96 |             //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero)
 97 | 
 98 |             int ret = 0;
 99 | 
100 | 
101 | 
102 |             if (AttachToInstance)
103 | 
104 |             {
105 |                 //attach to a running instance of SAP2000
106 |                 try
107 | 
108 |                 {
109 |                     //get the active SapObject
110 |                     sapObjectAPI = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject");
111 |                 }
112 | 
113 |                 catch (Exception ex)
114 | 
115 |                 {
116 |                     Console.WriteLine("No running instance of the program found or failed to attach.");
117 |                     return;
118 |                 }
119 |             }
120 | 
121 |             else
122 | 
123 |             {
124 |                 //create API helper object
125 |                 cHelper myHelper;
126 |                 try
127 | 
128 |                 {
129 |                     myHelper = new Helper();
130 |                 }
131 | 
132 |                 catch (Exception ex)
133 | 
134 |                 {
135 | 
136 |                     Console.WriteLine("Cannot create an instance of the Helper object");
137 | 
138 |                     return;
139 | 
140 |                 }
141 | 
142 | 
143 | 
144 |                 if (SpecifyPath)
145 | 
146 |                 {
147 |                     //'create an instance of the SapObject from the specified path
148 |                     try
149 | 
150 |                     {
151 |                         //create SapObject
152 | 
153 |                         sapObjectAPI = myHelper.CreateObject(ProgramPath);
154 |                     }
155 | 
156 |                     catch (Exception ex)
157 | 
158 |                     {
159 |                         Console.WriteLine("Cannot start a new instance of the program from " + ProgramPath);
160 |                         return;
161 |                     }
162 | 
163 |                 }
164 | 
165 |                 else
166 | 
167 |                 {
168 | 
169 |                     //'create an instance of the SapObject from the latest installed SAP2000
170 | 
171 |                     try
172 | 
173 |                     {
174 |                         //create SapObject
175 | 
176 |                         sapObjectAPI = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject");
177 | 
178 |                     }
179 | 
180 |                     catch (Exception ex)
181 | 
182 |                     {
183 |                         Console.WriteLine("Cannot start a new instance of the program.");
184 | 
185 |                         return;
186 |                     }
187 |                 }
188 |                 //start SAP2000 application
189 |                 
190 |                 ret = sapObjectAPI.ApplicationStart((eUnits)SapUnits.N_m_C,visible,"FileName");
191 |                // mySapObject.Hide();
192 |             }
193 | 
194 |             //create SapModel object
195 |             SapObjectModel = sapObjectAPI.SapModel;
196 |         }
197 | 
198 | 
199 |         #endregion
200 |         #region Methods
201 |         
202 |         public int Initialize(SapUnits sapUnits=SapUnits.N_m_C)
203 |         {   
204 |             //initialize model
205 |             SapObjectModel.InitializeNewModel((eUnits)sapUnits);
206 |             //create new blank model
207 |            return  SapObjectModel.File.NewBlank();
208 |             
209 |         }
210 |         public int RefreshView(int window=0,bool zoom=false)
211 |         {
212 |             return SapObjectModel.View.RefreshView(window, zoom);
213 |         }
214 | 
215 |         public void RunAnalysis()
216 |         {
217 |             SapObjectModel.File.Save(ModelPath);
218 |             SapObjectModel.Analyze.RunAnalysis();
219 |         }
220 | 
221 |         public void Close(bool FileSave=true)
222 |         {
223 |             if (FileSave)
224 |             {
225 |                 SapObjectModel.File.Save(ModelPath);
226 |             }
227 |             
228 |             sapObjectAPI.ApplicationExit(FileSave);
229 |             SapObjectModel = null;
230 |             sapObjectAPI = null;
231 |         }
232 |         #endregion
233 |     }
234 | }
235 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapPoint.cs:
--------------------------------------------------------------------------------
  1 | using System;
  2 | using System.Collections.Generic;
  3 | using System.Linq;
  4 | using System.Text;
  5 | using System.Threading.Tasks;
  6 | using SAP2000v20;
  7 | 
  8 | namespace SAP.API.Initial
  9 | {
 10 |    public class SapPoint
 11 |     {
 12 | 
 13 |         #region Member Variables
 14 | 
 15 |         
 16 |         private string name;
 17 |         private double x;
 18 |         private double y;
 19 |         private double z;
 20 | 
 21 |         SapJointRestraint jointRestraint;
 22 |         public SapJointRestraint JointRestraint
 23 |         {
 24 |             get { return jointRestraint; }
 25 |             set { jointRestraint = value;UpdateRestrains(); }
 26 |         }
 27 | 
 28 |         List pointloads;
 29 |         List pointResults;
 30 |         #endregion
 31 | 
 32 |         #region Properties
 33 |         public cSapModel SapModel { get; set; }
 34 |         public double X
 35 |         {
 36 |             get { return x; }
 37 |             set { x = value; }
 38 |         }
 39 |         public double Y
 40 |         {
 41 |             get { return y; }
 42 |             set { y = value; }
 43 |         }
 44 |         public double Z
 45 |         {
 46 |             get { return z; }
 47 |             set { z = value; }
 48 |         }
 49 | 
 50 |         public string Name
 51 |         {
 52 |             get { return name; }
 53 |             set {
 54 |                 // changeing the name of point
 55 |                 SapModel.PointObj.ChangeName(name, value);
 56 |                 name = value;
 57 |             }
 58 |         }
 59 | 
 60 |         public List Pointloads { get => pointloads; set => pointloads = value; }
 61 |         internal List PointResults { get => pointResults; set => pointResults = value; }
 62 |         #endregion
 63 | 
 64 |         #region Constructors
 65 |         public SapPoint(cSapModel model,double x,double y,double z)
 66 |         {
 67 |             this.SapModel = model;
 68 |             this.x = x;
 69 |             this.y = y;
 70 |             this.z = z;
 71 |             model.PointObj.AddCartesian(x, y, z, ref name);
 72 |             //Iniitialize the point with no restraints;
 73 |             jointRestraint = new SapJointRestraint(Restrains.NoRestraint);
 74 |             pointloads = new List();
 75 |             pointResults = new List();
 76 |         }
 77 | 
 78 |         public SapPoint(cSapModel model):this(model,0,0,0)
 79 |         {
 80 |         }
 81 |         #endregion
 82 | 
 83 | 
 84 |         #region Methods
 85 | 
 86 |         public void SetRestraint(Restrains restrains)
 87 |         {
 88 |             jointRestraint = new SapJointRestraint(restrains);
 89 |             bool[] tempRestrains = jointRestraint.Restrains;
 90 |            int r= SapModel.PointObj.SetRestraint(name, ref tempRestrains,0);
 91 |             
 92 |         }
 93 |         public void SetRestraint(bool U1, bool U2, bool U3, bool R1, bool R2, bool R3)
 94 |         {
 95 |             jointRestraint.SetRestraint(U1, U2, U3, R1, R2, R3);
 96 |             bool[] tempRestrains = jointRestraint.Restrains;
 97 |             SapModel.PointObj.SetRestraint(name, ref tempRestrains,0);
 98 |             
 99 |         }
100 |         public void DeleteRestraint()
101 |         {
102 |             SapModel.PointObj.DeleteRestraint(name);
103 |         }
104 |         public void AddPointLoad(SapPointLoad pointload)
105 |         {
106 |             double[] temp = new double[6];
107 |             temp = pointload.Values;
108 |             this.SapModel.PointObj.SetLoadForce(this.name, pointload.LoadPattern.Name, ref temp, true, "Global", 0);
109 |             pointload.Values = temp;
110 |             pointloads.Add(pointload);
111 |         }
112 | 
113 |         #endregion
114 | 
115 |         #region private Method
116 |         private void UpdateRestrains()
117 |         {
118 |             bool[] tempRestrains = jointRestraint.Restrains;
119 |             SapModel.PointObj.SetRestraint(name, ref tempRestrains);
120 | 
121 |         }
122 |         #endregion
123 | 
124 | 
125 |         #region Static Methods
126 |         public static long Count(cSapModel SapModel)
127 |         {
128 |              return SapModel.PointObj.Count();
129 |         }
130 | 
131 |         public static string[] GetNameList(cSapModel sapModel)
132 |         {
133 |             int NumberNames=0;
134 |             //get the count of the point to initialise the array size first
135 |             long PointCount=Count(sapModel);
136 |             string[] PointNames=new string[PointCount];
137 | 
138 |             sapModel.PointObj.GetNameList(ref NumberNames, ref PointNames);
139 |             return PointNames;
140 | 
141 |         }
142 |        
143 |         #endregion
144 | 
145 | 
146 |     }
147 | }
148 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapPointLoad.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | using System.Collections.Generic;
 3 | using System.Linq;
 4 | using System.Text;
 5 | using System.Threading.Tasks;
 6 | using SAP2000v20;
 7 | 
 8 | namespace SAP.API.Initial
 9 | {
10 |    public class SapPointLoad
11 |     {
12 |         #region Member Variables
13 | 
14 |         SapLoadPattern loadPattern;
15 |         double[] values ;
16 |         #endregion
17 | 
18 |         #region Properties
19 |         public double[] Values { get => values; set => values = value; }
20 |         internal SapLoadPattern LoadPattern { get => loadPattern; set => loadPattern = value; }
21 |         #endregion
22 | 
23 |         #region Constructors
24 |         public SapPointLoad(SapLoadPattern _loadPattern, double[] _sixLoadValues, bool replace)
25 |         {
26 |             loadPattern = _loadPattern;
27 |             try
28 |             {
29 |                 if (_sixLoadValues.Length==6 && replace)
30 |                 {
31 |                     values = _sixLoadValues;
32 |                 }
33 |                 else if (_sixLoadValues.Length == 6 && !replace)
34 |                 {
35 |                     for (int i = 0; i < 6; i++)
36 |                     {
37 |                         values[i] += _sixLoadValues[i];
38 |                     }
39 |                 }
40 |                 
41 |             }
42 |             catch (Exception)
43 |             {
44 | 
45 |                 throw;
46 |             }
47 |             
48 |           
49 |         }
50 | 
51 |         #endregion
52 | 
53 | 
54 |         #region Methods
55 | 
56 | 
57 |         #endregion
58 | 
59 |         #region Static Methods
60 | 
61 | 
62 |         #endregion
63 |     }
64 | }
65 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapPointResult.cs:
--------------------------------------------------------------------------------
 1 | using System;
 2 | using System.Collections.Generic;
 3 | using System.Linq;
 4 | using System.Text;
 5 | using System.Threading.Tasks;
 6 | using SAP2000v20;
 7 | 
 8 | namespace SAP.API.Initial
 9 | {
10 |     class SapPointResult
11 |     {
12 | 
13 |         #region Member Variables
14 |         cSapModel sapModel;
15 |         string pointName;
16 |         int numberOfResults = 0;
17 |         string[] pointObjName = new string[0];
18 |         string[] pointElmName = new string[0];
19 |         string[] loadCase = new string[0];
20 |         string[] stepType = new string[0];
21 |         double[] stepNum = new double[0];
22 |         double[] u1 = new double[0];
23 |         double[] u2 = new double[0];
24 |         double[] u3 = new double[0];
25 |         double[] r1 = new double[0];
26 |         double[] r2 = new double[0];
27 |         double[] r3 = new double[0];
28 |         double[] f1 = new double[0];
29 |         double[] f2 = new double[0];
30 |         double[] f3 = new double[0];
31 |         double[] m1 = new double[0];
32 |         double[] m2 = new double[0];
33 |         double[] m3 = new double[0];
34 |         #endregion
35 | 
36 |         #region Properties
37 |         public int NumberOfResults { get => numberOfResults; set => numberOfResults = value; }
38 |         public string[] PointObjName { get => pointObjName; set => pointObjName = value; }
39 |         public string[] PointElmName { get => pointElmName; set => pointElmName = value; }
40 |         public string[] LoadCase { get => loadCase; set => loadCase = value; }
41 |         public string[] StepType { get => stepType; set => stepType = value; }
42 |         public double[] StepNum { get => stepNum; set => stepNum = value; }
43 |         public double[] U1 { get => u1; set => u1 = value; }
44 |         public double[] U2 { get => u2; set => u2 = value; }
45 |         public double[] U3 { get => u3; set => u3 = value; }
46 |         public double[] R1 { get => r1; set => r1 = value; }
47 |         public double[] R2 { get => r2; set => r2 = value; }
48 |         public double[] R3 { get => r3; set => r3 = value; }
49 |         public double[] F1 { get => f1; set => f1 = value; }
50 |         public double[] F2 { get => f2; set => f2 = value; }
51 |         public double[] F3 { get => f3; set => f3 = value; }
52 |         public double[] M1 { get => m1; set => m1 = value; }
53 |         public double[] M2 { get => m2; set => m2 = value; }
54 |         public double[] M3 { get => m3; set => m3 = value; }
55 |         public cSapModel SapModel { get => sapModel; set => sapModel = value; }
56 |         public string PointName { get => pointName; set => pointName = value; }
57 |         #endregion
58 | 
59 |         #region Constructors
60 |         public SapPointResult(cSapModel _sapModel, string _pointName)
61 |         {
62 |             sapModel = _sapModel;
63 |             pointName = _pointName;
64 |             sapModel.Results.JointDispl(pointName, eItemTypeElm.ObjectElm, ref numberOfResults, ref pointObjName, ref pointElmName, ref loadCase, ref stepType, ref stepNum, ref u1, ref u2, ref u3, ref r1, ref r2, ref r3);
65 |             sapModel.Results.JointReact(pointName, eItemTypeElm.ObjectElm, ref numberOfResults, ref pointObjName, ref pointElmName, ref loadCase, ref stepType, ref stepNum, ref f1, ref f2, ref f3, ref m1, ref m2, ref m3);
66 |            
67 |         }
68 | 
69 | 
70 |         #endregion
71 | 
72 |         #region Methods
73 | 
74 | 
75 |         #endregion
76 | 
77 |         #region Static Methods
78 | 
79 | 
80 |         #endregion
81 |     }
82 | }
83 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/SapRecangularSection.cs:
--------------------------------------------------------------------------------
 1 | using SAP2000v20;
 2 | using System;
 3 | using System.Collections.Generic;
 4 | using System.Linq;
 5 | using System.Text;
 6 | using System.Threading.Tasks;
 7 | 
 8 | namespace SAP.API.Initial
 9 | {
10 |     
11 |     class SapRecangularSection
12 |     {
13 |         #region MembVariables
14 |         string name;
15 |         SapMaterial material;
16 |         double t2;
17 |         double t3;
18 |         string note;
19 |         string guid;
20 |         double[] modifiers;
21 |         int color;
22 |         cSapModel mysapmodel;
23 |         #endregion
24 |         #region Prop
25 |         public string Name { get => name; set => name = value; }
26 |         internal SapMaterial Material { get => material; set => material = value; }
27 |         public double T2 { get => t2; set => t2 = value; }
28 |         public double T3 { get => t3; set => t3 = value; }
29 |         public string Note { get => note; set => note = value; }
30 |         public string Guid { get => guid; set => guid = value; }
31 |         public double[] Modifiers { get => modifiers; set => modifiers = value; }
32 |         public int Color { get => color; set => color = value; }
33 |         public cSapModel Mysapmodel { get => mysapmodel; set => mysapmodel = value; }
34 |         #endregion
35 |         #region constructor
36 |         public SapRecangularSection(cSapModel my_model,SapMaterial material,string name,double t2,double t3,string note,string guid, int color, double[] modifiers)
37 |         {
38 |             this.mysapmodel = my_model;
39 |             this.material = material;
40 |             this.name = name;
41 |             this.t2 = t2;
42 |             this.t3 = t3;
43 |             this.note = note;
44 |             this.guid = guid;
45 |             this.color = color;
46 |             mysapmodel.PropFrame.SetRectangle(this.name, this.material.Name, this.t3, this.t2, this.color, this.note, this.guid);
47 |             this.modifiers = new double[0];
48 |             this.modifiers = modifiers;
49 |             mysapmodel.PropFrame.SetModifiers(this.name, ref this.modifiers);
50 |         }
51 |         public SapRecangularSection(cSapModel my_model, SapMaterial material, string name, double t2, double t3, string note, string guid, int color)
52 |         {
53 |             this.mysapmodel = my_model;
54 |             this.material = material;
55 |             this.name = name;
56 |             this.t2 = t2;
57 |             this.t3 = t3;
58 |             this.note = note;
59 |             this.guid = guid;
60 |             this.color = color;
61 |             this.modifiers = new double[0];
62 |             int check = mysapmodel.PropFrame.SetRectangle(this.name, this.material.Name, this.t3, this.t2, this.color, this.note, this.guid);
63 |         }
64 |         #endregion
65 |         #region Methods
66 |         public void SetModifiers(double[] Modifiers)
67 |         {
68 |             this.modifiers = Modifiers;
69 |             mysapmodel.PropFrame.SetModifiers(name,ref modifiers);
70 |         }
71 |         #endregion
72 | 
73 | 
74 |     }
75 | }
76 | 
--------------------------------------------------------------------------------
/SAP.API.Initial/packages.config:
--------------------------------------------------------------------------------
1 | 
2 | 
3 |   
4 | 
--------------------------------------------------------------------------------
/SAP.API.sln:
--------------------------------------------------------------------------------
 1 | 
 2 | Microsoft Visual Studio Solution File, Format Version 12.00
 3 | # Visual Studio 15
 4 | VisualStudioVersion = 15.0.26228.4
 5 | MinimumVisualStudioVersion = 10.0.40219.1
 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SAP.API.Initial", "SAP.API.Initial\SAP.API.Initial.csproj", "{8D9D80D8-C20C-4236-AB5A-E99AD2AF8C98}"
 7 | EndProject
 8 | Global
 9 | 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | 		Debug|Any CPU = Debug|Any CPU
11 | 		Release|Any CPU = Release|Any CPU
12 | 	EndGlobalSection
13 | 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | 		{8D9D80D8-C20C-4236-AB5A-E99AD2AF8C98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | 		{8D9D80D8-C20C-4236-AB5A-E99AD2AF8C98}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | 		{8D9D80D8-C20C-4236-AB5A-E99AD2AF8C98}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | 		{8D9D80D8-C20C-4236-AB5A-E99AD2AF8C98}.Release|Any CPU.Build.0 = Release|Any CPU
18 | 	EndGlobalSection
19 | 	GlobalSection(SolutionProperties) = preSolution
20 | 		HideSolutionNode = FALSE
21 | 	EndGlobalSection
22 | EndGlobal
23 | 
--------------------------------------------------------------------------------