C# Grasshopper / Rhino 7 / Error(CS1518)

Hi,

I get an error when I am trying to run the following c# in Grasshopper:

for (int j = 0; j < iterationCount; j++)
{
  List<Point3d> newControlPoints = new List<Point3d>();

  for (int i = 0; i < controlPoints.Count - 1; i++)
  {
    Point3d oneQuarterPoint = 0.75 * controlPoints[i] + 0.25 * controlPoints[i + 1];
    newControlPoints.Add(oneQuarterPoint);

    Point3d threeQuarterPoint = 0.25 * controlPoints[i] + 0.75 * controlPoints[i + 1];
    newControlPoints.Add(threeQuarterPoint);
  }

  controlPoints = newControlPoints;
}

curve = new PolylineCurve(controlPoints);

}

Iā€™ve already added assemblies like it was suggested in this post:

But it didnā€™t helpā€¦

What should I do to run this code?

The code is from this youtube lesson:

Here are some screenshots:

Thanks in advance!

The error sounds like you have a typo somewhere.

It is going hard to say where when there is not enough to go on. It would be more useful to see the grasshopper definition instead of just the small code snippet (that on a quick glance looks fine)

yes. the code doesnā€™t require any additional assemblies so you donā€™t need to worry about them.
it looks like a very simple error that involves misunderstanding of the basic syntax of C#.

giving us a screenshot of whatā€™s happening inside the C# snippet would be nice. What you posted here has no error, but you might have forgotten to set input typesā€¦ or misplaced the code inside the snippet.

Maybe you want this?

Curve_Add_GCPoints_V1.gh (7.9 KB)

Here is my definition.

Some c# Scripts are working, some of them notā€¦

test.gh (12.5 KB)
test.3dm (31.3 KB)

Here is a screenshot of the code.
In Errors Messages there are some problems with lines: 82, 83 ā€¦ 88, 106, 108, 109
But I canā€™t see these lines in the code

P.S. This is an another code, but problems are the same

You canā€™t put a function inside a function like that. Your component wants you to implement inside the RunScript function. It takes a Curve and a double, and expects an object reference out.

If you want to have a Curve, three doubles, then you must add that to the component inputs.

Also, you should remove all the assembly references. Most of the DLLs you added are not .NET assemblies, but regular DLLs. You should not need to add any of those.

1 Like

Hi,
your error is very obvious.
you cannot define a method while defining a RunScript Method. Thatā€™s just how C# syntax works.
put the method definition in the Custom Additional Code.

Remember this order when writing C#, Namespace ā†’ Class ā†’ Properties ā†’ Method.

  • Namespace is what you called assemblies. we call these assemblies/libraries at the beginning of the code using ā€œusingā€ (e.g. using System.IO ; )

  • Here in the Snippet you see public class Script_Instance : GH_ScriptInstance. It means the code is trying to define a class inheriting from the GH_ScriptInstance class.

  • Then you see the private void RunScript() {} This is the Method that C# is trying to run with. This is where you define what to do.

*if you want to define additional Properties/Parameters or supplementary Methods, Donā€™t do it inside RunScript(). Do it in the Custom Additional code.

At first it sounds confusing. But once you do more, you understand how the Syntax works. Just like Grammar.

2 Likes

@Wiley @nathanletwory
Thank you for explanation - itā€™s helpful to know for the future scripts.

Here is the solution - Iā€™ve found working files from this workshop, maybe theyā€™ll be helpful for someone who will get the same errors.

1 Like

Thank you! Itā€™s not what I needed, but Iā€™ve learned some things from your script