错误(CS1513):}预期(第163行) [英] Error (CS1513): } expected (line 163)

查看:76
本文介绍了错误(CS1513):}预期(第163行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回上述错误的蚱蜢代码。我无法在代码中看到错误,并且想知道,任何人都可以提供帮助吗?

I have a grasshopper code that returns the above error. I cannot see the error in the code, and wonder, can anyone help?

第163行是代码部分后面的第二个}; //如果重置为真,则清除显示...  

Line 163 is the second } that follows the section of code; //clear display if reset is true... 

clr_f_rgb.Clear();

clr_f_rgb.Clear () ;

}

}

谢谢

using Rhino;
using Rhino.Geometry;
using Rhino.DocObjects;
using Rhino.Collections;

using GH_IO;
using GH_IO.Serialization;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Linq;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Runtime.InteropServices;



/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
{
#region Utility functions
  /// <summary>Print a String to the [Out] Parameter of the Script component.</summary>
  /// <param name="text">String to print.</param>
  private void Print(string text) { /* Implementation hidden. */ }
  /// <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
  /// <param name="format">String format.</param>
  /// <param name="args">Formatting parameters.</param>
  private void Print(string format, params object[] args) { /* Implementation hidden. */ }
  /// <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj) { /* Implementation hidden. */ }
  /// <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj, string method_name) { /* Implementation hidden. */ }
#endregion

#region Members
  /// <summary>Gets the current Rhino document.</summary>
  private readonly RhinoDoc RhinoDocument;
  /// <summary>Gets the Grasshopper document that owns this script.</summary>
  private readonly GH_Document GrasshopperDocument;
  /// <summary>Gets the Grasshopper script component that owns this script.</summary>
  private readonly IGH_Component Component;
  /// <summary>
  /// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
  /// Any subsequent call within the same solution will increment the Iteration count.
  /// </summary>
  private readonly int Iteration;
#endregion

  /// <summary>
  /// This procedure contains the user code. Input parameters are provided as regular arguments,
  /// Output parameters as ref arguments. You don't have to assign output parameters,
  /// they will have a default value.
  /// </summary>
  private void RunScript(object pts_r, object pts_l, object pts_h, object x, object clr_r, object clr_l, object clr_h, object y, object rst, ref object A)
  {
    int linewidth = 3;
    {
      //clear the display conduit
      if(m_display_left != null){
        m_display_left.Clear();
        m_display_left.Dispose();
        m_display_left = null;
      }
      {
        if(m_display_right != null){
          m_display_right.Clear();
          m_display_right.Dispose();
          m_display_right = null;
        }
        {
          if(m_display_head != null){
            m_display_head.Clear();
            m_display_head.Dispose();
            m_display_head = null;
          }
          {
            if(m_display_fourth != null){
              m_display_fourth.Clear();
              m_display_fourth.Dispose();
              m_display_fourth = null;
            }
            //instantiate new display conduit
            m_display_left = new Rhino.Display.CustomDisplay(true);
            m_display_right = new Rhino.Display.CustomDisplay(true);
            m_display_head = new Rhino.Display.CustomDisplay(true);
            m_display_fourth = new Rhino.Display.CustomDisplay(true);

            //generate color lists
            GetColorStep_right(clr_r, pts_r.Count);
            GetColorStep_left(clr_l, pts_l.Count);
            GetColorStep_head(clr_h, pts_h.Count);
            GetColorStep_fourth(clr_f, pts_f.Count);

            //generate the display for left hand
            int i = 0;
            if(pts_l.Count > 2){
              for(i = 1; i < pts_l.Count; ++i){
                Line ln = new Line(pts_l[i], pts_l[i - 1]);
                m_display_left.AddLine(ln, clr_l_rgb[pts_l.Count - i - 1], linewidth);
              }
            }

            //generate the display for right hand
            int j = 0;
            if(pts_r.Count > 2){
              for(j = 1; j < pts_r.Count; ++j){
                Line ln = new Line(pts_r[j], pts_r[j - 1]);
                m_display_right.AddLine(ln, clr_r_rgb[pts_r.Count - j - 1], linewidth);
              }
            }

            //generate the display for head
            int k = 0;
            if(pts_h.Count > 2){
              for(k = 1; k < pts_h.Count; ++k){
                Line ln = new Line(pts_h[k], pts_h[k - 1]);
                m_display_head.AddLine(ln, clr_h_rgb[pts_h.Count - k - 1], linewidth);
              }
            }

            //generate the display for fourth
            int l = 0;
            if(pts_f.Count > 2){
              for(l = 1; l < pts_f.Count; ++l){
                Line ln = new Line(pts_h[l], pts_h[l - 1]);
                m_display_fourth.AddLine(ln, clr_f_rgb[pts_f.Count - l - 1], linewidth);
              }
            }

            //clear display if reset is true
            if(rst){
              m_display_left.Clear();
              m_display_left.Dispose();
              m_display_left = null;
              m_display_right.Clear();
              m_display_right.Dispose();
              m_display_right = null;
              m_display_head.Clear();
              m_display_head.Dispose();
              m_display_head = null;
              m_display_fourth.Clear();
              m_display_fourth.Dispose();
              m_display_fourth = null;
              clr_l_rgb.Clear();
              clr_r_rgb.Clear();
              clr_h_rgb.Clear();
              clr_f_rgb.Clear();
            }
  }

  // <Custom additional code> 

          public static Rhino.Display.CustomDisplay m_display_left = null;
          public static Rhino.Display.CustomDisplay m_display_right = null;
          public static Rhino.Display.CustomDisplay m_display_head = null;
          public static Rhino.Display.CustomDisplay m_display_fourth = null;
          public int clr_r_red = 0;
          public int clr_r_grn = 0;
          public int clr_r_blu = 0;
          public int clr_l_red = 0;
          public int clr_l_grn = 0;
          public int clr_l_blu = 0;
          public int clr_h_red = 0;
          public int clr_h_grn = 0;
          public int clr_h_blu = 0;
          public int clr_f_red = 0;
          public int clr_f_grn = 0;
          public int clr_f_blu = 0;
          public List<Color> clr_l_rgb = new List<Color>();
          public List<Color> clr_r_rgb = new List<Color>();
          public List<Color> clr_h_rgb = new List<Color>();
          public List<Color> clr_f_rgb = new List<Color>();


          public void GetColorStep_Right(Color clr, int cnt){

            clr_r_rgb.Clear();

            //get color step values
            int dtr = (255 - clr.R) / cnt;
            int dtg = (255 - clr.G) / cnt;
            int dtb = (255 - clr.B) / cnt;

            int i = 0;
            for(i = 0;i < cnt;i++){
              clr_r_red = clr.R + (dtr * i);
              clr_r_grn = clr.G + (dtg * i);
              clr_r_blu = clr.B + (dtb * i);
              clr_r_rgb.Add(Color.FromArgb(clr_r_red, clr_r_grn, clr_r_blu));
            }
          }

          public void GetColorStep_Left(Color clr, int cnt){

            clr_l_rgb.Clear();

            //get color step values
            int dtr = (255 - clr.R) / cnt;
            int dtg = (255 - clr.G) / cnt;
            int dtb = (255 - clr.B) / cnt;

            int i = 0;
            for(i = 0;i < cnt;i++){
              clr_l_red = clr.R + (dtr * i);
              clr_l_grn = clr.G + (dtg * i);
              clr_l_blu = clr.B + (dtb * i);
              clr_l_rgb.Add(Color.FromArgb(clr_l_red, clr_l_grn, clr_l_blu));
            }
          }
          public void GetColorStep_head(Color clr, int cnt){

            clr_h_rgb.Clear();

            //get color step values
            int dtr = (255 - clr.R) / cnt;
            int dtg = (255 - clr.G) / cnt;
            int dtb = (255 - clr.B) / cnt;

            int i = 0;
            for(i = 0;i < cnt;i++){
              clr_h_red = clr.R + (dtr * i);
              clr_h_grn = clr.G + (dtg * i);
              clr_h_blu = clr.B + (dtb * i);
              clr_h_rgb.Add(Color.FromArgb(clr_h_red, clr_h_grn, clr_h_blu));
            }
          }
          public void GetColorStep_fourth(Color clr, int cnt){

            clr_f_rgb.Clear();

            //get color step values
            int dtr = (255 - clr.R) / cnt;
            int dtg = (255 - clr.G) / cnt;
            int dtb = (255 - clr.B) / cnt;

            int i = 0;
            for(i = 0;i < cnt;i++){
              clr_f_red = clr.R + (dtr * i);
              clr_f_grn = clr.G + (dtg * i);
              clr_f_blu = clr.B + (dtb * i);
              clr_f_rgb.Add(Color.FromArgb(clr_f_red, clr_f_grn, clr_f_blu));
            }
          }


  // </Custom additional code> 
}




推荐答案

它给你的线路可能会产生误导,因为Visual Studio试图匹配大括号并在它确定它们不匹配之前就已经到了那里。

The line its giving you is probably misleading, because Visual Studio is trying to match up curly brackets and gets as far as there before it decides they just aren't matching up.

你似乎在你的内容中有很多额外的括号码。 E.g

You seem to have a lot of extraneous brackets further up in your code. E.g

 int linewidth = 3;
    {
      //clear the display conduit
      if(m_display_left != null){
        m_display_left.Clear();
        m_display_left.Dispose();
        m_display_left = null;
      }  // ???????????
      {
        if(m_display_right != null){
          m_display_right.Clear();
          m_display_right.Dispose();
          m_display_right = null;
        } // ???????????
        {
          if(m_display_head != null){
            m_display_head.Clear();
            m_display_head.Dispose();
            m_display_head = null;
          }

//   etc

这没有多大意义。您是否尝试在此处进行if / else测试并错过'else'关键字?

This doesn't make a lot of sense. Are you trying to do if/else tests here and missing out the 'else' keyword?

我认为您应该从脚本顶部开始工作并确保正常工作,确保您拥有正确的大括号和'if'语句等语法。

I think you should start at the top of your script and work down, ensuring you have the correct syntax with respect to curly brackets and your 'if' statements etc.


这篇关于错误(CS1513):}预期(第163行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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