Finding arc properties C#

I’m very new to c# scripting. I don’t find how to get the radius of an arc (or where to get the c# method for that…), I’m able to get the lenght, the start and end points, but not the radius…
my definition:
curves (6.9 KB)

I’d like to include this radius information through an “if the curve is an arc, get his radius…” loop

If( data[i] is Arc)
     Arc arc = data[i] as Arc;
     double r = arc.Radius;

   \\\ Do other stuff


Ps: The RhinoCommon docs are your friend and the C# docs by Microsoft are your best friend

Thank you.
My problem isn’t in the loops yet,
but when in the C# editor, I type “double r= myCurves.” the “radius” function doesn’t appear as does “lenght” or “PointAtStart”.
then an error “CS1061” appears. I added “using” at the beginning a bit randomly, but that doesn’t work either.
curves (5.7 KB)

Forgot, Arc is s struct so the as keyword will not work. Check this out. Make sure, in the future when you are operating on a List you set the input to be of type List and not item

Again, RhinoCommon is your friend:

 private void RunScript(List<Curve> x, ref object A)

    int arcCount = 0;
    for (int i = 0; i < x.Count; i++)
        Arc arc;
        if(x[i].TryGetArc(out arc))
          Print(string.Format("Arc: {0}, Radis = {1}", arcCount, Math.Round(arc.Radius, 3)));


      if (x[i].IsLinear())
        // Do stuff.



You might want to put your code in to a method, so its more organized and modular.

As I’m an apprentice in this skill, I’m already trying to do it in “item access” mode to understand. I’m trying to get used to the syntax…
I’ve adapted your script in “item access”, it works.
Even if I have good friends in rhinocommon, they are not easy to find!
Thanks again for your help :+1:

Yeah, but by doing that, its not correct. If you were coding in an other IDE like Visual Studio, you would get a compile time error because a List does not contain a method called IsArc() The McNeel guys were probably nice, and maybe did some exception handling to prevent this error from throwing to the user in the C# script component editor. Also, the component will be messed up with its expire solution routine when its access type is set to item, although it is given a list, it will probably expire itself many more times than just once.

Long story short, start acquiring proper programming practices from the beginning before its to late. And try to learn the basics of programming, such as OOP, methods, variable types, etc. Before rushing and trying to code without really knowing why things work the way they do, or why RhinoCommon was designed the way it is. It will really pay off down the road if you are really serious about learning, and its not just a sunday funday thing or an occasional follow along Garcia Del Castillo’s new YouTube tutorials.

Thanks for the advice, it’s true that at the moment I’m a little Sunday programmer… Actually I have no pretention to become a C# guru!
I managed to achieve my “programming” goals by using the basic components of grasshopper. I simply aspire to make my tools evolve, because I realize that this C# programming is much faster.
I was thinking that the C# editor of Grasshopper was simpler (and generates immediate satisfaction) to understand the basics of programming than Visual Studio, which is installed on my PC and to which I have already been initiated.
I understood your remark and I will try to reason in “lists” mode, since it is on this mode that I will work anyway when the time comes. So, what is your opinion about the “tree access” mode? At first glance, doesn’t it seem to simplify the work?
To start I use this tutorial: Essential Guide to C# Scripting for Grasshopper