I have also tried to add:
for (var i = 0; i < m_settings.Length; i ++)
{
DA.SetData(i, m_settings[i]);
}
but I am getting the error message on GH below:
algorithmic modeling for Rhino
Hi Guys,
Is there a simple method to separate the lines of a string similarly to what is describe here. The ini file that I am using already has separated lines but when importing it using the code below, it does not separate the lines with indices.
What kind of data is directly separated with indices by GH?
Many thanks,
Arthur
public void ShowSettingsGui()
{
var dialog = new OpenFileDialog { Filter = "Data Sources (*.ini)|*.ini*|All Files|*.*" };
if (dialog.ShowDialog() != DialogResult.OK) return;
m_settings = File.ReadAllText(dialog.FileName);
ExpireSolution(true);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
if (m_settings == null)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You must declare some valid settings");
return;
}
DA.SetData(0, m_settings);
}
Tags:
http://msdn.microsoft.com/en-us/library/system.string.split.aspx
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks a lot David, I have tried the code below and a simpler way using
m_settings = File.ReadAllLines(dialog.FileName); but I get
{0} 0. System.String[]as output of my component in both cases instead of the actual lines.
string m_settings_temp;
string[] m_settings;
public void ShowSettingsGui()
{
var dialog = new OpenFileDialog { Filter = "Data Sources (*.ini)|*.ini*|All Files|*.*" };
if (dialog.ShowDialog() != DialogResult.OK) return;m_settings_temp = File.ReadAllText(dialog.FileName);
m_settings = m_settings_temp.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
}protected override void SolveInstance(IGH_DataAccess DA)
{
if (m_settings == null)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You must declare some valid settings");
return;
}
DA.SetData(0, m_settings);
}
If it can help I get the following exception in VS:
System.Exception occurred
Message=Unknown file
Source=Grasshopper
StackTrace:
at Grasshopper.Global_Proc.ASSERT(Guid assert_id, String message, Exception exception) in C:\dev\Grasshopper\1.0\root\src\GH_GlobalProc.vb:line 98
InnerException:
m_settings is an array of strings, so you need to assign lists:
DA.SetDataList(0, m_settings);
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by