From ff6595296526cf724dacb7924bf46af37ecbb24e Mon Sep 17 00:00:00 2001 From: rnilay81 Date: Tue, 23 May 2023 15:36:42 +0530 Subject: [PATCH 1/7] Added the new prorgam sample and readme --- csharp/Program.cs | 317 ++++++++++++++++++++++++++++++++++++---- csharp/README.md | 341 +++++++++++++++++++++++++++++++++++++++++-- csharp/SkyCiv.csproj | 13 +- csharp/config.json | 5 + 4 files changed, 637 insertions(+), 39 deletions(-) create mode 100644 csharp/config.json diff --git a/csharp/Program.cs b/csharp/Program.cs index 6d23360..1ee89d3 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -1,43 +1,304 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using SkyCivAPI.Client; +using SkyCivAPI.Constant; + +using SkyCivAPI.Extensions; +using SkyCivAPI.Models; +using System.Collections.Generic; using System; using System.IO; +using File = System.IO.File; +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"); - // Request succeeded, save the response - File.WriteAllText(outputFilePath, response); + // Plates + int[] plateNodeArr = new int[] { 5, 4, 3, 2 }; + model.Plates.Add(plateNodeArr, 1, 12, true); - // Notify in the console - Console.Write($"The HTTP request to the SkyCiv API was successful - see {outputFilePath} for the JSON 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); + + // 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 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()); + + SkyCivModelObject convertedModel = modelObject.ToObject(); + convertedModel.LoadCombinations.Add("SW1 + LG1", "strength", @"{ 'SW1': 1, 'LG1': 1}"); + + + var jsonModel = JsonConvert.SerializeObject(convertedModel, Formatting.Indented); + System.IO.File.WriteAllText(@"model.json", jsonModel); + + // set up Auth + var auth = new Authentication(); + + var jsonConfig = JsonConvert.DeserializeObject(File.ReadAllText("config.json")); + auth.Source = "API"; + auth.Username = jsonConfig["username"].Value; + auth.Key = jsonConfig["token_ID"].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; + + 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; - /// - /// 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 ); + 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.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..03e5912 100644 --- a/csharp/README.md +++ b/csharp/README.md @@ -5,12 +5,335 @@ Simple example of how to call into the SkyCiv API from a console application wri - dotnet 3.0 or Visual Studio 2019 ## 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"); + + // 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, 12, 1, 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 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()); + + SkyCivModelObject convertedModel = modelObject.ToObject(); + convertedModel.LoadCombinations.Add("SW1 + LG1", "strength", @"{ 'SW1': 1, 'LG1': 1}"); + + + var jsonModel = JsonConvert.SerializeObject(convertedModel, Formatting.Indented); + System.IO.File.WriteAllText(@"model.json", jsonModel); + + // set up Auth + var auth = new Authentication(); + auth.Source = "API"; + auth.Username = "YOUR_API_USERNAME_HERE"; + auth.Key = "YOUR_API_KEY_HERE"; + + // 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; + + 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.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.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..2087bd7 100644 --- a/csharp/SkyCiv.csproj +++ b/csharp/SkyCiv.csproj @@ -1,8 +1,8 @@ - + Exe - netcoreapp3.0 + net6.0 true @@ -11,6 +11,15 @@ + + ..\..\cs-api-wrapper-nuget\cs-api-wrapper\bin\Debug\net6.0\SkyCivAPI.dll + + + + + + Always + Always diff --git a/csharp/config.json b/csharp/config.json new file mode 100644 index 0000000..ebd6b3f --- /dev/null +++ b/csharp/config.json @@ -0,0 +1,5 @@ +{ + "username": "YOUR_API_USERNAME_HERE", + "token_ID": "YOUR_API_KEY_HERE" + +} From e01fe0996622483d27af6a057119d80d60c4d6b9 Mon Sep 17 00:00:00 2001 From: rnilay81 Date: Tue, 23 May 2023 15:41:44 +0530 Subject: [PATCH 2/7] updated the reference to .net core --- csharp/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp/README.md b/csharp/README.md index 03e5912..d7d994c 100644 --- a/csharp/README.md +++ b/csharp/README.md @@ -1,8 +1,8 @@ # 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 `config.json` to your own credentials. From 23f204027e796cdc8afd65fe8fa9432033df6b9b Mon Sep 17 00:00:00 2001 From: rnilay81 Date: Tue, 23 May 2023 16:46:54 +0530 Subject: [PATCH 3/7] Added nuget package reference --- csharp/SkyCiv.csproj | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/csharp/SkyCiv.csproj b/csharp/SkyCiv.csproj index 2087bd7..5011dd8 100644 --- a/csharp/SkyCiv.csproj +++ b/csharp/SkyCiv.csproj @@ -1,28 +1,23 @@  - - Exe - net6.0 - true - + + Exe + net6.0 + true + - - - + + + + - - - ..\..\cs-api-wrapper-nuget\cs-api-wrapper\bin\Debug\net6.0\SkyCivAPI.dll - - - - - - Always - - - Always - - + + + Always + + + Always + + From eb7c89129f51e0c804c6496fc9595285c42eadb4 Mon Sep 17 00:00:00 2001 From: rnilay81 Date: Thu, 25 May 2023 15:01:18 +0530 Subject: [PATCH 4/7] changed the nuget version of api --- csharp/Program.cs | 6 ++++-- csharp/SkyCiv.csproj | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/csharp/Program.cs b/csharp/Program.cs index 1ee89d3..5d874f5 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -226,7 +226,7 @@ public static void Main(string[] args) request.options.ValidateInput = false; SkyCivAPIObject apiObject = new SkyCivAPIObject(); - request.options.Timeout = 2; + request.options.Timeout = 2 * 60 * 1000; var requestJson = JsonConvert.SerializeObject(request, Formatting.Indented); System.IO.File.WriteAllText(@"request.json", requestJson); @@ -248,7 +248,7 @@ public static void Main(string[] args) 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); @@ -273,6 +273,8 @@ public static void Main(string[] args) 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 diff --git a/csharp/SkyCiv.csproj b/csharp/SkyCiv.csproj index 5011dd8..54b5df5 100644 --- a/csharp/SkyCiv.csproj +++ b/csharp/SkyCiv.csproj @@ -8,7 +8,7 @@ - + From d2b672aa9f8cccfdfc890b1b2d1f2ed96242100f Mon Sep 17 00:00:00 2001 From: Stuart Gale Date: Wed, 28 Jun 2023 15:30:16 +0100 Subject: [PATCH 5/7] minor formatting changes --- csharp/Program.cs | 20 +++----------------- csharp/config.json | 5 ++--- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/csharp/Program.cs b/csharp/Program.cs index 5d874f5..2121240 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -2,13 +2,10 @@ using Newtonsoft.Json.Linq; using SkyCivAPI.Client; using SkyCivAPI.Constant; - using SkyCivAPI.Extensions; using SkyCivAPI.Models; -using System.Collections.Generic; using System; -using System.IO; -using File = System.IO.File; +using System.Collections.Generic; using System.Linq; namespace SkyCivAPI @@ -138,8 +135,6 @@ public static void Main(string[] args) // Material model.Materials.Add("Structural Steel", 7850, 210000, 0.29, 300, 440, "steel");// For custom material - - model.Materials.Add(DefaultMaterials.STRUCTURAL_STEEL); // Supports @@ -159,10 +154,6 @@ public static void Main(string[] args) // 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"); @@ -174,8 +165,6 @@ public static void Main(string[] args) //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', @@ -190,7 +179,6 @@ public static void Main(string[] args) '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 and continue setting up the properties //or if we are done with the property setting we can just deserialize the `modelObject` @@ -199,17 +187,16 @@ public static void Main(string[] args) SkyCivModelObject convertedModel = modelObject.ToObject(); convertedModel.LoadCombinations.Add("SW1 + LG1", "strength", @"{ 'SW1': 1, 'LG1': 1}"); - var jsonModel = JsonConvert.SerializeObject(convertedModel, Formatting.Indented); System.IO.File.WriteAllText(@"model.json", jsonModel); // set up Auth var auth = new Authentication(); - var jsonConfig = JsonConvert.DeserializeObject(File.ReadAllText("config.json")); + var jsonConfig = JsonConvert.DeserializeObject(System.IO.File.ReadAllText("config.json")); auth.Source = "API"; auth.Username = jsonConfig["username"].Value; - auth.Key = jsonConfig["token_ID"].Value; + auth.Key = jsonConfig["key"].Value; // making a request to start session, set and save model @@ -295,7 +282,6 @@ public static void Main(string[] args) var designMsg = designResponseObj["msg"].ToString(); Console.WriteLine(designMsg); - var designResponseJson = JsonConvert.SerializeObject(designResponse.RespJsonObject, Formatting.Indented); System.IO.File.WriteAllText(@"designResponse.json", designResponseJson); diff --git a/csharp/config.json b/csharp/config.json index ebd6b3f..9fd5284 100644 --- a/csharp/config.json +++ b/csharp/config.json @@ -1,5 +1,4 @@ { "username": "YOUR_API_USERNAME_HERE", - "token_ID": "YOUR_API_KEY_HERE" - -} + "key": "YOUR_API_KEY_HERE" +} \ No newline at end of file From 529df9c9a54cce1613b13a7f8cd9e16af0b6ef91 Mon Sep 17 00:00:00 2001 From: rnilay81 Date: Mon, 24 Jul 2023 13:41:49 +0530 Subject: [PATCH 6/7] Changes for LC and new versionof nuget --- csharp/Program.cs | 14 ++++++++---- csharp/README.md | 52 +++++++++++++++++++++++++++++--------------- csharp/SkyCiv.csproj | 2 +- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/csharp/Program.cs b/csharp/Program.cs index 2121240..fa75027 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -179,15 +179,21 @@ public static void Main(string[] args) 'loaded_members_axis': null, 'LG': 'LG'}"); + + + + //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}"); + //There are two approaches we can take from hereon.. The `modelObject` can be convereted again back to SkyCivModelObject as //shown below 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()); - SkyCivModelObject convertedModel = modelObject.ToObject(); - convertedModel.LoadCombinations.Add("SW1 + LG1", "strength", @"{ 'SW1': 1, 'LG1': 1}"); - - var jsonModel = JsonConvert.SerializeObject(convertedModel, Formatting.Indented); + var jsonModel = JsonConvert.SerializeObject(model, Formatting.Indented); System.IO.File.WriteAllText(@"model.json", jsonModel); // set up Auth diff --git a/csharp/README.md b/csharp/README.md index d7d994c..95b1c76 100644 --- a/csharp/README.md +++ b/csharp/README.md @@ -42,21 +42,22 @@ The recommended use of this package is by using the `SkyCivModelObject()` , `Sky ```csharp ``` - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - using SkyCivAPI.Client; - using SkyCivAPI.Constant; + using Newtonsoft.Json; + using Newtonsoft.Json.Linq; + using SkyCivAPI.Client; + using SkyCivAPI.Constant; - using SkyCivAPI.Extensions; - using SkyCivAPI.Models; + using SkyCivAPI.Extensions; + using SkyCivAPI.Models; - namespace SkyCivAPI + namespace SkyCivAPI + { + public class Program { - 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); @@ -138,7 +139,7 @@ The recommended use of this package is by using the `SkyCivModelObject()` , `Sky // Plates int[] plateNodeArr = new int[] { 5, 4, 3, 2 }; - model.Plates.Add(plateNodeArr, 12, 1, true); + model.Plates.Add(plateNodeArr, 1, 12, true); // Sections model.Sections.AddLibrarySection(LibrarySections.Australian_Steel_300_Grade_CHS_Grade_350_101_6x3_2_CHS, 1); @@ -177,6 +178,8 @@ The recommended use of this package is by using the `SkyCivModelObject()` , `Sky // Material model.Materials.Add("Structural Steel", 7850, 210000, 0.29, 300, 440, "steel");// For custom material + + model.Materials.Add(DefaultMaterials.STRUCTURAL_STEEL); // Supports @@ -228,23 +231,34 @@ The recommended use of this package is by using the `SkyCivModelObject()` , `Sky 'LG': 'LG'}"); + //There are two approaches we can take from hereon.. The `modelObject` can be convereted again back to SkyCivModelObject as - //shown below and continue setting up the properties + //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()); - SkyCivModelObject convertedModel = modelObject.ToObject(); - convertedModel.LoadCombinations.Add("SW1 + LG1", "strength", @"{ 'SW1': 1, 'LG1': 1}"); + + //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(convertedModel, Formatting.Indented); + + 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 = "YOUR_API_USERNAME_HERE"; - auth.Key = "YOUR_API_KEY_HERE"; + auth.Username = "nilay.ram@skyciv.com"; + auth.Key = "v1tMCV5J4TQ5mEojrSN7N8fWNyRbfeNmwBBuax6JhTdU2udr4I4nhoAIxtMxIgLQ"; // making a request to start session, set and save model @@ -261,7 +275,7 @@ The recommended use of this package is by using the `SkyCivModelObject()` , `Sky request.options.ValidateInput = false; SkyCivAPIObject apiObject = new SkyCivAPIObject(); - request.options.Timeout = 2; + request.options.Timeout = 2 * 60 * 1000; var requestJson = JsonConvert.SerializeObject(request, Formatting.Indented); System.IO.File.WriteAllText(@"request.json", requestJson); @@ -283,7 +297,7 @@ The recommended use of this package is by using the `SkyCivModelObject()` , `Sky 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); @@ -308,6 +322,7 @@ The recommended use of this package is by using the `SkyCivModelObject()` , `Sky 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 @@ -337,3 +352,4 @@ The recommended use of this package is by using the `SkyCivModelObject()` , `Sky } } } + diff --git a/csharp/SkyCiv.csproj b/csharp/SkyCiv.csproj index 54b5df5..b0ae4bc 100644 --- a/csharp/SkyCiv.csproj +++ b/csharp/SkyCiv.csproj @@ -8,7 +8,7 @@ - + From 9ffc7f5365630ba88731ead59ce28c7aea1daa5b Mon Sep 17 00:00:00 2001 From: rnilay81 Date: Thu, 10 Aug 2023 17:38:08 +0530 Subject: [PATCH 7/7] Added the new way to add load combinations --- csharp/Program.cs | 22 ++++++++++++++++++---- csharp/SkyCiv.csproj | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/csharp/Program.cs b/csharp/Program.cs index fa75027..38fb8e6 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -182,16 +182,30 @@ public static void Main(string[] args) + //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}"); - //There are two approaches we can take from hereon.. The `modelObject` can be convereted again back to SkyCivModelObject as - //shown below 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()); + //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); diff --git a/csharp/SkyCiv.csproj b/csharp/SkyCiv.csproj index b0ae4bc..3239ee6 100644 --- a/csharp/SkyCiv.csproj +++ b/csharp/SkyCiv.csproj @@ -8,7 +8,7 @@ - +