运行以下代码时出现以下错误消息:
c#: 组件的输出参数索引[1] 太高或太低。
IGH_DataAccess
已经在“获取当前迭代计数”的帮助中提供了迭代计数。在解决方案期间第一次在SolveInstance()
组件上调用该函数时,迭代计数器将为零。每次后续调用它都会加一。使用DA.SetData(0, m_settings[0]);
时确实显示第一行。
错误消息出现在使用的程序中,我得到以下异常DA.SetData(i, m_settings[i]);
:
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:
Herafter 是 IGH_DataAccess.SetData 方法的描述:Stores data in an output parameter during GH_Component.SolveInstance(). Use this function only for setting individual data items. If you want to set lists of data, you *must* call SetDataList() instead.
将代码更改为DA.SetDataList(i, m_settings[i]);
第一行的字符时会被拆分,而我希望每一行都被拆分。
我究竟做错了什么?
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 = File.ReadAllLines(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;
}
for (var i = 0; i < m_settings.Length; i++)
{
DA.SetData(i, m_settings[i]);
}
}
提前致谢!