Example #1
0
        public static void InitializeSapModel(ref SapObject mySAPObject, ref cSapModel mySapModel, string units)
        {
            long ret = 0;

            //TO DO: Grab open Instance if already open!!!

            //Create SAP2000 Object
            mySAPObject = new SAP2000v20.SapObject();

            // get enum from Units
            eUnits Units = (eUnits)Enum.Parse(typeof(eUnits), units);

            //Start Application
            mySAPObject.ApplicationStart(Units, true);

            //Create SapModel object
            mySapModel = mySAPObject.SapModel;

            //initialize the model
            ret = mySapModel.InitializeNewModel(Units);

            //create new blank model
            ret = mySapModel.File.NewBlank();

            //SET UP ... SET UP ... SET UP ... SET UP
            DefineMaterials(ref mySapModel);
        }
Example #2
0
        public void ShellStructure()
        {
            // Launch SAP2000v20 and Open a blank model
            SapObject mySapObject = null;
            cSapModel mySapModel  = null;

            SAPConnection.Initialize.InitializeSapModel(ref mySapObject, ref mySapModel, "kip_ft_F");

            //Open and Run the sample file
            OpenAndRunDynamoDefinition(@".\Sample_1c_ShellStructure.dyn");

            // Test Logic is here --->
            string failreport = string.Empty;

            // Check dropdown Shell Types
            var ShellType = (Int64)GetPreviewValue("e0c739ee-8e95-4531-95b8-d5bb71501b6c");

            if (ShellType != 1)
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Shell Types Dropdown" + "' returns wrong value !");
            }

            // Check Node ShellProp.Define
            if (IsNodeInErrorOrWarningState("c0f21c61-375a-42b8-a1f4-d94a43f1272b"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "ShellProp.Define" + "' failed or threw a warning.");
            }

            // Check Node Shell.FromSurface
            if (IsNodeInErrorOrWarningState("0c217e34-2531-4450-a066-f839b64b1a1e"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Shell.FromSurface" + "' failed or threw a warning.");
            }

            // Check Node StructuralModel.Collector
            if (IsNodeInErrorOrWarningState("a6bc0f86-a159-4f79-934d-238323b65de8"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "StructuralModel.Collector" + "' failed or threw a warning.");
            }

            // Check Node Bake to SAP
            if (IsNodeInErrorOrWarningState("d86c67da-ff87-4c04-8976-c7a00a640518"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Bake.toSAP" + "' failed or threw a warning.");
            }

            // Set SAP instances to null;
            mySapObject.ApplicationExit(false);
            mySapObject = null;
            mySapModel  = null;

            if (!string.IsNullOrEmpty(failreport))
            {
                Assert.Fail(failreport);
            }

            //if we got here, nothing failed.
            Assert.Pass();
        }
Example #3
0
        public static void Release(ref SapObject SAP, ref cSapModel Model)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();

            if (SAP != null)
            {
                Marshal.FinalReleaseComObject(SAP);
            }

            if (Model != null)
            {
                Marshal.FinalReleaseComObject(Model);
            }
        }
Example #4
0
        public static void GrabOpenSAP(ref cSapModel mySapModel, ref string ModelUnits, string DynInputUnits = "kip_ft_F")
        {
            Process[] SapInstances = Process.GetProcessesByName("SAP2000");

            //http://docs.csiamerica.com/help-files/sap2000-oapi/SAP2000_API_Fuctions/General_Functions/SetAsActiveObject.htm
            if (SapInstances.LongLength >= 1)
            {
                SapObject Obj;
                object    getObj = ROTHelper.GetActiveObject("SAP2000v20.SapObject");
                if (getObj == null)
                {
                    Obj    = new SapObject();
                    getObj = ROTHelper.GetActiveObject("SAP2000v20.SapObject");
                }
                if (getObj != null)
                {
                    Obj        = (SapObject)getObj;
                    mySapModel = Obj.SapModel;
                    // get enum from Units & Set to model
                    if (!String.IsNullOrEmpty(DynInputUnits))
                    {
                        eUnits Units = (eUnits)Enum.Parse(typeof(eUnits), DynInputUnits);
                        try
                        {
                            int ret = mySapModel.SetPresentUnits(Units);
                        }
                        catch (Exception ex) {
                            string message = ex.Message;
                        }
                    }
                    ModelUnits = mySapModel.GetPresentUnits().ToString();
                }

                //SET UP ... SET UP ... SET UP ... SET UP
                try
                {
                    DefineMaterials(ref mySapModel);
                }
                catch { }
            }
        }
Example #5
0
 /// <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 CSiApiBaseSeed(SapObject sapObject, cSapModel sapModel)
 {
     SapObject = sapObject;
     SapModel  = sapModel;
 }
