Skip to content

Commit

Permalink
✨ extend results from bsc
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco-Pellegrino committed Oct 4, 2024
1 parent 8e9fb99 commit 4343168
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 10 deletions.
4 changes: 2 additions & 2 deletions FemDesign.Core/FemDesignConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ public List<T> GetResultsOnPoints<T>(List<CmdResultPoint> resultPoints, Results.
/// <param name="outputCsvPath"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public List<string> GetResultsFromBsc(string inputBscPath, string outputCsvPath = null)
public List<string> GetResultsFromBsc(string inputBscPath, string outputCsvPath = null, List<IStructureElement> element = null)
{
// Check input
if (outputCsvPath == null)
Expand All @@ -779,7 +779,7 @@ public List<string> GetResultsFromBsc(string inputBscPath, string outputCsvPath
throw new Exception("Extension output file must be .csv");

// Create .fdscript and list results
_listResultsByFdScript("GetResultsFromBsc", new List<string> { inputBscPath }, new List<string> { outputCsvPath });
_listResultsByFdScript("GetResultsFromBsc", new List<string> { inputBscPath }, new List<string> { outputCsvPath }, element);

// Read results
var results = System.IO.File.ReadAllLines(outputCsvPath, System.Text.Encoding.UTF8).Select(x => x.Replace("\t", ",")).ToList();
Expand Down
3 changes: 2 additions & 1 deletion FemDesign.Grasshopper/FemDesign.Grasshopper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@
<Compile Include="Pipe\PipeOpen.cs" />
<Compile Include="Pipe\PipeReadEigenFrequencyResults.cs" />
<Compile Include="Pipe\PipeReadStabilityResults.cs" />
<Compile Include="Pipe\PipeResultFromBsc.cs" />
<Compile Include="Pipe\PipeSetCfg.cs" />
<Compile Include="Pipe\OBSOLETE\PipeSetGlobalCfg_OBSOLETE2306.cs" />
<Compile Include="Pipe\WIP_PipeReadStabilityResults.cs" />
<Compile Include="Pipe\PipeReadCaseCombResults.cs" />
<Compile Include="Pipe\PipeResultFromBsc.cs" />
<Compile Include="Pipe\OBSOLETE\PipeResultFromBsc_OBSOLETE.cs" />
<Compile Include="Pipe\PipeRunAnalysis.cs" />
<Compile Include="Bars\StiffnessModifierBar.cs" />
<Compile Include="Bars\Truss.cs" />
Expand Down
147 changes: 147 additions & 0 deletions FemDesign.Grasshopper/Pipe/OBSOLETE/PipeResultFromBsc_OBSOLETE.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// https://strusoft.com/
using System;
using System.Collections.Generic;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using System.Linq;
using System.Windows.Forms;
using System.Reflection;
using GrasshopperAsyncComponent;
using FemDesign;
using FemDesign.Calculate;
using Grasshopper.Documentation;

namespace FemDesign.Grasshopper
{
public class PipeResultFromBsc_OBSOLETE : GH_AsyncComponent
{
public PipeResultFromBsc_OBSOLETE() : base(" FEM-Design.GetResultFromBsc", "ResultFromBsc", "Extract results from a model with a .bsc file", CategoryName.Name(), SubCategoryName.Cat8())
{
BaseWorker = new ApplicationResultFromBsc_OBSOLETE(this);
}
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Connection", "Connection", "FEM-Design connection.", GH_ParamAccess.item);
pManager.AddTextParameter("BscFilePath", "BscFilePath", "File path to .bsc batch-file.", GH_ParamAccess.list);
pManager.AddTextParameter("CsvFilePath", "CsvFilePath", "Specify where the .csv will be saved. If not specified, the results will be saved in the same folder of the .bsc file.", GH_ParamAccess.list);
pManager[pManager.ParamCount - 1].Optional = true;
pManager.AddBooleanParameter("RunNode", "RunNode", "If true node will execute. If false node will not execute.", GH_ParamAccess.item, true);
pManager[pManager.ParamCount - 1].Optional = true;
}
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Connection", "Connection", "FEM-Design connection.", GH_ParamAccess.item);
pManager.AddTextParameter("Results", "Results", "", GH_ParamAccess.tree);
pManager.AddBooleanParameter("Success", "Success", "True if session has exited. False if session is open or was closed manually.", GH_ParamAccess.item);
}

protected override System.Drawing.Bitmap Icon => FemDesign.Properties.Resources.FEM_readresult;

public override Guid ComponentGuid => new Guid("{E7EEAC5F-4C80-40D3-AA16-C2E6E3BD62BC}");
public override GH_Exposure Exposure => GH_Exposure.hidden;
private class ApplicationResultFromBsc_OBSOLETE : WorkerInstance
{
public FemDesignConnection _connection = null;

private List<string> bscPath = new List<string>();
private List<string> csvPath = new List<string>();

private DataTree<object> _results = new DataTree<object>();
private bool _runNode = true;
private bool _success = false;

public ApplicationResultFromBsc_OBSOLETE(GH_Component component) : base(component) { }

public override void DoWork(Action<string, string> ReportProgress, Action Done)
{

try
{
if (_runNode == false)
{
_success = false;
_connection = null;
RuntimeMessages.Add((GH_RuntimeMessageLevel.Warning, "Run node set to false."));
Done();
return;
}

if (_connection == null)
{
RuntimeMessages.Add((GH_RuntimeMessageLevel.Warning, "Connection is null."));
Done();
return;
}

if (_connection.IsDisconnected)
{
_success = false;
_connection = null;
throw new Exception("Connection to FEM-Design have been lost.");
}

if (_connection.HasExited)
{
_success = false;
_connection = null;
throw new Exception("FEM-Design have been closed.");
}

ReportProgress("", "");

var results = bscPath.Zip(csvPath, (bsc, csv) => _connection.GetResultsFromBsc(bsc, csv) );

int i = 0;
foreach( var result in results)
{
_results.AddRange(result, new GH_Path(i));
i++;
}
_success = true;
}
catch (Exception ex)
{
RuntimeMessages.Add((GH_RuntimeMessageLevel.Error, ex.Message));
_success = false;
_connection = null;
}

Done();

}

public override WorkerInstance Duplicate() => new ApplicationResultFromBsc_OBSOLETE(Parent);

public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
{
if (!DA.GetData("Connection", ref _connection)) return;
DA.GetDataList("BscFilePath", bscPath);
if(!DA.GetDataList("CsvFilePath", csvPath))
{
foreach(var bsc in bscPath)
{
csvPath.Add(System.IO.Path.ChangeExtension(bsc, "csv"));
}
};



DA.GetData("RunNode", ref _runNode);
}

public override void SetData(IGH_DataAccess DA)
{
foreach (var (level, message) in RuntimeMessages)
{
Parent.AddRuntimeMessage(level, message);
}

DA.SetData("Connection", _connection);
DA.SetDataTree(1, _results);
DA.SetData("Success", _success);
}
}
}

}
17 changes: 10 additions & 7 deletions FemDesign.Grasshopper/Pipe/PipeResultFromBsc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ protected override void RegisterInputParams(GH_InputParamManager pManager)
pManager.AddTextParameter("BscFilePath", "BscFilePath", "File path to .bsc batch-file.", GH_ParamAccess.list);
pManager.AddTextParameter("CsvFilePath", "CsvFilePath", "Specify where the .csv will be saved. If not specified, the results will be saved in the same folder of the .bsc file.", GH_ParamAccess.list);
pManager[pManager.ParamCount - 1].Optional = true;
pManager.AddGenericParameter("Elements", "Elements", "Elements for which the results will be return. Default will return the values for all elements.", GH_ParamAccess.list);
pManager[pManager.ParamCount - 1].Optional = true;
pManager.AddBooleanParameter("RunNode", "RunNode", "If true node will execute. If false node will not execute.", GH_ParamAccess.item, true);
pManager[pManager.ParamCount - 1].Optional = true;
}
Expand All @@ -38,7 +40,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager)

