Grasshopper返回'“标识符预期”和“方法必须有返回类型”

时间:2018-02-03 03:46:14

标签: c# grasshopper

我对C#很新,或者至少,当我涉足它时,它已经有一段时间了。在88号线附近,我不断收到标题中所述的错误。我真的不确定,我不太了解编码,只是事情的逻辑。 它适用于第二部分,我不知道为什么我的回报会给我错误。当我查看本网站上的其他解决方案时,它主要是因为这是一个大写等问题,而且我试着玩弄它无济于事......

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(double div, double rad, bool boolt, ref object Geometry)
  {
    var geometry = new List<object>();
    var pattlines = new List<Line>();
    var tri = Tri(rad, boolt);
    Line[] tr = tri.GetSegments(); // array creation, data structure functions similar to dict
    pattlines.Add(tr[0]);
    pattlines.Add(tr[1]);
    pattlines.Add(tr[2]);

    var gm = new List<Polyline>();
    int i = 0;
    while(i < div){
      gm.AddRange(pattlines);
      pattlines.AddRange(Patterning(gm));
      i++;
    }
    Geometry = pattlines;
  }

  Patterning(List<Line>)
  {
    var patternLines = new List<Line>();
    foreach(Line l in pattlines){
      double le = l.Length;
      Point3d pS = l.PointAt(0.0);
      Point3d p0 = l.PointAt(1 / 3);
      Point3d p1 = l.PointAt(2 / 3);
      Point3d pE = l.PointAt(1.0);

      var rotate = new Line(p0, p1);
      rotate.Transform(Rhino.Geometry.Transform.Rotation(Math.PI / 3, p0));
      Point3d tip = rotate.PointAt(1.0);
      var line0 = new Line(tip, p1);
      var line1 = new Line(pS, p0);
      var line2 = new Line(p1, pE);

      patternLines.Add(line0);
      patternLines.Add(line1);
      patternLines.Add(line2);

    }
    return patternLines;
  }

  Polyline Tri(double rad, bool boolt)
  {
    var a0 = 0;
    var a1 = a0 + Math.PI * 2 / 3;
    var a2 = a1 + Math.PI * 2 / 3;
    var p0 = new Point3d(Math.Cos(a0), Math.Sin(a0), 0);
    var p1 = new Point3d(Math.Cos(a1), Math.Sin(a1), 0);
    var p2 = new Point3d(Math.Cos(a2), Math.Sin(a2), 0);

    var tripl = new Polyline();
    tripl.Add(p0);
    tripl.Add(p1);
    tripl.Add(p2);
    tripl.Add(p0);

    if (boolt == true){
      tripl.Reverse();
    }

    return tripl;


  }

  // <Custom additional code> 

  // </Custom additional code> 
}

1 个答案:

答案 0 :(得分:0)

将您的方法更改为

Patterning(List<Line>)

private List<Line> Patterning(List<Line>)

您的方法返回的类型为 List<Line>

的patternLines