C#:输出参数索引[i]对于组件来说太高或太低 [英] C#: Output Parameter Index[i] too high or too low for Component

查看:116
本文介绍了C#:输出参数索引[i]对于组件来说太高或太低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行以下代码时,出现以下错误消息:

The following error message appears when running the code below:

c#:输出参数索引[1]对于组件来说太高或太低.

c#: Output Parameter Index[1] too high or too low for Component.

IGH_DataAccess已经在说明获取当前迭代计数" 的帮助中提供了迭代计数.在解决方案中第一次在组件上调用SolveInstance()函数时,迭代计数器将为零.以后每次通话时,它都会加一.使用DA.SetData(0, m_settings[0]);时,它确实显示第一行.

The IGH_DataAccess is already providing an iteration count in the help it says "Gets the current iteration count". The first time the SolveInstance() function is called on a component during a solution the Iteration counter will be zero. It will be incremented by one for every subsequent call. When using DA.SetData(0, m_settings[0]); it does show the first line.

错误消息出现在所用程序中,并且在DA.SetData(i, m_settings[i]);上出现以下异常:

The error message appears in the program used and I get the following exception on 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:

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:

以下是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.

Herafter is the description of the IGH_DataAccess.SetData Method: 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]);时,第一行的字符会被拆分,而我希望每一行都将被拆分.

When changing the code to DA.SetDataList(i, m_settings[i]); the characters of the first line get split while I want every line to get split.

我在做什么错了?

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]);
    }
}

提前谢谢!

推荐答案

此问题通过使用以下代码解决,将SetData替换为SetDatalist,且不使用循环,也使用其他拆分字符串的方法:

This was solved by using the following code, replacing the SetData by SetDatalist with no loop and a different way of splitting the strings:

  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);
                ExpireSolution(true);
            }



            protected override void SolveInstance(IGH_DataAccess DA)
            {
                if (m_settings == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You must declare some valid settings");
                    return;
                }

                else

                {  
                        DA.SetDataList(0, m_settings);
                }  

            }

这篇关于C#:输出参数索引[i]对于组件来说太高或太低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