Rhinoscript Sintax

Hello I am using rs inside c#:

        var rhinoscript_object = RhinoApp.GetPlugInObject("RhinoScript");
        var rs = (IRhinoScript)rhinoscript_object;

        var new_part = rs.GetObject("Selecionar a peça Nova", 8):

        var new_part_corece = rs.coercegeometry(new_part);

coercegeometry function work well on Python editor, but on C# coercegeometry function
dont exist?

How can I get the coercegeometry with c# an use with rhinoscript_object?


there is absolutely no reason to use rs within C#. Rs is only a wrapper around Rhinocommon to simplify using a C# library with Python syntax.

Here is an “Get Object” example for C# using Rhinocommon directly:

Curve[] curves = null;
using (var go = new Rhino.Input.Custom.GetObject())

  go.SetCommandPrompt("Select curves");
  go.GeometryFilter = ObjectType.Curve;
  go.GetMultiple(0, 0);

  if (go.CommandResult() != Rhino.Commands.Result.Success)
    throw new Exception("Failed for unknown reasons");

  curves = new Curve[go.ObjectCount];
  for (int i = 0; i < curves.Length; i++)
    curves[i] = go.Object(i).Curve();
A = curves;

Don’t know if this the best in doing things but you get the point :slight_smile:

Thank you,

I understand what you say.

But my reason is, for me is better use the Python Syntax, less code for the same
propose, and I very accustomed use to python, in addition I have many scrits in python that I am introducing in a plugin in C # with some dock forms.

I start to trying understand the c# way to get objects,make geometry on Rhino etc, Actually, I could not understand the dynamics.


If you still try to understand it have a look at the Source code of rhinoscriptsyntax. You can look up all of its functions and understand how they call into rhinocommon.

If you don’t want to use rhinocommon for efficiency then what’s the point of using c# at all?


You are quite right, and I believe I could benefit greatly if not directly use python syntax on c#.

But, my reason for used with c# is:
1º Make dockable forms
2º Visual studio is excellent in helping the creation of forms (save alot of time)
3º integrate everything into just one plugin
4º I can use all c# method (which has very interesting tools)
5º I have alot python files no convert to c#.(save time if use python sintax)

I’m now beginning to deal with C # language, it’s a slow process of learning, but I confess that I’m liking it and I believe that I can gradually begin to understand the dynamics of rhinocommon on c#.

when I started with python editor, I had a feeling it could do everything, over time I was found the limitations of ironpython vs Rhino, so I decided to take a step forward and try the C rhino-for-windows

The question is:
Is there any problem in using python syntax in C #?
What can happen? slower application? bugs ? What can go wrong? etc??

No there is no obvious problem in using rs within C#, but its not very useful.
Its just an additional but unnecessary layer on top. This increases errors and gives unnecessary overheat. But so what?!
Arguments of performance are secondary, because I consider this as micro optimisation. In the end the algorithm is the most important aspect when it comes to performance.

Pythons better readability and easiness is a trade-off. Most readability comes from not using curly brackets for blocks and being a dynamic typed language.
Strongly typing features are no disadvantages at all. They result in more code, but they also eliminate a whole category of bugs. Furthermore its more likely to show errors at the right spot (unless you working with “null”) . When coding within an advanced IDE you can even instantly see errors while coding.
I’m not pro C# nor pro Python. Both have their right on existence and I use both equally often. But you shouldn’t mix paradigms just for comfort. Learn C#, learn the syntax and write C#. If you use Python learn the pythonic way in doing things and write true Python code. Its that simple. In the end you’ll see more similarities then differences.

1 Like