public void CloseModel(bool fileSave = true) { if (fileSave) { MySapObjectModel.File.Save(ModelPath); } MySapObjectAPI.ApplicationExit(fileSave); MySapObjectModel = null; MySapObjectAPI = null; }
public void Close(bool FileSave = true) { if (FileSave) { SapObjectModel.File.Save(ModelPath); } sapObjectAPI.ApplicationExit(FileSave); SapObjectModel = null; sapObjectAPI = null; }
public static bool CloseApplication() { int flag = mySapObject.ApplicationExit(true); mySapModel = null; mySapObject = null; if (flag != 0) { return(false); } return(true); }
public int etabsAttach() { try { myETABSObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.ETABS.API.ETABSObject"); } catch { ErrorForm errorForm = new ErrorForm("ERROR", "Failed to attach , Run Etabs As Administrator and try again! ", false); errorForm.ShowDialog(); return(0); } return(1); }
public static bool StartApplication(bool attachToInstance, bool isVisible, eUnits units = eUnits.Ton_m_C) { if (attachToInstance == false) { try { cHelper myHelper = new Helper(); mySapObject = myHelper.CreateObject(ProgramPath); } catch (Exception ex) { throw ex; } } else { try { mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject"); } catch { try { if (mySapObject == null) { cHelper myHelper = new Helper(); mySapObject = myHelper.CreateObject(ProgramPath); } } catch (Exception ex) { throw ex; } } } if (isVisible == true) { mySapObject.Visible(); } else { mySapObject.Hide(); } mySapObject.ApplicationStart(units); mySapModel = mySapObject.SapModel; return(true); }
public static void InitializeSapModel(ref cSapModel mySAPObject, ref cSapModel mySapModel, string units) { //dimension the SapObject as cOAPI type cOAPI mySapObject = null; //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero) var ret = 0; //create API helper object cHelper myHelper; try { myHelper = new Helper(); } catch (Exception ex) { //Console.WriteLine("Cannot create an instance of the Helper object"); return; } try { //create SapObject mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject"); } catch (Exception ex) { //Console.WriteLine("Cannot start a new instance of the program."); return; } //start SAP2000 application ret = mySapObject.ApplicationStart(); //create SapModel object mySapModel = mySapObject.SapModel; //initialize model ret = mySapModel.InitializeNewModel(eUnits.kN_m_C); //create new blank model ret = mySapModel.File.NewBlank(); //define material property //ret = mySapModel.PropMaterial.SetMaterial("CONC", eMatType.Concrete, -1, "", ""); }
private void CrearModeloSap() { int ret = 0; //PARTE INICIAL-------------------------------------------------------------------------------- cHelper myHelper = new Helper(); cOAPI ETABSObject = myHelper.CreateObject(_rutaETABS); //Abrir el programa ETABS ret = ETABSObject.ApplicationStart(); if (ret != 0) { MessageBox.Show("No se pudo Abrir la aplicacion ETABS. ¿Desea especificar ahora la direccion del programa?", "Error de inicializacion", MessageBoxButtons.YesNo); return; } //Obtener una referencia al modelo cSapModel para acceder a todas las clases y funciones del OAPI _modeloSap = ETABSObject.SapModel; }
static SAP2000API() { mySapObject = null; mySapModel = null; ProgramPath = SAP2000Resources.ProgramPath; ModelDirectory = SAP2000Resources.ModelDirectory; if (!System.IO.Directory.Exists(ModelDirectory)) { try { System.IO.Directory.CreateDirectory(ModelDirectory); } catch (Exception ex) { throw ex; } } }
public static void OpenSAPModel(string filePath, ref cSapModel mySapModel, ref string units) { int ret = 0; //Create SAP2000 Object cOAPI mySapObject = null; cHelper myHelper = new Helper(); mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject"); //Start Application mySapObject.ApplicationStart(); //Create SapModel object mySapModel = mySapObject.SapModel; ret = mySapModel.InitializeNewModel(); ret = mySapModel.File.OpenFile(filePath); units = mySapModel.GetPresentUnits().ToString(); }
public static void GrabOpenSAP(ref cSapModel mySapModel, ref string ModelUnits, string DynInputUnits = "kip_ft_F") { //dimension the SapObject as cOAPI type cOAPI mySapObject = null; //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero) var ret = 0; //attach to a running instance of SAP2000 try { //get the active SapObject //try the code form the example //mySapObject =(cOAPI) Marshal.GetActiveObject("CSI.SAP2000.API.SapObject"); //get the active SapObject mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject"); } catch (Exception ex) { Console.WriteLine("No running instance of the program found or failed to attach."); return; } //Create SapModel object mySapModel = mySapObject.SapModel; // get enum from Units & Set to model if (!String.IsNullOrEmpty(DynInputUnits)) { eUnits Units = (eUnits)Enum.Parse(typeof(eUnits), DynInputUnits); try { ret = mySapModel.SetPresentUnits(Units); } catch (Exception ex) { string message = ex.Message; } } ModelUnits = mySapModel.GetPresentUnits().ToString(); }
static void Main(string[] args) { //是否启动一个新的sap2000实例 bool AttachToInstance = false; //是否从指定的sap2000启动一个实例,如果不指定,则选择最新安装的版本启动,主要是计算机安装多个sap2000版本的时候 用来选择启动版本 bool SpecifyPath = false; //如果specityPath = true 则通过ProgramPath 指定启动路径 string ProgramPath = "C:\\Program Files (x86)\\Computers and Structures\\SAP2000 19\\SAP2000.exe"; //模型的保存文件夹 运行完成后 在这个目录下将会看到结果文件 string ModelDirectory = "C:\\CSiAPIexample"; try { Directory.CreateDirectory(ModelDirectory); } catch (Exception ex) { Console.WriteLine("Could not create directory: " + ModelDirectory); } //模型名称 string ModelName = "API_1-001.sdb"; //模型保存路径 string ModelPath = ModelDirectory + Path.DirectorySeparatorChar + ModelName; //定义sap2000实例对象为cOAPI类型 先赋一个空值 后面会赋上实际的对象 cOAPI mySapObject = null; //定义一个变量ret标记函数是佛运行成功 ret=0 为成功 否则为不成功 int ret = 0; //如果AttachToInstance = true 则获取系统运行时中的sap2000实例 if (AttachToInstance) { try { //获取系统中处于active状态的sap2000实例 mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject"); } catch (Exception ex) { Console.WriteLine("No running instance of the program found or failed to attach."); return; } } else {//启动新的SAP000实例 //创建APIhelper对象 该对象可以创建sap2000实例 cHelper myHelper; try { myHelper = new Helper(); } catch (Exception ex) { Console.WriteLine("Cannot create an instance of the Helper object"); return; } //如果specitypath=true 则从programpath创建一个新sap2000实例 if (SpecifyPath) { try { mySapObject = myHelper.CreateObject(ProgramPath); } catch (Exception ex) { Console.WriteLine("Cannot start a new instance of the program from " + ProgramPath); return; } } else { //从最新安装的sap2000版本创建实例 try { mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject"); } catch (Exception ex) { Console.WriteLine("Cannot start a new instance of the program."); return; } } //启动sap2000实例 ret = mySapObject.ApplicationStart(); } //创建实例的模型 cSapModel mySapModel = mySapObject.SapModel; //初始化模型 eUnits 变量是什么没搞清楚 应该是模型的类型 ???? ret = mySapModel.InitializeNewModel((eUnits.kip_in_F)); //创建一个新的空模型文件 用户保存模型 ret = mySapModel.File.NewBlank(); //定义材料属性 ret = mySapModel.PropMaterial.SetMaterial("CONC", eMatType.Concrete, -1, "", ""); //各向同性的属性赋给材料 ret = mySapModel.PropMaterial.SetMPIsotropic("CONC", 3600, 0.2, 0.0000055, 0); //定义一个矩形截面并将上面定义的材料赋给截面 ret = mySapModel.PropFrame.SetRectangle("R1", "CONC", 12, 12, -1, "", ""); //define frame section property modifiers //定义截面的修正值 这个我没搞清楚是什么 一个截面8个值 double[] ModValue = new double[8]; int i; for (i = 0; i <= 7; i++) { ModValue[i] = 1; } ModValue[0] = 1000; ModValue[1] = 0; ModValue[2] = 0; ret = mySapModel.PropFrame.SetModifiers("R1", ref ModValue); //设置成k-ft单位制 ret = mySapModel.SetPresentUnits(eUnits.kip_ft_F); //定义线框模型 3条线 Global为坐标系 temp_string1 为系统生成的名称 string[] FrameName = new string[3]; string temp_string1 = FrameName[0]; string temp_string2 = FrameName[0]; //第一根线框 ret = mySapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, ref temp_string1, "R1", "1", "Global"); FrameName[0] = temp_string1; //第二根线框 ret = mySapModel.FrameObj.AddByCoord(0, 0, 10, 8, 0, 16, ref temp_string1, "R1", "2", "Global"); FrameName[1] = temp_string1; //第三根线框 ret = mySapModel.FrameObj.AddByCoord(-4, 0, 10, 0, 0, 10, ref temp_string1, "R1", "3", "Global"); FrameName[2] = temp_string1; //增加约束 PointName 两个约束点 string[] PointName = new string[2]; //定义下部的约束点 //定义约束 1 2 3 4 约束 5 6 不约束 一个节点6个自由度 bool[] Restraint = new bool[6]; for (i = 0; i <= 3; i++) { Restraint[i] = true; } for (i = 4; i <= 5; i++) { Restraint[i] = false; } //获取第一根线的两个节点 temp_string1 temp_string2 ret = mySapModel.FrameObj.GetPoints(FrameName[0], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; //将上面定义的约束 赋给第一个节点 ret = mySapModel.PointObj.SetRestraint(PointName[0], ref Restraint, 0); //定义顶部的约束点 该约束点只约束 0 1 两个自由度 其他自由度放开 for (i = 0; i <= 1; i++) { Restraint[i] = true; } for (i = 2; i <= 5; i++) { Restraint[i] = false; } //获取第二根线的两个节点 ret = mySapModel.FrameObj.GetPoints(FrameName[1], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; //将上面定义的约束赋给第二个节点 ret = mySapModel.PointObj.SetRestraint(PointName[1], ref Restraint, 0); //刷新sap2000界面的视图 bool temp_bool = false; ret = mySapModel.View.RefreshView(0, temp_bool); //增加7种载荷样式 temp_bool = true; ret = mySapModel.LoadPatterns.Add("1", eLoadPatternType.Other, 1, temp_bool); ret = mySapModel.LoadPatterns.Add("2", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("3", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("4", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("5", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("6", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("7", eLoadPatternType.Other, 0, temp_bool); //对第二种载荷样式添加载荷 //获取第3根线的两个节点 ret = mySapModel.FrameObj.GetPoints(FrameName[2], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; //定义载荷 第3个自由度-10 其他方向无载荷 double[] PointLoadValue = new double[6]; PointLoadValue[2] = -10; //第一个节点赋载荷 ret = mySapModel.PointObj.SetLoadForce(PointName[0], "2", ref PointLoadValue, false, "Global", 0); //添加分布载荷 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); //对第三种载荷样式添加载荷 ret = mySapModel.FrameObj.GetPoints(FrameName[2], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; //定义载荷 PointLoadValue = new double[6]; PointLoadValue[2] = -17.2; PointLoadValue[4] = -54.4; //第二节节点赋载荷 ret = mySapModel.PointObj.SetLoadForce(PointName[1], "3", ref PointLoadValue, false, "Global", 0); //载荷样式五添加载荷 第二根线添加分布载荷 ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "4", 1, 11, 0, 1, 2, 2, "Global", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); //样式五添加分布载荷 ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[0], "5", 1, 2, 0, 1, 2, 2, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "5", 1, 2, 0, 1, -2, -2, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); //样式六添加分布载荷 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); ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "6", 1, 2, 0, 1, -0.3744, 0, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); //样式7添加点载荷 ret = mySapModel.FrameObj.SetLoadPoint(FrameName[1], "7", 1, 2, 0.5, -15, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); //设置单位制 kip_in_F ret = mySapModel.SetPresentUnits(eUnits.kip_in_F); //保存模型 ret = mySapModel.File.Save(ModelPath); //分析模型 这一步会创建分析模型文件 ret = mySapModel.Analyze.RunAnalysis(); //下面的类容是后处理部分 暂时不用看 后面再研究 //initialize for SAP2000 results double[] SapResult = new double[7]; ret = mySapModel.FrameObj.GetPoints(FrameName[1], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; //get SAP2000 results for load patterns 1 through 7 int NumberResults = 0; string[] Obj = new string[1]; string[] Elm = new string[1]; string[] LoadCase = new string[1]; string[] StepType = new string[1]; double[] StepNum = new double[1]; double[] U1 = new double[1]; double[] U2 = new double[1]; double[] U3 = new double[1]; double[] R1 = new double[1]; double[] R2 = new double[1]; double[] R3 = new double[1]; for (i = 0; i <= 6; i++) { ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput(); ret = mySapModel.Results.Setup.SetCaseSelectedForOutput(System.Convert.ToString(i + 1), System.Convert.ToBoolean(-1)); if (i <= 3) { 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); U3.CopyTo(U3, 0); SapResult[i] = U3[0]; } else { 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); U1.CopyTo(U1, 0); SapResult[i] = U1[0]; } } //close SAP2000 mySapObject.ApplicationExit(false); mySapModel = null; mySapObject = null; //fill SAP2000 result strings string[] SapResultString = new string[7]; for (i = 0; i <= 6; i++) { SapResultString[i] = string.Format("{0:0.00000}", SapResult[i]); ret = (string.Compare(SapResultString[i], 1, "-", 1, 1, true)); if (ret != 0) { SapResultString[i] = " " + SapResultString[i]; } } //fill independent results double[] IndResult = new double[7]; string[] IndResultString = new string[7]; IndResult[0] = -0.02639; IndResult[1] = 0.06296; IndResult[2] = 0.06296; IndResult[3] = -0.2963; IndResult[4] = 0.3125; IndResult[5] = 0.11556; IndResult[6] = 0.00651; for (i = 0; i <= 6; i++) { IndResultString[i] = string.Format("{0:0.00000}", IndResult[i]); ret = (string.Compare(IndResultString[i], 1, "-", 1, 1, true)); if (ret != 0) { IndResultString[i] = " " + IndResultString[i]; } } //fill percent difference double[] PercentDiff = new double[7]; string[] PercentDiffString = new string[7]; for (i = 0; i <= 6; i++) { PercentDiff[i] = (SapResult[i] / IndResult[i]) - 1; PercentDiffString[i] = string.Format("{0:0%}", PercentDiff[i]); ret = (string.Compare(PercentDiffString[i], 1, "-", 1, 1, true)); if (ret != 0) { PercentDiffString[i] = " " + PercentDiffString[i]; } } //display message box comparing results string msg = ""; msg = msg + "LC Sap2000 Independent %Diff\r\n"; for (i = 0; i <= 5; i++) { msg = msg + string.Format("{0:0}", i + 1) + " " + SapResultString[i] + " " + IndResultString[i] + " " + PercentDiffString[i] + "\r\n"; } msg = msg + string.Format("{0:0}", i + 1) + " " + SapResultString[i] + " " + IndResultString[i] + " " + PercentDiffString[i]; Console.WriteLine(msg); Console.ReadKey(); }
/// <summary> /// Initializes a new instance of the <see cref="CSiApiSeed" /> class. /// </summary> /// <param name="sapObject">The sap object.</param> /// <param name="sapModel">The sap model.</param> public CSiApiSeed(cOAPI sapObject, cSapModel sapModel) { _sapObject = sapObject; _sapModel = sapModel; }
public SapModel(string _modelDirectory, string _modelName = "Trial1") { this.modelDirectory = _modelDirectory; this.modelName = _modelName; //set the following flag to true to attach to an existing instance of the program //otherwise a new instance of the program will be started AttachToInstance = false; //set the following flag to true to manually specify the path to SAP2000.exe //this allows for a connection to a version of SAP2000 other than the latest installation //otherwise the latest installed version of SAP2000 will be launched SpecifyPath = false; //if the above flag is set to true, specify the path to SAP2000 below string ProgramPath; ProgramPath = "C:\\Program Files (x86)\\Computers and Structures\\SAP2000 20\\SAP2000.exe"; //full path to the model //set it to the desired path of your model try { System.IO.Directory.CreateDirectory(ModelDirectory); } //Model Directory is input to the constructor. catch (Exception /*ex*/) { Console.WriteLine("Could not create directory: " + ModelDirectory); } modelPath = ModelDirectory + System.IO.Path.DirectorySeparatorChar + ModelName; //model name is input to the constructor. //dimension the SapObject as cOAPI type cOAPI mySapObjectAPI = null; //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero) int ret = 0; if (AttachToInstance) { //attach to a running instance of SAP2000 try { //get the active SapObject mySapObjectAPI = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject"); } catch (Exception /*ex*/) { Console.WriteLine("No running instance of the program found or failed to attach."); return; } } else { //create API helper object from which we create SAPAPI object from which we Create SAPModel// cHelper myHelper; try { myHelper = new Helper(); } catch (Exception /*ex*/) { Console.WriteLine("Cannot create an instance of the Helper object"); return; } if (SpecifyPath) { //'create an instance of the SapObject from the specified path try { //create SapObject mySapObjectAPI = myHelper.CreateObject(ProgramPath); } catch (Exception /*ex*/) { Console.WriteLine("Cannot start a new instance of the program from " + ProgramPath); return; } } else { //'create an instance of the SapObject from the latest installed SAP2000 try { //create SapObject mySapObjectAPI = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject"); } catch (Exception /*ex*/) { Console.WriteLine("Cannot start a new instance of the program."); return; } } //start SAP2000 application ret = mySapObjectAPI.ApplicationStart(eUnits.kN_m_C); } //create SapModel object mySapObjectModel = mySapObjectAPI.SapModel; }
public void SAPCalculation(string inputPath, string loadingName, string outputPath, List <string> frameName, out bool getResult, string condition, int realTimes) { //loadingName = "DL+SOIL(NL)"; loadingUID.Clear(); loadingValue.Clear(); loadingProp.Clear(); jointProp.Clear(); jtDisplacement.Clear(); myHelper = new Helper(); mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject"); ret = mySapObject.ApplicationStart(); mySapModel = mySapObject.SapModel; ret = mySapModel.InitializeNewModel((eUnits.kip_in_F)); //bool temp_bool = true; //mySapObject = new SAP2000v15.SapObject(); //mySapModel = mySapObject.SapModel; //mySapObject.ApplicationStart(SAP2000v15.eUnits.kip_ft_F, temp_bool, ""); ret = mySapModel.File.OpenFile(inputPath); ret = mySapModel.Analyze.RunAnalysis(); ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput(); ret = mySapModel.Results.Setup.SetCaseSelectedForOutput(loadingName, true); wb = new XSSFWorkbook(); for (int i = 0; i < frameName.Count; i++) { ret = mySapModel.Results.FrameForce(frameName[i], eItemTypeElm.ObjectElm, ref num, ref obj, ref ObjSta, ref elm, ref ElmSta, ref LoadCase, ref StepType_test, ref StepNum_test, ref P, ref V2, ref V3, ref T, ref M2, ref M3); var forceProp = Tuple.Create(frameName[i], loadingName, frameName[i]); loadingProp.Add(forceProp); try { forceProp = Tuple.Create(frameName[i], loadingName, frameName[i + 1]); loadingProp.Add(forceProp); } catch { forceProp = Tuple.Create(frameName[i], loadingName, frameName[0]); loadingProp.Add(forceProp); } for (int j = 0; j < 2; j++) { var forceValue = Tuple.Create(P[j], V2[j], V3[j], T[j], M2[j], M3[j]); loadingValue.Add(forceValue); loadingUID.Add(Guid.NewGuid().ToString("D")); } ret = mySapModel.Results.JointDispl(frameName[i], eItemTypeElm.ObjectElm, ref num, ref obj, ref elm, ref LoadCase, ref StepType_test, ref StepNum_test, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3); var dispProp = Tuple.Create(frameName[i], loadingName); jointProp.Add(dispProp); var dispValue = Tuple.Create(U1[0], U2[0], U3[0], R1[0], R2[0], R3[0]); jtDisplacement.Add(dispValue); } input.CreateResultFile(wb, loadingProp, loadingValue, loadingName); input.CreateDisplacementFile(wb, jointProp, jtDisplacement, "JointDisplacement"); input.FileSaving(wb, outputPath); getResult = true;//0.33直徑與地震載重使用,只有當直徑變化過目標值後再擷取分析結果, if (getResult) { try { oExcuteSQL.DeleteDataBySectionUIDAndTimes($"STN_{condition}Data", sectionUID, realTimes); } catch { } oExcuteSQL.InsertSAPData($"STN_{condition}Data", loadingUID, sectionUID, loadingProp, realTimes, loadingValue); } mySapObject.ApplicationExit(true); }
public void ModelObject(cOAPI applicationObject) { this.activeModel = applicationObject.SapModel; }
public void ApplicationObject(cHelper helper) { this.applicationObject = (cOAPI)helper.GetObject("CSI.ETABS.API.ETABSObject"); }
/// <summary> /// ALEKSANDRA COPY AND PASTE DATAEXTRACTION.TESTING CODE HERE /// </summary> /// <returns></returns> public static ExportedResults PopulateDesignResults() { //Attach to existing SAP2000v22 model cHelper myHelper = new Helper(); cOAPI mySapObject = myHelper.GetObject("CSI.SAP2000.API.SapObject"); cSapModel mySapModel = mySapObject.SapModel; //Get list of all frames int numbernames = 0; string[] names = null; mySapModel.FrameObj.GetNameList(ref numbernames, ref names); string outputname = ""; for (int i = 0; i < numbernames; i++) { bool notselected = false; mySapModel.FrameObj.GetSelected(names[i], ref notselected); if (notselected) { outputname = names[i]; break; } } string point1 = ""; string point2 = ""; mySapModel.FrameObj.GetPoints(outputname, ref point1, ref point2); double x1 = 0; double y1 = 0; double z1 = 0; double x2 = 0; double y2 = 0; double z2 = 0; mySapModel.PointObj.GetCoordCartesian(point1, ref x1, ref y1, ref z1); mySapModel.PointObj.GetCoordCartesian(point2, ref x2, ref y2, ref z2); string pointname = point1; if (z2 < z1) { pointname = point2; } int numres = 0; string[] obj = null; string[] elm = null; string[] loadcase = null; string[] steptype = null; double[] stepnum = null; double[] f1 = null; double[] f2 = null; double[] f3 = null; double[] m1 = null; double[] m2 = null; double[] m3 = null; mySapModel.Results.JointReact(pointname, eItemTypeElm.ObjectElm, ref numres, ref obj, ref elm, ref loadcase, ref steptype, ref stepnum, ref f1, ref f2, ref f3, ref m1, ref m2, ref m3); List <ForceObject> exportforce = new List <ForceObject>(); for (int j = 0; j < numres; j++) { ForceObject fobj = new ForceObject(f1[j], f2[j], f3[j], m1[j], m2[j], m3[j]); exportforce.Add(fobj); } string propname = ""; string sauto = ""; mySapModel.FrameObj.GetSection(outputname, ref propname, ref sauto); double fy = 0; double fu = 0; double efy = 0; double efu = 0; int sstype = 0; int sshys = 0; double strainhard = 0; double strainmax = 0; double strainrupt = 0; string matprop = ""; mySapModel.PropFrame.GetMaterial(propname, ref matprop); mySapModel.PropMaterial.GetOSteel(matprop, ref fy, ref fu, ref efy, ref efu, ref sstype, ref sshys, ref strainhard, ref strainmax, ref strainrupt); Steel steel = new Steel(matprop, fy); Column col = new Column(propname, steel); ExportedResults expres = new ExportedResults(); expres._column = col; expres._name = outputname; expres._exportedforces = exportforce; return(expres); }
public void Clean() { mySapModel = null; myETABSObject = null; CleanContainers(true); }
public void SAPCalculation(string inputPath, string loadingName, string outputPath, List <string> frameName) { loadingUID.Clear(); loadingValue.Clear(); loadingProp.Clear(); jointProp.Clear(); jtDisplacement.Clear(); myHelper = new Helper(); mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject"); ret = mySapObject.ApplicationStart(); mySapModel = mySapObject.SapModel; ret = mySapModel.InitializeNewModel((eUnits.kip_in_F)); //bool temp_bool = true; //mySapObject = new SapObject(); //mySapModel = mySapObject.SapModel; //mySapObject.ApplicationStart(eUnits.kip_ft_F, temp_bool, ""); ret = mySapModel.File.OpenFile(inputPath); ret = mySapModel.Analyze.RunAnalysis(); ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput(); ret = mySapModel.Results.Setup.SetCaseSelectedForOutput(loadingName, true); wb = new XSSFWorkbook(); for (int i = 0; i < frameName.Count; i++) { ret = mySapModel.Results.FrameForce(frameName[i], eItemTypeElm.ObjectElm, ref num, ref obj, ref ObjSta, ref elm, ref ElmSta, ref LoadCase, ref StepType_test, ref StepNum_test, ref P, ref V2, ref V3, ref T, ref M2, ref M3); // I-End of frame var forceProp = Tuple.Create(frameName[i], loadingName, frameName[i]); loadingProp.Add(forceProp); // J-End of frame try { forceProp = Tuple.Create(frameName[i], loadingName, frameName[i + 1]); loadingProp.Add(forceProp); } catch // last frame { forceProp = Tuple.Create(frameName[i], loadingName, frameName[0]); loadingProp.Add(forceProp); } for (int j = 0; j < 2; j++) { string tempUID = Guid.NewGuid().ToString("D"); var forceValue = Tuple.Create(P[j], V2[j], V3[j], T[j], M2[j], M3[j]); loadingValue.Add(forceValue); loadingUID.Add(tempUID); // find maximum value if (Math.Abs(V2[j]) > MaxV) { MaxV = Math.Abs(V2[j]); indexV = (i + 1).ToString(); parameterV[0] = P[j]; parameterV[1] = V2[j]; parameterV[2] = M3[j]; stirrupUID = tempUID; } if (Math.Abs(M3[j]) > MaxM) { MaxM = Math.Abs(M3[j]); indexM = (i + 1).ToString(); parameterM[0] = P[j]; parameterM[1] = V2[j]; parameterM[2] = M3[j]; RCUID = tempUID; } } ret = mySapModel.Results.JointDispl(frameName[i], eItemTypeElm.ObjectElm, ref num, ref obj, ref elm, ref LoadCase, ref StepType_test, ref StepNum_test, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3); var dispProp = Tuple.Create(frameName[i], loadingName); jointProp.Add(dispProp); var dispValue = Tuple.Create(U1[0], U2[0], U3[0], R1[0], R2[0], R3[0]); jtDisplacement.Add(dispValue); } List <Tuple <string, double, double, double> > outData = new List <Tuple <string, double, double, double> >(); outData.Add(Tuple.Create(indexV, parameterV[0], parameterV[1], parameterV[2])); outData.Add(Tuple.Create(indexM, parameterM[0], parameterM[1], parameterM[2])); input.CreateResultFile(wb, loadingProp, loadingValue, loadingName); input.CreateDisplacementFile(wb, jointProp, jtDisplacement, "JointDisplacement"); input.FileSaving(wb, outputPath); try { oExcuteSQL.DeleteDataBySectionUIDAndTimes($"STN_SiteData", sectionUID, 1); } catch { } oExcuteSQL.InsertSAPData($"STN_SiteData", loadingUID, sectionUID, loadingProp, 1, loadingValue); // close Sap2000 mySapObject.ApplicationExit(false); mySapModel = null; mySapObject = null; // validation foreach (var list in outData) { Console.WriteLine("frame {0}:\tP={1}\tV={2}\tM={3}", list.Item1, list.Item2, list.Item3, list.Item4); } }
/// <summary> /// Release the ETABS link /// </summary> public void Release() { _ETABS = null; _SapModel = null; RaiseMessage("ETABS link released."); }
static void Main(string[] args) { //Program starts here //set the following flag to true to attach to an existing instance of the program //otherwise a new instance of the program will be started bool AttachToInstance = true; //set the following flag to true to manually specify the path to SAP2000.exe //this allows for a connection to a version of SAP2000 other than the latest installation //otherwise the latest installed version of SAP2000 will be launched bool SpecifyPath = false; //if the above flag is set to true, specify the path to SAP2000 below string ProgramPath; ProgramPath = @"C:\Program Files\Computers and Structures\SAP2000 22\SAP2000.exe"; //full path to the model //set it to the desired path of your model string ModelDirectory = @"C:\CSiAPIexample"; try { System.IO.Directory.CreateDirectory(ModelDirectory); } catch (Exception ex) { Console.WriteLine("Could not create directory: " + ModelDirectory); } string ModelName = "API_1-001.sdb"; string ModelPath = ModelDirectory + System.IO.Path.DirectorySeparatorChar + ModelName; //dimension the SapObject as cOAPI type cOAPI mySapObject = null; //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero) int ret = 0; //create API helper object cHelper myHelper; try { myHelper = new Helper(); } catch (Exception ex) { Console.WriteLine("Cannot create an instance of the Helper object"); return; } if (AttachToInstance) { //attach to a running instance of SAP2000 try { //get the active SapObject mySapObject = myHelper.GetObject("CSI.SAP2000.API.SapObject"); } catch (Exception ex) { Console.WriteLine("No running instance of the program found or failed to attach."); return; } } else { if (SpecifyPath) { //'create an instance of the SapObject from the specified path try { //create SapObject mySapObject = myHelper.CreateObject(ProgramPath); } catch (Exception ex) { Console.WriteLine("Cannot start a new instance of the program from " + ProgramPath); return; } } else { //create an instance of the SapObject from the latest installed SAP2000 try { //create SapObject mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject"); } catch (Exception ex) { Console.WriteLine("Cannot start a new instance of the program."); return; } } //start SAP2000 application ret = mySapObject.ApplicationStart(); } //create SapModel object cSapModel mySapModel; mySapModel = mySapObject.SapModel; eUnits test = mySapModel.GetDatabaseUnits(); //mySapModel.FrameObj.GetSelected; bool selected = false; string name = "183"; ret = mySapModel.FrameObj.GetSelected(name, ref selected); if (selected) { string point1 = ""; string point2 = ""; mySapModel.FrameObj.GetPoints(name, ref point1, ref point2); double x1 = 0; double y1 = 0; double z1 = 0; double x2 = 0; double y2 = 0; double z2 = 0; mySapModel.PointObj.GetCoordCartesian(point1, ref x1, ref y1, ref z1); mySapModel.PointObj.GetCoordCartesian(point1, ref x2, ref y2, ref z2); //here check z or check if restrained if(z) { //use this to get reactions -> mySapModel.Results } List<ForceObject> exportforce = new List<ForceObject>(); ForceObject fobj = new ForceObject(1, 1, 1, 1, 1, 1,name); exportforce.Add(fobj); } //Get frame thats selected //Find base point //Get results from base point //If results = nothing throw message to user that selection is wrong //Else get base point reactions ////initialize model //ret = mySapModel.InitializeNewModel((eUnits.kip_in_F)); ////create new blank model //ret = mySapModel.File.NewBlank(); }
public static void SapExampleMain() { //set the following flag to true to attach to an existing instance of the program //otherwise a new instance of the program will be started bool AttachToInstance; AttachToInstance = false; //set the following flag to true to manually specify the path to SAP2000.exe //this allows for a connection to a version of SAP2000 other than the latest installation //otherwise the latest installed version of SAP2000 will be launched bool SpecifyPath; SpecifyPath = false; //if the above flag is set to true, specify the path to SAP2000 below string ProgramPath; ProgramPath = "C:\\Program Files (x86)\\Computers and Structures\\SAP2000 19\\SAP2000.exe"; //full path to the model //set it to the desired path of your model string ModelDirectory = "C:\\CSiAPIexample"; try { System.IO.Directory.CreateDirectory(ModelDirectory); } catch (Exception ex) { Console.WriteLine("Could not create directory: " + ModelDirectory); } string ModelName = "API_1-001.sdb"; string ModelPath = ModelDirectory + System.IO.Path.DirectorySeparatorChar + ModelName; //dimension the SapObject as cOAPI type cOAPI mySapObject = null; //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero) int ret = 0; // AttachToInstance -- initialized to False if (AttachToInstance) { //attach to a running instance of SAP2000 try { //get the active SapObject mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject"); } catch (Exception ex) { Console.WriteLine("No running instance of the program found or failed to attach."); return; } } else { //create API helper object cHelper myHelper; try { myHelper = new Helper(); } catch (Exception ex) { Console.WriteLine("Cannot create an instance of the Helper object"); return; } // SpecifyPath -- initialized to False if (SpecifyPath) { //'create an instance of the SapObject from the specified path try { //create SapObject mySapObject = myHelper.CreateObject(ProgramPath); } catch (Exception ex) { Console.WriteLine("Cannot start a new instance of the program from " + ProgramPath); return; } } else { //'create an instance of the SapObject from the latest installed SAP2000 try { //create SapObject mySapObject = myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject"); } catch (Exception ex) { Console.WriteLine("Cannot start a new instance of the program."); return; } } //start SAP2000 application ret = mySapObject.ApplicationStart(); } //create SapModel object cSapModel mySapModel; mySapModel = mySapObject.SapModel; //initialize model //ret = mySapModel.InitializeNewModel((eUnits.kN_mm_C)); ret = mySapModel.InitializeNewModel((eUnits.kip_in_F)); //create new blank model ret = mySapModel.File.NewBlank(); //define material property ret = mySapModel.PropMaterial.SetMaterial("CONC", eMatType.Concrete, -1, "", ""); //assign isotropic mechanical properties to material ret = mySapModel.PropMaterial.SetMPIsotropic("CONC", 3600, 0.2, 0.0000055, 0); //define rectangular frame section property ret = mySapModel.PropFrame.SetRectangle("R1", "CONC", 12, 12, -1, "", ""); //define frame section property modifiers double[] ModValue = new double[8]; int i; for (i = 0; i <= 7; i++) { ModValue[i] = 1; } ModValue[0] = 1000; ModValue[1] = 0; ModValue[2] = 0; ret = mySapModel.PropFrame.SetModifiers("R1", ref ModValue); //switch to k-ft units ret = mySapModel.SetPresentUnits(eUnits.kip_ft_F); //add frame object by coordinates string[] FrameName = new string[3]; string temp_string1 = FrameName[0]; string temp_string2 = FrameName[0]; // ret = mySapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, ref temp_string1, "R1"/*Property*/, "1"/*Label*/, "Global"); FrameName[0] = temp_string1; // ret = mySapModel.FrameObj.AddByCoord(0, 0, 10, 8, 0, 16, ref temp_string1, "R1", "2", "Global"); FrameName[1] = temp_string1; ret = mySapModel.FrameObj.AddByCoord(-4, 0, 10, 0, 0, 10, ref temp_string1, "R1", "3", "Global"); FrameName[2] = temp_string1; string framename = ""; SapMaterial s = new SapMaterial(mySapModel, "ff", MaterialType.CONCRETE); SapRecangularSection srs = new SapRecangularSection(mySapModel, s, "fouad", 12, 25, "", "", -1); SapFrameElement sfm = new SapFrameElement(mySapModel, 0, 0, 0, 0, 0, 10, "ah", ""); SapPoint point1 = new SapPoint(mySapModel, 0, 0, 10); SapPoint point2 = new SapPoint(mySapModel, 8, 0, 16); SapFrameElement sfm2 = new SapFrameElement(mySapModel, point1, point2, "", "fo2sh"); SapLoadPattern loadpattern = new SapLoadPattern(mySapModel, "m", LoadPatternType.Other, 0, true); SapFrameDistLoad distload = new SapFrameDistLoad(loadpattern, 1, 2, 0, 1, 2, 2); sfm2.AddDistributedLoad(distload); point2.SetRestraint(Restrains.Fixed); SapPointLoad pload = new SapPointLoad(loadpattern, new double[] { 1, 2, 3, 4, 5, 6 }, true); point2.AddPointLoad(pload); //sfm.Point1.SetRestraint(Restrains.Fixed); //assign point object restraint at base string[] PointName = new string[2]; bool[] Restraint = new bool[6]; for (i = 0; i <= 3; i++) { Restraint[i] = true; } for (i = 4; i <= 5; i++) { Restraint[i] = false; } ret = mySapModel.FrameObj.GetPoints(FrameName[0], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; ret = mySapModel.PointObj.SetRestraint(PointName[0], ref Restraint, 0); //assign point object restraint at top for (i = 0; i <= 1; i++) { Restraint[i] = true; } for (i = 2; i <= 5; i++) { Restraint[i] = false; } ret = mySapModel.FrameObj.GetPoints(FrameName[1], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; ret = mySapModel.PointObj.SetRestraint(PointName[1], ref Restraint, 0); //refresh view, update (initialize) zoom bool temp_bool = false; ret = mySapModel.View.RefreshView(0, temp_bool); //add load patterns temp_bool = true; ret = mySapModel.LoadPatterns.Add("1", eLoadPatternType.Other, 1, temp_bool); ret = mySapModel.LoadPatterns.Add("2", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("3", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("4", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("5", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("6", eLoadPatternType.Other, 0, temp_bool); ret = mySapModel.LoadPatterns.Add("7", eLoadPatternType.Other, 0, temp_bool); //assign loading for load pattern 2 ret = mySapModel.FrameObj.GetPoints(FrameName[2], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; double[] PointLoadValue = new double[6]; PointLoadValue[2] = -10; ret = mySapModel.PointObj.SetLoadForce(PointName[0], "2", ref PointLoadValue, false, "Global", 0); 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); //assign loading for load pattern 3 ret = mySapModel.FrameObj.GetPoints(FrameName[2], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; PointLoadValue = new double[6]; PointLoadValue[2] = -17.2; PointLoadValue[4] = -54.4; ret = mySapModel.PointObj.SetLoadForce(PointName[1], "3", ref PointLoadValue, false, "Global", 0); //assign loading for load pattern 4 ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "4", 1, 11, 0, 1, 2, 2, "Global", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); //assign loading for load pattern 5 ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[0], "5", 1, 2, 0, 1, 2, 2, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "5", 1, 2, 0, 1, -2, -2, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); //assign loading for load pattern 6 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); ret = mySapModel.FrameObj.SetLoadDistributed(FrameName[1], "6", 1, 2, 0, 1, -0.3744, 0, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); //assign loading for load pattern 7 ret = mySapModel.FrameObj.SetLoadPoint(FrameName[1], "7", 1, 2, 0.5, -15, "Local", System.Convert.ToBoolean(-1), System.Convert.ToBoolean(-1), 0); //switch to k-in units ret = mySapModel.SetPresentUnits(eUnits.kip_in_F); //save model ret = mySapModel.File.Save(ModelPath); //run model (this will create the analysis model) ret = mySapModel.Analyze.RunAnalysis(); //initialize for SAP2000 results double[] SapResult = new double[7]; ret = mySapModel.FrameObj.GetPoints(FrameName[1], ref temp_string1, ref temp_string2); PointName[0] = temp_string1; PointName[1] = temp_string2; //get SAP2000 results for load patterns 1 through 7 int NumberResults = 0; string[] Obj = new string[1]; string[] Elm = new string[1]; string[] LoadCase = new string[1]; string[] StepType = new string[1]; double[] StepNum = new double[1]; double[] U1 = new double[1]; double[] U2 = new double[1]; double[] U3 = new double[1]; double[] R1 = new double[1]; double[] R2 = new double[1]; double[] R3 = new double[1]; for (i = 0; i <= 6; i++) { ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput(); ret = mySapModel.Results.Setup.SetCaseSelectedForOutput(System.Convert.ToString(i + 1), System.Convert.ToBoolean(-1)); if (i <= 3) { 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); U3.CopyTo(U3, 0); SapResult[i] = U3[0]; } else { 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); U1.CopyTo(U1, 0); SapResult[i] = U1[0]; } } //close SAP2000 mySapObject.ApplicationExit(false); mySapModel = null; mySapObject = null; //fill SAP2000 result strings string[] SapResultString = new string[7]; for (i = 0; i <= 6; i++) { SapResultString[i] = string.Format("{0:0.00000}", SapResult[i]); ret = (string.Compare(SapResultString[i], 1, "-", 1, 1, true)); if (ret != 0) { SapResultString[i] = " " + SapResultString[i]; } } //fill independent results double[] IndResult = new double[7]; string[] IndResultString = new string[7]; IndResult[0] = -0.02639; IndResult[1] = 0.06296; IndResult[2] = 0.06296; IndResult[3] = -0.2963; IndResult[4] = 0.3125; IndResult[5] = 0.11556; IndResult[6] = 0.00651; for (i = 0; i <= 6; i++) { IndResultString[i] = string.Format("{0:0.00000}", IndResult[i]); ret = (string.Compare(IndResultString[i], 1, "-", 1, 1, true)); if (ret != 0) { IndResultString[i] = " " + IndResultString[i]; } } //fill percent difference double[] PercentDiff = new double[7]; string[] PercentDiffString = new string[7]; for (i = 0; i <= 6; i++) { PercentDiff[i] = (SapResult[i] / IndResult[i]) - 1; PercentDiffString[i] = string.Format("{0:0%}", PercentDiff[i]); ret = (string.Compare(PercentDiffString[i], 1, "-", 1, 1, true)); if (ret != 0) { PercentDiffString[i] = " " + PercentDiffString[i]; } } //display message box comparing results string msg = ""; msg = msg + "LC Sap2000 Independent %Diff\r\n"; for (i = 0; i <= 5; i++) { msg = msg + string.Format("{0:0}", i + 1) + " " + SapResultString[i] + " " + IndResultString[i] + " " + PercentDiffString[i] + "\r\n"; } msg = msg + string.Format("{0:0}", i + 1) + " " + SapResultString[i] + " " + IndResultString[i] + " " + PercentDiffString[i]; Console.WriteLine(msg); Console.ReadKey(); }
void CreateScene() { var cache = ResourceCache; scene = new Scene(Context); // Create the Octree component to the scene. This is required before adding any drawable components, or else nothing will // show up. The default octree volume will be from (-1000, -1000, -1000) to (1000, 1000, 1000) in world coordinates; it // is also legal to place objects outside the volume but their visibility can then not be checked in a hierarchically // optimizing manner octree = scene.CreateComponent <Octree> (); scene.CreateComponent <DebugRenderer>(); // Create a child scene node (at world origin) and a StaticModel component into it. Set the StaticModel to show a simple // plane mesh with a "stone" material. Note that naming the scene nodes is optional. Scale the scene node larger // (100 x 100 world units) var planeNode = scene.CreateChild("Plane"); planeNode.Scale = new Vector3(10, 1, 10); var planeObject = planeNode.CreateComponent <StaticModel> (); planeObject.Model = cache.GetModel("Models/Plane.mdl"); planeObject.SetMaterial(cache.GetMaterial("Materials/StoneTiled.xml")); // Create a directional light to the world so that we can see something. The light scene node's orientation controls the // light direction; we will use the SetDirection() function which calculates the orientation from a forward direction vector. // The light will use default settings (white light, no shadows) var lightNode = scene.CreateChild("DirectionalLight"); lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized var light = lightNode.CreateComponent <Light>(); light.LightType = LightType.Directional; //var rand = new Random(); //for (int i = 0; i < 200; i++) //{ // var mushroom = scene.CreateChild ("Mushroom"); // mushroom.Position = new Vector3 (rand.Next (90)-45, 0, rand.Next (90)-45); // mushroom.Rotation = new Quaternion (0, rand.Next (360), 0); // mushroom.SetScale (0.5f+rand.Next (20000)/10000.0f); // var mushroomObject = mushroom.CreateComponent<StaticModel>(); // mushroomObject.Model = cache.GetModel ("Models/Mushroom.mdl"); // mushroomObject.SetMaterial (cache.GetMaterial ("Materials/Mushroom.xml")); //} List <VertexBuffer.PositionNormal> lineVertices = new List <VertexBuffer.PositionNormal>(); cOAPI sapObject = null; cSapModel sapModel = null; try { var helper = new Helper(); sapObject = helper.GetObject("CSI.SAP2000.API.SapObject"); //sapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject"); sapModel = sapObject.SapModel; } catch (Exception ex) { ex.GetType(); } int numberFrames = 0; string[] frameNames = null; int ret = sapModel.FrameObj.GetNameList(ref numberFrames, ref frameNames); material = Material.FromColor(Color.Blue); material.SetTechnique(0, CoreAssets.Techniques.NoTextureUnlit); material.LineAntiAlias = true; selectedMaterial = Material.FromColor(Color.Yellow); selectedMaterial.SetTechnique(0, CoreAssets.Techniques.NoTextureUnlit); selectedMaterial.LineAntiAlias = true; Node linesNode = scene.CreateChild("linesNode"); foreach (var frameName in frameNames) { string Point1 = null; string Point2 = null; ret = sapModel.FrameObj.GetPoints(frameName, ref Point1, ref Point2); double X1 = 0; double Y1 = 0; double Z1 = 0; ret = sapModel.PointObj.GetCoordCartesian(Point1, ref X1, ref Y1, ref Z1); lineVertices.Add(new VertexBuffer.PositionNormal { Position = new Vector3((float)X1, (float)Z1, (float)Y1) }); double X2 = 0; double Y2 = 0; double Z2 = 0; ret = sapModel.PointObj.GetCoordCartesian(Point2, ref X2, ref Y2, ref Z2); lineVertices.Add(new VertexBuffer.PositionNormal { Position = new Vector3((float)X2, (float)Z2, (float)Y2) }); var start = new Vector3((float)X1, (float)Z1, (float)Y1); var end = new Vector3((float)X2, (float)Z2, (float)Y2); var frame = new Frame(start, end, material); var frameNode = linesNode.CreateChild("Frame Node"); frameNode.Position = start + (end - start) * 0.5f; frameNode.AddComponent(frame); } VertexBuffer lineBuffer = new VertexBuffer(CurrentContext, false); lineBuffer.SetSize((uint)lineVertices.Count, ElementMask.Position | ElementMask.Normal, false); lineBuffer.SetData(lineVertices.ToArray()); Geometry lineGeometry = new Geometry(); lineGeometry.SetVertexBuffer(0, lineBuffer); lineGeometry.SetDrawRange(PrimitiveType.LineList, 0, 0, 0, (uint)lineVertices.Count, true); Model lineModel = new Model(); lineModel.NumGeometries = 1; lineModel.SetGeometry(0, 0, lineGeometry); lineModel.BoundingBox = new BoundingBox(new Vector3(-10000, -10000, 1000), new Vector3(10000, 10000, 1000)); linesNode.SetScale(0.08333f); //StaticModel lines = linesNode.CreateComponent<StaticModel>(); //lines.Model = lineModel; RootNode = linesNode; //lines.SetMaterial(material); CameraNode = scene.CreateChild("camera"); camera = CameraNode.CreateComponent <Camera>(); CameraNode.Position = new Vector3(0, 25, 0); }