Skip to content

Commit

Permalink
🐛 GlobConfig objects as input parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lorinczandrea committed Oct 9, 2024
1 parent d26469b commit ea1d787
Show file tree
Hide file tree
Showing 3 changed files with 380 additions and 6 deletions.
38 changes: 32 additions & 6 deletions FemDesign.Grasshopper/Calculate/ApplicationRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager)
pManager.AddGenericParameter("Config", "Config", "Filepath of the configuration file or Config objects.\nIf file path is not provided, the component will read the cfg.xml file in the package manager library folder.\n%AppData%\\McNeel\\Rhinoceros\\packages\\7.0\\FemDesign\\", GH_ParamAccess.list);
pManager[pManager.ParamCount - 1].Optional = true;

pManager.AddTextParameter("GlobalConfig", "GlobalConfig", "GlobalCfg file path. You can use the 'cmdglobalcfg.xml' file in located package manager library folder as a starting point.\n%AppData%\\McNeel\\Rhinoceros\\packages\\7.0\\FemDesign\\", GH_ParamAccess.item);
pManager.AddGenericParameter("GlobalConfig", "GlobalConfig", "Filepath of the global configuration file or GlobConfig objects.\nIf file path is not provided, the component will read the cmdglobalcfg.xml file in the package manager library folder.\n%AppData%\\McNeel\\Rhinoceros\\packages\\7.0\\FemDesign\\", GH_ParamAccess.list);
pManager[pManager.ParamCount - 1].Optional = true;

pManager.AddTextParameter("DocxTemplatePath", "DocxTemplatePath", "File path to documentation template file (.dsc). The documentation will be saved in the `FEM-Design API` folder. Optional parameter.", GH_ParamAccess.item);
Expand Down Expand Up @@ -171,8 +171,8 @@ protected override void SolveInstance(IGH_DataAccess DA)
List<dynamic> cfg = new List<dynamic>();
DA.GetDataList("Config", cfg);

string globalCfg = null;
DA.GetData("GlobalConfig", ref globalCfg);
List<dynamic> globalCfg = new List<dynamic>();
DA.GetDataList("GlobalConfig", globalCfg);

string dscTemplate = null;
DA.GetData("DocxTemplatePath", ref dscTemplate);
Expand Down Expand Up @@ -239,9 +239,35 @@ protected override void SolveInstance(IGH_DataAccess DA)
}
}
}
else
{
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
var _cfgfilePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(assemblyLocation), @"cfg.xml");
connection.SetConfig(_cfgfilePath);
}

if (globalCfg != null)
connection.SetGlobalConfig(CmdGlobalCfg.DeserializeCmdGlobalCfgFromFilePath(globalCfg));
if (globalCfg.Count != 0)
{
foreach (var config in globalCfg)
{
// Check if the value is a string
if (config.Value is string filePath)
{
connection.SetGlobalConfig(filePath);
}
// Check if the value is of type FemDesign.Calculate.CONFIG
else if (config.Value is FemDesign.Calculate.GlobConfig globConfig)
{
connection.SetGlobalConfig(globConfig);
}
}
}
else
{
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
var _globCfgfilePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(assemblyLocation), @"cmdglobalcfg.xml");
connection.SetConfig(_globCfgfilePath);
}

if (analysis != null)
connection.RunAnalysis(analysis);
Expand Down Expand Up @@ -338,7 +364,7 @@ protected override System.Drawing.Bitmap Icon
}
public override Guid ComponentGuid
{
get { return new Guid("{3BF26144-8F6A-46F3-A826-070A2B43D2A2}"); }
get { return new Guid("{D8FB0474-D57A-4DFC-80E3-2D1D0F5D2FD4}"); }
}

public override GH_Exposure Exposure => GH_Exposure.primary;
Expand Down
Loading

0 comments on commit ea1d787

Please sign in to comment.