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