diff --git a/csharp/Program.cs b/csharp/Program.cs index 6d23360..38fb8e6 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -1,43 +1,312 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using SkyCivAPI.Client; +using SkyCivAPI.Constant; +using SkyCivAPI.Extensions; +using SkyCivAPI.Models; using System; -using System.IO; +using System.Collections.Generic; +using System.Linq; -namespace SkyCiv +namespace SkyCivAPI { - class Program + public class Program { - private static string inputFilePath = "input-simple-beam.json"; - private static string outputFilePath = "output.json"; - - static void Main(string[] args) + public static void Main(string[] args) { - // Load the input data (authentication & SkyCiv API commands), from a file - var jsonRequestBody = File.ReadAllText(inputFilePath); + SkyCivModelObject model = new SkyCivModelObject("metric"); - // Try calling the SkyCiv API - if( SkyCiv.TryRequest(jsonRequestBody, out var response, post: true) ) - { - response = BeautifyJson(response); + // Nodes + model.Nodes.Add(0, 0, 0); + model.Nodes.Add(0, 0.5, 0); + model.Nodes.Add(0, 1, 0); + model.Nodes.Add(0.5, 1, 0); + model.Nodes.Add(0.5, 0.5, 0); + model.Nodes.Add(1, 0.6, 0); + model.Nodes.Add(1, 0.1, 0); + model.Nodes.Add(1.5, 0.1, 0); + model.Nodes.Add(1.5, 0.6, 0); + model.Nodes.Add(1.5, 0, 0); + model.Nodes.Add(1.5, -0.4, 0); + model.Nodes.Add(1, -0.6, 0); + model.Nodes.Add(2, 0, 0); + model.Nodes.Add(2, 0.7, 0); + model.Nodes.Add(2, 1, 0); + model.Nodes.Add(1.7, 0.7, 0); + model.Nodes.Add(2.3, 0.7, 0); + model.Nodes.Add(2.5, 1, 0); + model.Nodes.Add(2.5, 0.5, 0); + model.Nodes.Add(2.5, 0, 0); + model.Nodes.Add(3, 0.5, 0); + model.Nodes.Add(3, 0, 0); + model.Nodes.Add(3.3, 0.5, 0); + model.Nodes.Add(3.3, 0.14, 0); + model.Nodes.Add(3.7, 0.14, 0); + model.Nodes.Add(3.7, 0.5, 0); + model.Nodes.Add(4, 0.5, 0); + model.Nodes.Add(4, 0.4, 0); + model.Nodes.Add(4, 0, 0); + model.Nodes.Add(4.5, 0.5, 0); + model.Nodes.Add(4.5, 0, 0); + model.Nodes.Add(-0.5, 0, 0); + model.Nodes.Add(3.3, 0, 0); + model.Nodes.Add(3.7, 0, 0); + model.Nodes.Add(4.9, 0, 0); + + // Members + model.Members.Add(1, 2, 1); + model.Members.Add(2, 3, 1); + model.Members.Add(3, 4, 1); + model.Members.Add(4, 5, 1); + model.Members.Add(5, 2, 1); + model.Members.Add(6, 7, 1); + model.Members.Add(7, 8, 1); + model.Members.Add(8, 9, 1); + model.Members.Add(8, 10, 1); + model.Members.Add(10, 11, 1); + model.Members.Add(11, 12, 1); + model.Members.Add(15, 14, 1); + model.Members.Add(14, 13, 1); + model.Members.Add(16, 14, 1); + model.Members.Add(14, 17, 1); + model.Members.Add(18, 19, 1); + model.Members.Add(19, 20, 1); + model.Members.Add(19, 21, 1); + model.Members.Add(21, 22, 1); + model.Members.Add(24, 25, 1); + model.Members.Add(25, 26, 1); + model.Members.Add(26, 23, 1); + model.Members.Add(23, 24, 1); + model.Members.Add(27, 28, 1); + model.Members.Add(28, 29, 1); + model.Members.Add(28, 30, 1); + model.Members.Add(30, 31, 1); + model.Members.Add(32, 1, 2); + model.Members.Add(1, 10, 2); + model.Members.Add(10, 13, 2); + model.Members.Add(13, 20, 2); + model.Members.Add(20, 22, 2); + model.Members.Add(22, 33, 2); + model.Members.Add(33, 34, 2); + model.Members.Add(34, 29, 2); + model.Members.Add(29, 31, 2); + model.Members.Add(31, 35, 2); + model.Members.Add(24, 33, 1, "normal", 0, "FFFfff", "FFFfff"); + model.Members.Add(25, 34, 1, "normal", 0, "FFFfff", "FFFfff"); + + // Plates + int[] plateNodeArr = new int[] { 5, 4, 3, 2 }; + model.Plates.Add(plateNodeArr, 1, 12, true); - // Request succeeded, save the response - File.WriteAllText(outputFilePath, response); + // Sections + model.Sections.AddLibrarySection(LibrarySections.Australian_Steel_300_Grade_CHS_Grade_350_101_6x3_2_CHS, 1); + model.Sections.AddLibrarySection( + LibrarySections.Australian_Steel_300_Grade_Universal_beams_150_UB_14_0, 1); - // Notify in the console - Console.Write($"The HTTP request to the SkyCiv API was successful - see {outputFilePath} for the JSON response"); + // Section with custom properties + string classJson = @"{ + 'version': 1, + 'name': '203 x 203', + 'area': 5894.42893, + 'Iy': 15391924.9909, + 'Iz': 45719276.66583, + 'J': 224234, + 'material_id': 1, + 'shear_area_z': 500, + 'shear_area_y': 800, + 'aux': { + 'composite': false, + 'Qz': 249151.30616, + 'Qy': 115057.81814, + 'centroid_point': [101.6, 101.6], + 'centroid_length': [101.6, 101.6], + 'depth': 203.2, + 'width': 203.2, + 'alpha': 0, + 'shear_area_z': 1380.153833546, + 'shear_area_y': 3889.4548957763, + 'torsion_radius': 16.5124 } - else + + }"; + + SectionProperties sectionProperties = JsonConvert.DeserializeObject(classJson); + model.Sections.AddCustomSection(sectionProperties); + + // Material + model.Materials.Add("Structural Steel", 7850, 210000, 0.29, 300, 440, "steel");// For custom material + model.Materials.Add(DefaultMaterials.STRUCTURAL_STEEL); + + // Supports + model.Supports.Add(32, "FFFFRR"); + model.Supports.Add(35, "FFFFRR"); + + // Add point load + model.PointLoads.Add("m", member: 3, position: 30.4, y_mag: -5, load_group: "LG1"); + model.PointLoads.Add("n", node: 13, y_mag: 1.6, load_group: "LG1"); + model.PointLoads.Add("n", node: 12, y_mag: -3.7, load_group: "LG1"); + + // Add moment + + model.Moments.Add("n", node: 12, y_mag: 0.3, load_group: "LG1"); + model.Moments.Add("m", member: 16, position: 0, x_mag: -0.1, load_group: "LG1"); + + // Add distributed load + model.DistributedLoads.Add(32, y_mag_A: -10, y_mag_B: -2, position_B: 100, load_group: "LG1"); + + // Pressure + model.PlatePressures.Add(1, "global", 0, 0, 0.1, "LG1"); + + // Selfweight + model.SelfWeight.Add(y: -1, load_group: "SW1"); + + //We have set up most of the properties on the model object. + //We will now see how to set the dynamic properties . Below is the example of setting the area loads + //Once the dynamic property is set, we should pass the model object for further processing. + + //Add Area Load + JObject modelObject = JObject.FromObject(model); + modelObject["area_loads"] = new JObject(); + modelObject["area_loads"]["1"] = (JToken)Newtonsoft.Json.JsonConvert.DeserializeObject(/*lang=json*/ @"{'type': 'one_way', + 'nodes': [1, 2, 3, 4], + 'members': null, + 'mag': 10, + 'direction': 'X', + 'elevations': null, + 'mags': null, + // Loads will span parallel to the direction from node 1 to node 2 + 'column_direction': '1,2', + 'loaded_members_axis': null, + 'LG': 'LG'}"); + + + + + //There are two approaches we can take from hereon.. The `modelObject` can be convereted again back to SkyCivModelObject as + //shown below + + //skyCivModelObject = modelObject.ToObject(); + //and continue setting up the properties + //or if we are done with the property setting we can just deserialize the `modelObject` + //SkyCivModelObject convertedModel = JsonConvert.DeserializeObject(modelObject.ToString()); + + + //For setting the load combinations , we have two options + // Setting the default LCs - DL1, LL1, SW1 and WIND1 factors .. This can be done by below call + model.LoadCombinations.Add("SW1 + LL1", "strength", @"{ 'SW1': 1, 'LL1': 1}"); + // Adding the custom LCs SW1 + LG1 ( where LG is other than from the default).. This can be done by + //passing the load combo factor as a string + APIExtensions.AddCustomLoadCombination(ref model, "SW1 + LG1", "strength", @"{ 'SW1': 1, 'LG1': 1}"); + + //or load combo can also be added by directly passing the dictionary + Dictionary load_combo_dict = new Dictionary(); + load_combo_dict.Add("SW2", 1); + load_combo_dict.Add("LG2", 1.5); + + APIExtensions.AddCustomLoadCombination(ref model, "SW2 + LG2", "strength", load_combo_dict); + + + + var jsonModel = JsonConvert.SerializeObject(model, Formatting.Indented); + System.IO.File.WriteAllText(@"model.json", jsonModel); + + // set up Auth + var auth = new Authentication(); + + var jsonConfig = JsonConvert.DeserializeObject(System.IO.File.ReadAllText("config.json")); + auth.Source = "API"; + auth.Username = jsonConfig["username"].Value; + auth.Key = jsonConfig["key"].Value; + + // making a request to start session, set and save model + + SkyCivRequestObject request = new SkyCivRequestObject(); + request.Auth = auth; + request.Functions.Add(APIConstants.Functions.S3D_SESSION_START, "{ keep_open:true}"); + request.Functions.Add(APIConstants.Functions.S3D_MODEL_SET, "{s3d_model:" + jsonModel + "}"); + Dictionary saveArguments = new Dictionary { - // Request failed, notify in the console (response will be an error message) - Console.Write(response); - } - } + { "name", "csharp" }, + { "path", "api samples" } + }; + request.Functions.Add(APIConstants.Functions.S3D_FILE_SAVE, saveArguments); + + request.options.ValidateInput = false; + SkyCivAPIObject apiObject = new SkyCivAPIObject(); + request.options.Timeout = 2 * 60 * 1000; + + var requestJson = JsonConvert.SerializeObject(request, Formatting.Indented); + System.IO.File.WriteAllText(@"request.json", requestJson); + + Console.WriteLine("Requesting for session start and model set"); + SkyCivAPIResponse response = apiObject.Request(request); + + var saveResponse = response.RespJsonObject["functions"].First(f => f["function"].ToString() == "s3d.file.save"); // find the save function by name + var link = saveResponse["data"].ToString(); // get the link from this functions return data + Console.WriteLine($"Request finished, model was saved at {link}"); + Console.WriteLine(response.Msg); + Console.WriteLine(response.Status); + + var responseJson = JsonConvert.SerializeObject(response.RespJsonObject); + System.IO.File.WriteAllText(@"response.json", responseJson); + + // ---------------------------------------------------------------------------------------- + // making a request including analysis + + SkyCivRequestObject analysisRequest = new SkyCivRequestObject(); + analysisRequest.Auth = auth; + analysisRequest.options.ValidateInput = false; + analysisRequest.Functions.Add(APIConstants.Functions.S3D_SESSION_START, "{ keep_open:true}"); + analysisRequest.Functions.Add(APIConstants.Functions.S3D_MODEL_SET, "{s3d_model:" + jsonModel + "}"); + request.Functions.Add(APIConstants.Functions.S3D_FILE_SAVE, saveArguments); + analysisRequest.Functions.Add(APIConstants.Functions.S3D_MODEL_SOLVE, "{\"analysis_type\":\"linear\",\"repair_model\":\"true\"," + + "\"format\":\"json\"}"); - /// - /// Deserializes and serializes the given json. - /// - /// The json to prettify. - /// Prettified json. - private static string BeautifyJson(string jsonContent) - => JsonConvert.SerializeObject( JsonConvert.DeserializeObject(jsonContent), Formatting.Indented ); + var analysisRequestJson = JsonConvert.SerializeObject(analysisRequest, Formatting.Indented); + System.IO.File.WriteAllText(@"analysisRequest.json", analysisRequestJson); + + Console.WriteLine("Requesting for Analysis"); + var analysisResponse = apiObject.Request(analysisRequest); + Console.WriteLine("Completed the Analysis"); + var analysisResponseObj = analysisResponse.RespJsonObject["functions"].First(f => f["function"].ToString() == APIConstants.Functions.S3D_MODEL_SOLVE); // find the save function by name + var analysisMsg = analysisResponseObj["msg"].ToString(); + Console.WriteLine(analysisMsg); + + var analysisResponseJson = JsonConvert.SerializeObject(analysisResponse.RespJsonObject, Formatting.Indented); + System.IO.File.WriteAllText(@"analysisResponse.json", analysisResponseJson); + + // ---------------------------------------------------------------------------------------- + // Making a request including member design (AISC_360-16_LRFD) + + SkyCivRequestObject designRequest = new SkyCivRequestObject(); + designRequest.Auth = auth; + designRequest.options.ValidateInput = false; + + designRequest.Functions.Add(APIConstants.Functions.S3D_SESSION_START, "{ keep_open:true}"); + + //AISC_360-16_LRFD + Dictionary s3dDesignOptions = new Dictionary + { + {"s3d_model" , jsonModel }, + {"design_code", "AISC_360-16_LRFD" } + }; + + designRequest.Functions.Add(APIConstants.Functions.S3D_MEMBER_DESIGN_CHECK, s3dDesignOptions); + + var designRequestJson = JsonConvert.SerializeObject(designRequest, Formatting.Indented); + System.IO.File.WriteAllText(@"designRequest.json", designRequestJson); + + Console.WriteLine("Requesting for Design"); + SkyCivAPIResponse designResponse = apiObject.Request(designRequest); + var designResponseObj = designResponse.RespJsonObject["functions"].First(f => f["function"].ToString() == APIConstants.Functions.S3D_MEMBER_DESIGN_CHECK); // find the save function by name + var designMsg = designResponseObj["msg"].ToString(); + Console.WriteLine(designMsg); + + var designResponseJson = JsonConvert.SerializeObject(designResponse.RespJsonObject, Formatting.Indented); + System.IO.File.WriteAllText(@"designResponse.json", designResponseJson); + + Console.WriteLine("Press any key to finish"); + Console.ReadLine(); + } } } diff --git a/csharp/README.md b/csharp/README.md index e85f03c..95b1c76 100644 --- a/csharp/README.md +++ b/csharp/README.md @@ -1,16 +1,355 @@ # SkyCiv API v3 C# Example -Simple example of how to call into the SkyCiv API from a console application written in C# targeting dotnet core 3.0. +Simple example of how to call into the SkyCiv API from a console application written in C# targeting dotnet core 6.0. ## Prerequisites -- dotnet 3.0 or Visual Studio 2019 +- dotnet 6.0 or Visual Studio 2022 ## Run -- change the _"YOUR_API_USERNAME_HERE"_ and _"YOUR_API_KEY_HERE"_ fields in the `full-req.json` to your own credentials. -- `cd csharp` -- `dotnet run` -- or simply open the SkyCiv.sln file in VS2019 and hit run. - -## Roadmap -- Separate the API username/api-key from the `full-req.json` in a more elegant way. -- Provide more flexibility in terms of options of the request body (auth, functions, arguments, version etc) -- Add SDK classes for serialization/deserialization to improve UX. \ No newline at end of file +- change the _"YOUR_API_USERNAME_HERE"_ and _"YOUR_API_KEY_HERE"_ fields in the `config.json` to your own credentials. +- or simply open the SkyCiv.sln file in VS2022 and hit run. + + +--- + +## Documentation + +The SkyCiv API documentation can be found here: https://skyciv.com/api/v3/ + +The SkyCiv C# package documentation is a work in progress but for now, you can refer to the [JavaScript package docs](https://skyciv.com/api/v3/docs/packages/#npm---javascript) +which are not exactly the same but very similar. The main difference being that methods use differet casing for naming . + + +--- + +## Install +If you are developing in Visual Studio, the easiest way to install the SkyCiv NuGet package is through the NuGet Package Manager in Visual Studio. +Alternatively you can install the SkyCiv.API NuGet package from Package Manager Console: +``` +PM> Install-Package SkyCiv.API + +``` +# Installing from the Command-Line + +``` + dotnet add package SkyCiv.API +``` +--- + +## Example + +The recommended use of this package is by using the `SkyCivModelObject()` , `SkyCivRequestObject()`, `SkyCivAPIObject()` classes. + +```csharp + +``` + using Newtonsoft.Json; + using Newtonsoft.Json.Linq; + using SkyCivAPI.Client; + using SkyCivAPI.Constant; + + using SkyCivAPI.Extensions; + using SkyCivAPI.Models; + + namespace SkyCivAPI + { + public class Program + { + public static void Main(string[] args) + { + SkyCivModelObject model = new SkyCivModelObject("metric"); + model.Settings.VerticalAxis = "Z"; + + // Nodes + model.Nodes.Add(0, 0, 0); + model.Nodes.Add(0, 0.5, 0); + model.Nodes.Add(0, 1, 0); + model.Nodes.Add(0.5, 1, 0); + model.Nodes.Add(0.5, 0.5, 0); + model.Nodes.Add(1, 0.6, 0); + model.Nodes.Add(1, 0.1, 0); + model.Nodes.Add(1.5, 0.1, 0); + model.Nodes.Add(1.5, 0.6, 0); + model.Nodes.Add(1.5, 0, 0); + model.Nodes.Add(1.5, -0.4, 0); + model.Nodes.Add(1, -0.6, 0); + model.Nodes.Add(2, 0, 0); + model.Nodes.Add(2, 0.7, 0); + model.Nodes.Add(2, 1, 0); + model.Nodes.Add(1.7, 0.7, 0); + model.Nodes.Add(2.3, 0.7, 0); + model.Nodes.Add(2.5, 1, 0); + model.Nodes.Add(2.5, 0.5, 0); + model.Nodes.Add(2.5, 0, 0); + model.Nodes.Add(3, 0.5, 0); + model.Nodes.Add(3, 0, 0); + model.Nodes.Add(3.3, 0.5, 0); + model.Nodes.Add(3.3, 0.14, 0); + model.Nodes.Add(3.7, 0.14, 0); + model.Nodes.Add(3.7, 0.5, 0); + model.Nodes.Add(4, 0.5, 0); + model.Nodes.Add(4, 0.4, 0); + model.Nodes.Add(4, 0, 0); + model.Nodes.Add(4.5, 0.5, 0); + model.Nodes.Add(4.5, 0, 0); + model.Nodes.Add(-0.5, 0, 0); + model.Nodes.Add(3.3, 0, 0); + model.Nodes.Add(3.7, 0, 0); + model.Nodes.Add(4.9, 0, 0); + + // Members + model.Members.Add(1, 2, 1); + model.Members.Add(2, 3, 1); + model.Members.Add(3, 4, 1); + model.Members.Add(4, 5, 1); + model.Members.Add(5, 2, 1); + model.Members.Add(6, 7, 1); + model.Members.Add(7, 8, 1); + model.Members.Add(8, 9, 1); + model.Members.Add(8, 10, 1); + model.Members.Add(10, 11, 1); + model.Members.Add(11, 12, 1); + model.Members.Add(15, 14, 1); + model.Members.Add(14, 13, 1); + model.Members.Add(16, 14, 1); + model.Members.Add(14, 17, 1); + model.Members.Add(18, 19, 1); + model.Members.Add(19, 20, 1); + model.Members.Add(19, 21, 1); + model.Members.Add(21, 22, 1); + model.Members.Add(24, 25, 1); + model.Members.Add(25, 26, 1); + model.Members.Add(26, 23, 1); + model.Members.Add(23, 24, 1); + model.Members.Add(27, 28, 1); + model.Members.Add(28, 29, 1); + model.Members.Add(28, 30, 1); + model.Members.Add(30, 31, 1); + model.Members.Add(32, 1, 2); + model.Members.Add(1, 10, 2); + model.Members.Add(10, 13, 2); + model.Members.Add(13, 20, 2); + model.Members.Add(20, 22, 2); + model.Members.Add(22, 33, 2); + model.Members.Add(33, 34, 2); + model.Members.Add(34, 29, 2); + model.Members.Add(29, 31, 2); + model.Members.Add(31, 35, 2); + model.Members.Add(24, 33, 1, "normal", 0, "FFFfff", "FFFfff"); + model.Members.Add(25, 34, 1, "normal", 0, "FFFfff", "FFFfff"); + + // Plates + int[] plateNodeArr = new int[] { 5, 4, 3, 2 }; + model.Plates.Add(plateNodeArr, 1, 12, true); + + // Sections + model.Sections.AddLibrarySection(LibrarySections.Australian_Steel_300_Grade_CHS_Grade_350_101_6x3_2_CHS, 1); + model.Sections.AddLibrarySection( + LibrarySections.Australian_Steel_300_Grade_Universal_beams_150_UB_14_0, 1); + + // Section with custom properties + string classJson = @"{ + 'version': 1, + 'name': '203 x 203', + 'area': 5894.42893, + 'Iy': 15391924.9909, + 'Iz': 45719276.66583, + 'J': 224234, + 'material_id': 1, + 'shear_area_z': 500, + 'shear_area_y': 800, + 'aux': { + 'composite': false, + 'Qz': 249151.30616, + 'Qy': 115057.81814, + 'centroid_point': [101.6, 101.6], + 'centroid_length': [101.6, 101.6], + 'depth': 203.2, + 'width': 203.2, + 'alpha': 0, + 'shear_area_z': 1380.153833546, + 'shear_area_y': 3889.4548957763, + 'torsion_radius': 16.5124 + } + + }"; + + SectionProperties sectionProperties = JsonConvert.DeserializeObject(classJson); + model.Sections.AddCustomSection(sectionProperties); + + // Material + model.Materials.Add("Structural Steel", 7850, 210000, 0.29, 300, 440, "steel");// For custom material + + + model.Materials.Add(DefaultMaterials.STRUCTURAL_STEEL); + + // Supports + model.Supports.Add(32, "FFFFRR"); + model.Supports.Add(35, "FFFFRR"); + + // Add point load + model.PointLoads.Add("m", member: 3, position: 30.4, y_mag: -5, load_group: "LG1"); + model.PointLoads.Add("n", node: 13, y_mag: 1.6, load_group: "LG1"); + model.PointLoads.Add("n", node: 12, y_mag: -3.7, load_group: "LG1"); + + // Add moment + + model.Moments.Add("n", node: 12, y_mag: 0.3, load_group: "LG1"); + model.Moments.Add("m", member: 16, position: 0, x_mag: -0.1, load_group: "LG1"); + + // Add distributed load + model.DistributedLoads.Add(32, y_mag_A: -10, y_mag_B: -2, position_B: 100, load_group: "LG1"); + + + + + + // Pressure + model.PlatePressures.Add(1, "global", 0, 0, 0.1, "LG1"); + + // Selfweight + model.SelfWeight.Add(y: -1, load_group: "SW1"); + + //We have set up most of the properties on the model object. + //We will now see how to set the dynamic properties . Below is the example of setting the area loads + //Once the dynamic property is set, we should pass the model object for further processing. + + //Add Area Load + + + JObject modelObject = JObject.FromObject(model); + modelObject["area_loads"] = new JObject(); + modelObject["area_loads"]["1"] = (JToken)Newtonsoft.Json.JsonConvert.DeserializeObject(/*lang=json*/ @"{'type': 'one_way', + 'nodes': [1, 2, 3, 4], + 'members': null, + 'mag': 10, + 'direction': 'X', + 'elevations': null, + 'mags': null, + // Loads will span parallel to the direction from node 1 to node 2 + 'column_direction': '1,2', + 'loaded_members_axis': null, + 'LG': 'LG'}"); + + + + //There are two approaches we can take from hereon.. The `modelObject` can be convereted again back to SkyCivModelObject as + //shown below + + //skyCivModelObject = modelObject.ToObject(); + //and continue setting up the properties + //or if we are done with the property setting we can just deserialize the `modelObject` + //SkyCivModelObject convertedModel = JsonConvert.DeserializeObject(modelObject.ToString()); + + + //For setting the load combinations , we have two options + // Setting the default LCs - DL1, LL1, SW1 and WIND1 factors .. This can be done by below call + model.LoadCombinations.Add("SW1 + LL1", "strength", @"{ 'SW1': 1, 'LL1': 1}"); + // Adding the custom LCs SW1 + LG1 ( where LG is other than from the default).. This can be done by + + APIExtensions.AddCustomLoadCombination(ref model, "SW1 + LG1", "strength", @"{ 'SW1': 1, 'LG1': 1}"); + + + + var jsonModel = JsonConvert.SerializeObject(model, Formatting.Indented); + System.IO.File.WriteAllText(@"model.json", jsonModel); + + // set up Auth + + var auth = new Authentication(); + auth.Source = "API"; + auth.Username = "nilay.ram@skyciv.com"; + auth.Key = "v1tMCV5J4TQ5mEojrSN7N8fWNyRbfeNmwBBuax6JhTdU2udr4I4nhoAIxtMxIgLQ"; + + // making a request to start session, set and save model + + SkyCivRequestObject request = new SkyCivRequestObject(); + request.Auth = auth; + request.Functions.Add(APIConstants.Functions.S3D_SESSION_START, "{ keep_open:true}"); + request.Functions.Add(APIConstants.Functions.S3D_MODEL_SET, "{s3d_model:" + jsonModel + "}"); + Dictionary saveArguments = new Dictionary + { + { "name", "csharp" }, + { "path", "api samples" } + }; + request.Functions.Add(APIConstants.Functions.S3D_FILE_SAVE, saveArguments); + + request.options.ValidateInput = false; + SkyCivAPIObject apiObject = new SkyCivAPIObject(); + request.options.Timeout = 2 * 60 * 1000; + + var requestJson = JsonConvert.SerializeObject(request, Formatting.Indented); + System.IO.File.WriteAllText(@"request.json", requestJson); + + Console.WriteLine("Requesting for session start and model set"); + SkyCivAPIResponse response = apiObject.Request(request); + + var saveResponse = response.RespJsonObject["functions"].First(f => f["function"].ToString() == "s3d.file.save"); // find the save function by name + var link = saveResponse["data"].ToString(); // get the link from this functions return data + Console.WriteLine($"Request finished, model was saved at {link}"); + Console.WriteLine(response.Msg); + Console.WriteLine(response.Status); + + var responseJson = JsonConvert.SerializeObject(response.RespJsonObject); + System.IO.File.WriteAllText(@"response.json", responseJson); + + // ---------------------------------------------------------------------------------------- + // making a request including analysis + + SkyCivRequestObject analysisRequest = new SkyCivRequestObject(); + analysisRequest.Auth = auth; + analysisRequest.options.ValidateInput = false; + analysisRequest.Functions.Add(APIConstants.Functions.S3D_SESSION_START, "{ keep_open:true}"); + analysisRequest.Functions.Add(APIConstants.Functions.S3D_MODEL_SET, "{s3d_model:" + jsonModel + "}"); + request.Functions.Add(APIConstants.Functions.S3D_FILE_SAVE, saveArguments); + analysisRequest.Functions.Add(APIConstants.Functions.S3D_MODEL_SOLVE, "{\"analysis_type\":\"linear\",\"repair_model\":\"true\"," + + "\"format\":\"json\"}"); + + var analysisRequestJson = JsonConvert.SerializeObject(analysisRequest, Formatting.Indented); + System.IO.File.WriteAllText(@"analysisRequest.json", analysisRequestJson); + + Console.WriteLine("Requesting for Analysis"); + var analysisResponse = apiObject.Request(analysisRequest); + Console.WriteLine("Completed the Analysis"); + var analysisResponseObj = analysisResponse.RespJsonObject["functions"].First(f => f["function"].ToString() == APIConstants.Functions.S3D_MODEL_SOLVE); // find the save function by name + var analysisMsg = analysisResponseObj["msg"].ToString(); + Console.WriteLine(analysisMsg); + + var analysisResponseJson = JsonConvert.SerializeObject(analysisResponse.RespJsonObject, Formatting.Indented); + System.IO.File.WriteAllText(@"analysisResponse.json", analysisResponseJson); + + // ---------------------------------------------------------------------------------------- + // Making a request including member design (AISC_360-16_LRFD) + + SkyCivRequestObject designRequest = new SkyCivRequestObject(); + designRequest.Auth = auth; + designRequest.options.ValidateInput = false; + designRequest.Functions.Add(APIConstants.Functions.S3D_SESSION_START, "{ keep_open:true}"); + + //AISC_360-16_LRFD + Dictionary s3dDesignOptions = new Dictionary + { + {"s3d_model" , jsonModel }, + {"design_code", "AISC_360-16_LRFD" } + }; + + designRequest.Functions.Add(APIConstants.Functions.S3D_MEMBER_DESIGN_CHECK, s3dDesignOptions); + + var designRequestJson = JsonConvert.SerializeObject(designRequest, Formatting.Indented); + System.IO.File.WriteAllText(@"designRequest.json", designRequestJson); + + Console.WriteLine("Requesting for Design"); + SkyCivAPIResponse designResponse = apiObject.Request(designRequest); + var designResponseObj = designResponse.RespJsonObject["functions"].First(f => f["function"].ToString() == APIConstants.Functions.S3D_MEMBER_DESIGN_CHECK); // find the save function by name + var designMsg = designResponseObj["msg"].ToString(); + Console.WriteLine(designMsg); + + + var designResponseJson = JsonConvert.SerializeObject(designResponse.RespJsonObject, Formatting.Indented); + System.IO.File.WriteAllText(@"designResponse.json", designResponseJson); + + Console.WriteLine("Press any key to finish"); + Console.ReadLine(); + } + } + } + diff --git a/csharp/SkyCiv.csproj b/csharp/SkyCiv.csproj index 0d0f9dd..3239ee6 100644 --- a/csharp/SkyCiv.csproj +++ b/csharp/SkyCiv.csproj @@ -1,19 +1,23 @@ - + - - Exe - netcoreapp3.0 - true - + + Exe + net6.0 + true + - - - + + + + - - - Always - - + + + Always + + + Always + + diff --git a/csharp/config.json b/csharp/config.json new file mode 100644 index 0000000..9fd5284 --- /dev/null +++ b/csharp/config.json @@ -0,0 +1,4 @@ +{ + "username": "YOUR_API_USERNAME_HERE", + "key": "YOUR_API_KEY_HERE" +} \ No newline at end of file