Rhino 8 Feature: RhinoCode (CPython, CSharp)

Also appears the editor doesn’t like it when the file is edited externally while open.

1 Like

Logged as RH-66399

Both are logged and wip:

Any plans to have also C++ Editor?

No, C++ support is well outside the bounds of what we are trying to do with this project.

1 Like

Any plans of having a C++ API available to macOS users?

Do you find Visual Studio not adequate for your C++ work? I use it to create C++ DLL for use with my new Python 3.9 scripts.

How do you envision a C++ editor in Rhino would be better?

Are you focused on MacOS where there less C++ support?


No plans. The API for plug-in development on MacOS is RhinoCommon, that is .NET. This is how RhinoCycles is integrated on all supported platforms.

Thanks, I know that, but I prefer C++ and Python.

Nice work @jgillmanjr,
How are you running the file you are editing in pycharm?

I’m unable to open preferences and the right-click → format menus on macOS Monterey (Intel) with the latest wip. Also many buttons show up as a square… not sure if this is intended or just the current state of the new program. Also my editor font defaults to times? I don’'t think I’m doing anything different from the video demo. Screenshot attached:

I’m also experiencing issues with number arguments for rhinocommon methods:

curve_test.py (369 Bytes)
This issue has come up with more methods than just Curve.GetPoint().

Here is my wish list for the future:

  • External editing and running from VSCode and therefore the option of Kite.
    In my current ironpython workflow I use VSCode with a function at the beginning of the script that sends the current file to rhino through the atom http port. It would be nice to figure out a similar functionality where a shortcut in Code would run the script in rhino where one can interact and observe in an adjacent window.
  • Ability to change editor font and font size.
    Maybe this exists and I just can’t access format or preferences?

I hope I’m reporting these bugs correctly please lmk if not.
Thanks for this new feature that I’ve been wanting for so long especially on mac. It seems to be working great so far.

@tristanryerparke1 So in the particular screenshot you were looking at, I was (incorrectly) using RunPythonScript - incorrect in that wasn’t using the cpython interpreter.

Followup attempts involved just loading the script in the RhinoCode editor and running from there.

You need to call GetPoint in a different way now that the .NET integration goes through pythonnet:

import Rhino.Geometry as rg

# ...

crv = GetYourCurve()
pts = crv.Points
dummy_pt = rg.Point3d()
success, pt = pts.GetPoint(0, dummy_pt)

If you want to call the GetPoint that works with Rhino.Geometry.Point4d you need to instantiate dummy_pt with that type.

See https://pythonnet.github.io/ for more info, specifically the section Out and Ref parameters, about half-way the page at this time of writing.

Me running around with arms above head!

Anything that could lead to just a “slightly” better C# editor is warmly recieved. And nuget <3

On the python side, does one have to pick between IronPython and CPython? Or do you have CPython with access to RhinoCommon and .NET? Or is that technically not possible to get both at same time.

1 Like

Using RhinoCode you get to use CPython, where the .NET integration is built on top of pythonnet ( see the documentation link in my previous post). No need to import pythonnet (will fail currently anyway), and RhinoCommon is already referenced, so you can do straight away import Rhino.

The old ways are for using IronPython, currently.

1 Like

I have GetPoint working now but am having trouble with more complicated methods.
I read the pythonnet documentation but am still confused as I have no experience with c# and the language of the docu is pretty foreign to me. Do you think you could point me in the direction of a tutorial or guide that would help me grasp the concept?
This is failing in a similar fashion to my original script:

from Rhino.Input.Custom import *
from Rhino.Commands import *
from Rhino.Geometry import Point3d, PolylineCurve
import Rhino

def get_curve():
    gc = GetObject()
    gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
    if gc.CommandResult()!=Rhino.Commands.Result.Success: return
    crv = gc.Object(0).Curve()
    return crv

crv = get_curve()

dummy_ply = PolylineCurve()

print( crv.ToPolyline(0.1, 0.0, 0.0, 0.0, dummy_ply) )

Console output:

TypeError : No method matches given arguments for ToPolyline: (<class 'float'>, <class 'float'>, <class 'float'>, <class 'float'>, <class 'Rhino.Geometry.PolylineCurve'>)
  File "/Users/tristanryerparke/Dropbox (Personal)/Mac (2)/Desktop/RhinoCode Test/curve_test.py", line 18, in <module>
    print( crv.ToPolyline(0.1, 0.0, 0.0, 0.0, dummy_ply) )
   at Python.Runtime.Runtime.CheckExceptionOccurred() in /Users/bozo/TeamCity/buildAgent/work/96e64af5b81c6f85/src4/rhino4/Plug-ins/RhinoCodePlugins/src/lib/McNeel.PythonNet/src/runtime/runtime.cs:line 527
   at Python.Runtime.PyScope.Execute(PyObject script, PyDict locals) in /Users/bozo/TeamCity/buildAgent/work/96e64af5b81c6f85/src4/rhino4/Plug-ins/RhinoCodePlugins/src/lib/McNeel.PythonNet/src/runtime/pyscope.cs:line 240
   at Python.Runtime.RhinoCPythonEngine.RunScope(String scopeName, String pythonFile, Boolean tempFile, Boolean useCache) in /Users/bozo/TeamCity/buildAgent/work/96e64af5b81c6f85/src4/rhino4/Plug-ins/RhinoCodePlugins/src/lib/McNeel.PythonNet/src/runtime/RhinoCPythonEngine.cs:line 319

Is there any plan for functionality similar to how it was in ironpython or autocomplete hints that would help new users with this?

Change to

print(crv.ToPolyline(0.1, 0.0, 0.0, 0.0) )

Not sure why dummy_ply is provided a the end

@tristanryerparke1 as @eirannejad mentions don’t use that dummy_ply there. The section I referred you to talks about out and ref parameters. When you look at Curve.ToPolyline Method (Double, Double, Double, Double) you’ll see that the method takes neither.

For explanation of out see out parameter modifier - C# Reference | Microsoft Docs . For explanation of ref please see ref keyword - C# Reference | Microsoft Docs.

There is indeed a learning curve to this part of scripting with the new Python in Rhino 8, but once you have wrapped your head around it the concepts won’t be so hard.

If there are more parts of the pythonnet documentation that feel strange, try to look up the concepts in the C# language reference, or search for tutorials on the internet. Or maybe start new threads for specifically pythonnet/CPython/Rhino 8 in the Serengeti category of this forum. We’ll help (:

1 Like

All that said, this has been available all of two weeks. We do hope to solve these issues of incompatibility so you can use your existing scripts with the only required modifications being to make sure the script is python 3 compliant.


Release Notes (8.0.21327.16306)

:warning: Seems like the editor control is broken on Windows
:warning: We’re currently doing a bit of refactoring and cleanup on the editor UI code

  • Fixed crashing opening language settings RH-66388
  • pip installs with no issues now when user home path contains spaces RH-66335
  • First attempt at merging config files into editor.json. If there is a ~/.rhinocode/workspaces.json file you can delete that.
  • Language options how has “unset” state on mac (checkbox with a negative mark)
1 Like