protected override System.Drawing.Bitmap Icon => FemDesign.Properties.Resources.FEM_readresult;

public override Guid ComponentGuid => new Guid("{E7EEAC5F-4C80-40D3-AA16-C2E6E3BD62BC}");
public override Guid ComponentGuid => new Guid("{6A88FF5F-BC25-45D2-8140-385A652D30FE}");
public override GH_Exposure Exposure => GH_Exposure.tertiary;
private class ApplicationResultFromBsc : WorkerInstance
{
Expand All @@ -47,6 +49,8 @@ private class ApplicationResultFromBsc : WorkerInstance
private List<string> bscPath = new List<string>();
private List<string> csvPath = new List<string>();

private List<FemDesign.GenericClasses.IStructureElement> _elements = new List<GenericClasses.IStructureElement>();

private DataTree<object> _results = new DataTree<object>();
private bool _runNode = true;
private bool _success = false;
Expand Down Expand Up @@ -90,10 +94,10 @@ public override void DoWork(Action<string, string> ReportProgress, Action Done)

ReportProgress("", "");

var results = bscPath.Zip(csvPath, (bsc, csv) => _connection.GetResultsFromBsc(bsc, csv) );
var results = bscPath.Zip(csvPath, (bsc, csv) => _connection.GetResultsFromBsc(bsc, csv, _elements));

int i = 0;
foreach( var result in results)
foreach (var result in results)
{
_results.AddRange(result, new GH_Path(i));
i++;
Expand All @@ -117,16 +121,15 @@ public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
{
if (!DA.GetData("Connection", ref _connection)) return;
DA.GetDataList("BscFilePath", bscPath);
if(!DA.GetDataList("CsvFilePath", csvPath))
if (!DA.GetDataList("CsvFilePath", csvPath))
{
foreach(var bsc in bscPath)
foreach (var bsc in bscPath)
{
csvPath.Add(System.IO.Path.ChangeExtension(bsc, "csv"));
}
};



DA.GetDataList("Elements", _elements);
DA.GetData("RunNode", ref _runNode);
}

Expand Down

0 comments on commit 4343168

Please sign in to comment.