Rhino 8 Feature: ScriptEditor (CPython, CSharp)

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?
Thanks,
Tristan

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.
Best,
Tristan

@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

Thanks,
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
    gc.Get()
    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?
Best,
Tristan

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.

2 Likes

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

I really tried to code some stuff using RhinoCode but for me it was in to early stage of development to do something with it, so I moved back to Hops workaround to work with CPython.

I love the idea of the CPython in Rhino, but I’m not sure if creating new IDE from scratch for Rhino makes that much sense. As my colleage reacted when I send him a link to this thread, he asked: Why they work on a new IDE rather than make good tools that will allow to use whatever IDE you want. Even though GHPython console is quite good (while C# console is at least for me almost unusable) you will never top the best IDEs (VS, VSCode, Jetbrains, Spyder, Atom etc.) for obvious reasons. Even right now people who I know, they are just using ScriptParasite plugin for C# and use IDE they want. As we know for Python there is also a builtin way to do same thing. I appreciate these examples above from @jgillmanjr when there is this Pycharm being used, because it means that we will be able to do it flawless in the future.

Obviously I don’t have a bigger picture, I don’t know details regarding this technology, therefore I’m missing things for sure. Just wanted to suggest that at the end there is a big chance that many of us will just use it as a bridge with their favourite IDE, while at the same time others will request endless number of features for the editor, to make it look and work just like their favourite editor that already exists.

Best regards :wink:

3 Likes

You will eventually be able to use an external tool like VS Code. We also need to ensure that there is a built-in editor for those who don’t download and use external tools.

[edit] it should also be pointed out that our current EditPythonScript code editors on Windows and Mac are very platform specific. Moving toward the future, we want to be able to write a single cross platform editor that we can make improvements to which show up on both Windows and Mac.

9 Likes

In my case i started coding in rhino and switched after years to VS not the oposite way.
A good IDE in rhino is a great way to learn programming.

4 Likes

Will this feature also be applied to grasshopper code components? :smiley:

Hi @stevebaer, from these two replies I am drawing the conclusion that at some point beyond Rhino 8, Rhino usage of IronPython 2 code will be terminated, meaning we wouldn’t be able to run the IronPython 2 code that currently works on Rhino 5,6,7?

I don’t think that is the proper conclusion to draw. We’ve worked hard to keep legacy RhinoScript running version after version of Rhino. I don’t have any plans to pull IronPython either.

5 Likes

I’m curious as to what the benefits of keeping IronPython around might be. I would imagine the sorts of scripts being used in Rhino wouldn’t be too difficult to port over to Python 3.9.

But I’m obviously happy to be proven wrong.