簡體   English   中英

蚱hopper返回了“預期標識符”和“方法必須具有返回類型”

[英]Grasshopper returned '“identifier expected” and “method must have a return type”

我是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> 
}

將您的方法更改為

Patterning(List<Line>)

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

您的方法將返回類型為List<Line> patternLines

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM