From 65d08556e38827ce7aa0274a82e7588b0a93755e Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Thu, 29 Sep 2022 13:46:15 +0200 Subject: [PATCH 1/4] fixed prop.material == null handling --- GsaGH/Parameters/GsaMaterial.cs | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/GsaGH/Parameters/GsaMaterial.cs b/GsaGH/Parameters/GsaMaterial.cs index d63f8e94d..51fcac75b 100644 --- a/GsaGH/Parameters/GsaMaterial.cs +++ b/GsaGH/Parameters/GsaMaterial.cs @@ -124,30 +124,42 @@ internal GsaMaterial(GsaSection section, AnalysisMaterial analysisMaterial = nul { if (section == null) { return; } if (section.API_Section == null) { return; } - if (analysisMaterial == null && section.Material.AnalysisMaterial != null) - analysisMaterial = section.Material.AnalysisMaterial; - else if (section.API_Section.MaterialAnalysisProperty > 0 && section.Material != null && analysisMaterial == null) - analysisMaterial = section.Material.AnalysisMaterial; + if (section.Material != null) + { + if (analysisMaterial == null && section.Material.AnalysisMaterial != null) + analysisMaterial = section.Material.AnalysisMaterial; + else if (section.API_Section.MaterialAnalysisProperty > 0 && section.Material != null && analysisMaterial == null) + analysisMaterial = section.Material.AnalysisMaterial; + } + CreateFromAPI(section.API_Section.MaterialType, section.API_Section.MaterialAnalysisProperty, section.API_Section.MaterialGradeProperty, analysisMaterial); } internal GsaMaterial(GsaProp2d prop, AnalysisMaterial analysisMaterial = null) { if (prop == null) { return; } if (prop.API_Prop2d == null) { return; } - if (analysisMaterial == null && prop.Material.AnalysisMaterial != null) - analysisMaterial = prop.Material.AnalysisMaterial; - else if (prop.API_Prop2d.MaterialAnalysisProperty > 0 && prop.Material != null && analysisMaterial == null) - analysisMaterial = prop.Material.AnalysisMaterial; + if (prop.Material != null) + { + if (analysisMaterial == null && prop.Material.AnalysisMaterial != null) + analysisMaterial = prop.Material.AnalysisMaterial; + else if (prop.API_Prop2d.MaterialAnalysisProperty > 0 && analysisMaterial == null) + analysisMaterial = prop.Material.AnalysisMaterial; + } + CreateFromAPI(prop.API_Prop2d.MaterialType, prop.API_Prop2d.MaterialAnalysisProperty, prop.API_Prop2d.MaterialGradeProperty, analysisMaterial); } internal GsaMaterial(GsaProp3d prop, AnalysisMaterial analysisMaterial = null) { if (prop == null) { return; } if (prop.API_Prop3d == null) { return; } - if (analysisMaterial == null && prop.Material.AnalysisMaterial != null) - analysisMaterial = prop.Material.AnalysisMaterial; - else if (prop.API_Prop3d.MaterialAnalysisProperty > 0 && prop.Material != null && analysisMaterial == null) - analysisMaterial = prop.Material.AnalysisMaterial; + + if (prop.Material != null) + { + if (analysisMaterial == null && prop.Material.AnalysisMaterial != null) + analysisMaterial = prop.Material.AnalysisMaterial; + else if (prop.API_Prop3d.MaterialAnalysisProperty > 0 && analysisMaterial == null) + analysisMaterial = prop.Material.AnalysisMaterial; + } CreateFromAPI(prop.API_Prop3d.MaterialType, prop.API_Prop3d.MaterialAnalysisProperty, prop.API_Prop3d.MaterialGradeProperty, analysisMaterial); } private void CreateFromAPI(MaterialType materialType, int analysisProp, int gradeProp, AnalysisMaterial analysisMaterial) From c73dbea913a24fe2877e8d4455eed56cf1eb5955 Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Thu, 29 Sep 2022 13:46:33 +0200 Subject: [PATCH 2/4] ignore test bin --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 22e1a237f..50c980cb3 100644 --- a/.gitignore +++ b/.gitignore @@ -354,3 +354,4 @@ dist/* /IntegrationTests/obj /GhSA/bin/x64/Release +/UnitTestGsaGH/bin/x64/Debug From af8b97062df1d881443bb1371747b008fe16c916 Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Thu, 29 Sep 2022 13:46:45 +0200 Subject: [PATCH 3/4] add gwa command component --- GsaGH/Components/0_Model/GwaModel.cs | 61 +++++++++++++++++++++++++ GsaGH/GsaGH.csproj | 8 ++++ GsaGH/Properties/Icons/GwaModel.png | Bin 0 -> 738 bytes GsaGH/Properties/Resources.Designer.cs | 10 ++++ GsaGH/Properties/Resources.resx | 3 ++ 5 files changed, 82 insertions(+) create mode 100644 GsaGH/Components/0_Model/GwaModel.cs create mode 100644 GsaGH/Properties/Icons/GwaModel.png diff --git a/GsaGH/Components/0_Model/GwaModel.cs b/GsaGH/Components/0_Model/GwaModel.cs new file mode 100644 index 000000000..18fe0793f --- /dev/null +++ b/GsaGH/Components/0_Model/GwaModel.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using Grasshopper.Kernel; +using GsaAPI; +using GsaGH.Parameters; + + +namespace GsaGH.Components +{ + /// + /// Component to retrieve non-geometric objects from a GSA model + /// + public class GwaModel : GH_OasysComponent + { + #region Name and Ribbon Layout + // This region handles how the component in displayed on the ribbon + // including name, exposure level and icon + public override Guid ComponentGuid => new Guid("6f701c53-1531-45ef-9842-9356da59b590"); + public GwaModel() + : base("Create GWA Model", "GWA", "Create a model from a GWA string.", + Ribbon.CategoryName.Name(), + Ribbon.SubCategoryName.Cat0()) + { this.Hidden = true; } // sets the initial state of the component to hidden + public override GH_Exposure Exposure => GH_Exposure.tertiary | GH_Exposure.obscure; + + protected override System.Drawing.Bitmap Icon => GsaGH.Properties.Resources.GwaModel; + #endregion + + #region Input and output + protected override void RegisterInputParams(GH_InputParamManager pManager) + { + pManager.AddTextParameter("GWA string", "GWA", "GWA string from GSA. Right-click on any data, and select copy all. Paste into notepad to check the data. \r\nThis input takes a a list of text strings that will automatically be joined. Construct a tree structure if you want to create multiple GSA files. \r\nThe syntax of the command is based on GWA syntax and the units follow the GWA unit syntax; –\r\nrefer to the “GSA Keywords” document for details", GH_ParamAccess.list); + } + + protected override void RegisterOutputParams(GH_OutputParamManager pManager) + { + pManager.AddParameter(new GsaModelParameter()); + } + #endregion + + protected override void SolveInstance(IGH_DataAccess DA) + { + Interop.Gsa_10_1.ComAuto m = new Interop.Gsa_10_1.ComAuto(); + m.NewFile(); + string gwa = ""; + List strings = new List(); + if (DA.GetDataList(0, strings)) + foreach (string s in strings) + gwa += s + "\n"; + + m.GwaCommand(gwa); + string temp = Path.GetTempPath() + Guid.NewGuid().ToString() + ".gwb"; + m.SaveAs(temp); + GsaModel gsaGH = new GsaModel(); + gsaGH.Model.Open(temp); + DA.SetData(0, gsaGH); + } + } +} diff --git a/GsaGH/GsaGH.csproj b/GsaGH/GsaGH.csproj index b1269b765..44c05819b 100644 --- a/GsaGH/GsaGH.csproj +++ b/GsaGH/GsaGH.csproj @@ -58,6 +58,10 @@ ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\GsaAPI.dll False + + ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\Interop.Gsa_10_1.dll + True + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -99,6 +103,7 @@ + @@ -641,6 +646,9 @@ + + +