Example #6
0
        public void SpaceStructure()
        {
            // Launch SAP2000v20 and Open a blank model
            SapObject mySapObject = null;
            cSapModel mySapModel  = null;

            SAPConnection.Initialize.InitializeSapModel(ref mySapObject, ref mySapModel, "kip_ft_F");

            //Open and Run the sample file
            OpenAndRunDynamoDefinition(@".\Sample_1a_SpaceStructure.dyn");

            // Test Logic is here --->
            string failreport = string.Empty;

            // Check dropdown Material Types
            var material = (string)GetPreviewValue("89e9e6aa-5ea9-4641-8bee-743b2173ada1");

            if (material != "A992Fy50")
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Materials Dropdown" + "' returns wrong value !");
            }
            //Assert.Fail("The node called '" + "Materials Dropdown" + "' returns wrong value !");

            // Check dropdown Section Catalog Types
            var sectionCatalog = (string)GetPreviewValue("579cbea6-5b14-4023-bfef-44fde2eff3ee");

            if (sectionCatalog != "AISC14")
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Section Catalog Dropdown" + "' returns wrong value !");
            }
            //Assert.Fail("The node called '" + "Section Catalog Dropdown" + "' returns wrong result !");

            // Check Section Name read from SAP
            var sectionName = (string)GetPreviewValue("ba2e32bc-89b3-4566-9555-de98e9e98c2b");

            if (sectionName != "HSS5.563X.375")
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Section Name" + "' returns wrong value !");
            }
            //Assert.Fail("The node called '" + "Section Name" + "' returns wrong value !");

            // Check dropdown Units
            var units = (string)GetPreviewValue("aa80e305-bb4a-418b-87f4-022dd0268680");

            if (units == "kip_ft_F")
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Units" + "' returns wrong value !");
            }
            //Assert.Fail("The node called '" + "Units" + "' returns wrong value !");


            // Check Node Frame.FromLine
            if (IsNodeInErrorOrWarningState("73b79339-e8d9-4841-ac63-12d45e184b2f"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Frame.FromLine" + "' failed or threw a warning.");
                //Assert.Fail("The node called '" + "Frame.FromLine" + "' failed or threw a warning.");
            }

            // Check Node Bake to SAP
            if (IsNodeInErrorOrWarningState("d86c67da-ff87-4c04-8976-c7a00a640518"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Bake.toSAP" + "' failed or threw a warning.");
                //Assert.Fail("The node called '" + "Bake.toSAP" + "' failed or threw a warning.");
            }

            // Set SAP instances to null;
            mySapObject.ApplicationExit(false);
            mySapObject = null;
            mySapModel  = null;

            if (!string.IsNullOrEmpty(failreport))
            {
                Assert.Fail(failreport);
            }

            //if we got here, nothing failed.
            Assert.Pass();
        }
Example #7
0
        public void SpaceStructurewLoads()
        {
            // Launch SAP2000v20 and Open a blank model
            SapObject mySapObject = null;
            cSapModel mySapModel  = null;

            SAPConnection.Initialize.InitializeSapModel(ref mySapObject, ref mySapModel, "kip_ft_F");

            //Open and Run the sample file
            OpenAndRunDynamoDefinition(@".\Sample_1b_SpaceStructure_withLoads.dyn");

            // Test Logic is here --->
            string failreport = string.Empty;

            // Check dropdown Load Pattern Types
            var loadPatternType = (string)GetPreviewValue("c7adc7d3-fff5-49bc-b5ee-586546d3f1ba");

            if (loadPatternType != "LTYPE_DEAD")
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "LoadPatternTypes Dropdown" + "' returns wrong value !");
            }

            // Check Node SetLoadPattern
            if (IsNodeInErrorOrWarningState("89e67ebd-f8a6-4bec-a92e-1dfee2046852"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "LoadPattern.SetLoadPattern" + "' failed or threw a warning.");
            }

            // Check dropdown Load Type
            var loadType = (string)GetPreviewValue("7a68135c-0101-482d-a0a9-d1dd96cb00cd");

            if (loadType != "Force")
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Load Type Dropdown" + "' returns wrong value !");
            }

            // Check dropdown Load Direction
            var loadDirection = (Int64)GetPreviewValue("4abab34c-9147-4227-8c87-b6950b2fdcae");

            if (loadDirection != 6)
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Load Direction Dropdown" + "' returns wrong value !");
            }

            // Check Node Load.DistributedLoad
            if (IsNodeInErrorOrWarningState("c9d48de5-889c-4bf1-bfe8-462b8b0bc63d"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Load.DistributedLoad" + "' failed or threw a warning.");
            }

            // Check Node Frame.SetLoad
            if (IsNodeInErrorOrWarningState("fc60d698-d938-4513-b808-0619c35b25b2"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Frame.SetLoad" + "' failed or threw a warning.");
            }

            // Check Node StructuralModel.Collector
            if (IsNodeInErrorOrWarningState("3bfbb3b1-47e0-4aa9-8920-e589ec0ffbc9"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "StructuralModel.Collector" + "' failed or threw a warning.");
            }

            // Check Node Frame.DisplayLoads
            if (IsNodeInErrorOrWarningState("abee3b8e-52fe-44a4-9221-75b1d1a0bf5a"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "Frame.DisplayLoads" + "' failed or threw a warning.");
            }

            // Check Node StructuralModel.Decompose
            if (IsNodeInErrorOrWarningState("e449b27f-1209-4dc1-a94a-dfef78e20a00"))
            {
                failreport = string.Format(failreport + "{0}{1}", Environment.NewLine, "The node called '" + "StructuralModel.Decompose" + "' failed or threw a warning.");
            }

            // Set SAP instances to null;
            mySapObject.ApplicationExit(false);
            mySapObject = null;
            mySapModel  = null;

            if (!string.IsNullOrEmpty(failreport))
            {
                Assert.Fail(failreport);
            }

            //if we got here, nothing failed.
            Assert.Pass();
        }
        public void SAPCalculation(string inputPath, string loadingName, string outputPath, List <string> frameName)
        {
            loadingUID.Clear();
            loadingValue.Clear();
            loadingProp.Clear();
            jointProp.Clear();
            jtDisplacement.Clear();

            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);
            }
        }