0% found this document useful (0 votes)
19 views

CreateBridgeModel1 - Copy

The document is a C# code snippet for a Windows Forms application that interfaces with the CSiBridge API to create and manipulate a bridge model. It includes functionalities to initialize a new model, modify bridge components such as bents and deck sections, run analysis, and retrieve results. The code demonstrates the process of setting up a bridge model, updating its parameters, and displaying results in a message box before closing the application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

CreateBridgeModel1 - Copy

The document is a C# code snippet for a Windows Forms application that interfaces with the CSiBridge API to create and manipulate a bridge model. It includes functionalities to initialize a new model, modify bridge components such as bents and deck sections, run analysis, and retrieve results. The code demonstrates the process of setting up a bridge model, updating its parameters, and displaying results in a message box before closing the application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

using CSiBridge1;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BridgeModelerCSharpExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{

bool AttachToInstance;
AttachToInstance = false;

bool SpecifyPath;
SpecifyPath = false;

string ProgramPath;

string ModelDirectory = @"C:\CSiAPIexample";


try
{
System.IO.Directory.CreateDirectory(ModelDirectory);
}
catch (Exception ex)
{
Console.WriteLine("Could not create directory: " + ModelDirectory);
}

string ModelName = "SimpleBridgeModelerExample1.bdb";


string ModelPath = ModelDirectory +
System.IO.Path.DirectorySeparatorChar + ModelName;

cOAPI mySAPObject = null;


int ret = -1;

//create API helper object


cHelper myHelper;
try
{
myHelper = new Helper();
}
catch (Exception ex)
{
MessageBox.Show("Cannot create an instance of the Helper object");
return;
}

if (AttachToInstance)
{
try
{
mySAPObject =
myHelper.GetObject("CSI.CSiBridge.API.SapObject");
}
catch (Exception ex)
{
MessageBox.Show("No running instance of the program found or
failed to attach.");
return;
}
}
else
{
if (SpecifyPath)
{
try
{
mySAPObject = myHelper.CreateObject(ProgramPath);
}
catch (Exception ex)
{
MessageBox.Show("Cannot start a new instance of the program
from " + ProgramPath);
return;
}
}
else
{
try
{
mySAPObject =
myHelper.CreateObjectProgID("CSI.CSiBridge.API.SapObject");
}
catch (Exception ex)
{
MessageBox.Show("Cannot start a new instance of the
program.");
return;
}
}

ret = mySAPObject.ApplicationStart();
}

cSapModel mySapModel = mySAPObject.SapModel;

ret = mySapModel.InitializeNewModel(eUnits.kip_in_F);

cBridgeModeler_1 MyBridgeModeler = mySapModel.BridgeModeler_1;

double StartStation = 0;
string InitialBearing = "Default";
double Grade = 0;
string Skew = "Default";
double Radius = 3000;
double SuperElevation = 0;
double[] SpanLength = new double[] { 600, 750, 750, 600 }; // four
spans, length of each span in inches
int SectionType = 3;
ret = MyBridgeModeler.NewBridgeModel(StartStation, InitialBearing,
Grade, Skew, Radius, SuperElevation, ref SpanLength, SectionType);

int NumberNamesBent = -1;


string[] MyNameBent = null;
ret = MyBridgeModeler.Bent.GetNameList(ref NumberNamesBent, ref
MyNameBent);

//create copy of bent


string NewBent = "";
ret = MyBridgeModeler.Bent.AddCopy(ref NewBent, MyNameBent[0]);

//add column to new bent


string CapBeamSection = "";
double CapBeamLength = -1;
int SupportType = -1;
int NumberColumns = -1;
string FoundationGeneral = "";
int BentType = -1;
ret = MyBridgeModeler.Bent.GetGeneralData(NewBent, ref CapBeamSection,
ref CapBeamLength, ref SupportType, ref NumberColumns, ref FoundationGeneral, ref
BentType);

int NewNumberColumns = NumberColumns + 1;

ret = MyBridgeModeler.Bent.SetGeneralData(NewBent, CapBeamSection,


CapBeamLength, SupportType, NewNumberColumns, FoundationGeneral, BentType);

string[] Section = null;


double[] Distance = null;
double[] Height = null;
double[] Angle = null;
string[] FoundationCol = null;
ret = MyBridgeModeler.Bent.GetColumnData(NewBent, ref Section, ref
Distance, ref Height, ref Angle, ref FoundationCol);

double[] NewDistance = new double[] { 99, 198, 297 };


ret = MyBridgeModeler.Bent.SetColumnData(NewBent, ref Section, ref
NewDistance, ref Height, ref Angle, ref FoundationCol);

//
// Modify bridge object to use new bent
//
int NumberNamesBridgeObj = -1;
string[] MyNameBridgeObj = null;
ret = MyBridgeModeler.BridgeObject.GetNameList(ref
NumberNamesBridgeObj, ref MyNameBridgeObj);

string myBridgeObjName = MyNameBridgeObj[0];

double StartStationLayout = -99;


string[] SpanName = null;
double[] EndStation = null;
double[] SpanLengthLayout = null;
ret = MyBridgeModeler.BridgeObject.GetSpanLayout(myBridgeObjName, ref
StartStationLayout, ref SpanName, ref EndStation, ref SpanLengthLayout);

string mySpanName = SpanName[1];

ret =
MyBridgeModeler.BridgeObject.BentAssign.SetBentAssignment(myBridgeObjName,
mySpanName, NewBent, "Default");

//
// Modify deck section
//
int NumberNamesDeckSect = -1;
string[] MyNameDeckSect = null;
int[] BridgeSectionType = null;
ret = MyBridgeModeler.DeckSection.GetNameList(ref NumberNamesDeckSect,
ref MyNameDeckSect, ref BridgeSectionType);

string myDeckSectionName = MyNameDeckSect[0];


string SlabMaterial = string.Empty;
int NumberInteriorGirders = 0;
double TotalWidthOfDeckSection = 0;
int GirderLongitudinalLayout = 0;
ret =
MyBridgeModeler.DeckSection.PrecastConcreteIGirder.GetGeneralData(myDeckSectionName
, ref SlabMaterial, ref NumberInteriorGirders, ref TotalWidthOfDeckSection, ref
GirderLongitudinalLayout);

int NewNumberInteriorGirders = NumberInteriorGirders + 1;


double NewTotalWidthOfDeckSection = 600;
ret =
MyBridgeModeler.DeckSection.PrecastConcreteIGirder.SetGeneralData(myDeckSectionName
, SlabMaterial, NewNumberInteriorGirders, NewTotalWidthOfDeckSection,
GirderLongitudinalLayout);

bool ConstantSpacing = default;


double[] Spacing = null;
ret =
MyBridgeModeler.DeckSection.PrecastConcreteIGirder.GetGirderSpacingData(myDeckSecti
onName, ref ConstantSpacing, ref Spacing);

bool NewConstantSpacing = false;


double[] NewSpacing = (double[])Spacing.Clone();
NewSpacing[0] = 96;
NewSpacing[1] = 120;
NewSpacing[2] = 120;
ret =
MyBridgeModeler.DeckSection.PrecastConcreteIGirder.SetGirderSpacingData(myDeckSecti
onName, NewConstantSpacing, ref NewSpacing);

//modify overhang
double OverhangLength = -1;
double DistanceToFillet = -1;
double OuterThickness = -1;
ret =
MyBridgeModeler.DeckSection.PrecastConcreteIGirder.GetRightOverhangDimensions(myDec
kSectionName, ref OverhangLength, ref DistanceToFillet, ref OuterThickness);
double NewOverhangLength = OverhangLength + 24;
double NewDistanceToFillet = DistanceToFillet + 12;
ret =
MyBridgeModeler.DeckSection.PrecastConcreteIGirder.SetRightOverhangDimensions(myDec
kSectionName, NewOverhangLength, NewDistanceToFillet, OuterThickness);

//
// Update bridge
//
int Action = 4; // Clear and Create Linked Model
ret =
MyBridgeModeler.BridgeObject.UpdateWithSameParameters(myBridgeObjName, Action);

//save model
ret = mySapModel.File.Save(ModelPath);

//run model (this will create the analysis model)


ret = mySapModel.Analyze.RunAnalysis();

ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput();
ret = mySapModel.Results.Setup.SetCaseSelectedForOutput("DEAD");

int NumberResults = -1;


string[] LoadCase = null;
string[] StepType = null;
double[] StepNum = null;
double[] Fx = null;
double[] Fy = null;
double[] Fz = null;
double[] Mx = null;
double[] My = null;
double[] Mz = null;
double gx = -1;
double gy = -1;
double gz = -1;
ret = mySapModel.Results.BaseReact(ref NumberResults, ref LoadCase, ref
StepType, ref StepNum, ref Fx, ref Fy, ref Fz, ref Mx, ref My, ref Mz, ref gx, ref
gy, ref gz);

double handCalcFz = 2625.385;

MessageBox.Show("Base Reaction Fz (DEAD Load Case) - CSiBridge Result:


" + String.Format("{0:0.000}", Fz[0]) + " Independent: " +
String.Format("{0:0.000}", handCalcFz));

//close program
mySAPObject.ApplicationExit(false);

//clean up variables
mySapModel = null;
mySAPObject = null;

}
}
}

You might also like