Using rhinoscriptsyntax in Jupyter Notebook

Did anyone use rhinoscriptsyntax module in Jupiter notebook? Or is there an API from Rhino to extract surface normal vectors from a rhino model in the Jupiter notebook?

Hello,

You maybe able to do this with the Rhino3dm package or simply export the vectors from rhino to (e.g.) csv format and then import them into your Jupyter Notebook.

Graham

Hi Graham,

Thanks for your suggestion. I did try rhino3dm package but it doesn’t seem to have any function for surface normals which I need to automate my extract process.

Ahh yes you may need rhino compute for a lot of functionality if you want to stay in Python …

Hi @sunny.ying,

Use Surface.NormalAt.

https://mcneel.github.io/rhino3dm/python/api/Surface.html

– Dale

2 Likes

Hi Dale,

I found that NormalAt function this afternoon as well. It might work, but I will need to convert the objects that I pulled from Rhino model from Brep to Surface in order to use that function. And so far I didn’t find any rhino3dm function to convert from Brep to Surface. Could you advice?

Couldn’t you explode the brep/polysurface into its individual composants and look for the normal for each of these surfaces?

Exploding can be done with my_brep.Faces or my_brep.Surfaces, which will give you a collection of faces or surfaces respectively. for each surface, you could then get a normal with my_srf.NormalAt(u, v). You might want to normalize your surface first though, although I don’t know if Rhino3dm has this functionality yet. @Dale might know this!

1 Like

Hi @sunny.ying,

In a 3dm file, all surfaces and polysurfaces (both trimmed and untrimmed) are represented by a Brep. So you won’t be "converting"a Brep to a Surface, as that is not really possible. Instead, you will be evaluating a Brep and looking at it’s BrepFace objects and perhaps their underlying Surface objects.

– Dale

Have you tried Rhino.Inside CPython for running in jupyter notebooks? I haven’t personally tried, but it may work

Hi @stevebaer Steve,
I was able to pip install and import rhinoinside. But am I supposed to import rhino as well (I got an error here)? If so, how to successfully import rhino?

Are you running on Windows where a Rhino is installed? Do you know what version of CPython is running?

Yes I’m running on Windows with Rhino 6 & Rhino WIP installed.
What is CPython? I did install python 3.7 64 bit version:
image

Hello,

CPython, often known as just Python is the reference implementation of the python programming language, itself written in the C programming language. You have installed CPython, as opposed to the IronPython interpreter included with Rhino and GrassHopper, written in C#. The latest version of CPython is 3.8 and the latest version of IronPython is 2.7 so there are some differences in syntax and capabilities.

Rhino3dm and Rhino Inside are intended for CPython

1 Like
import Rhino

should work. It has to be capitalized if I remember correctly.

1 Like

Good catch Max. Yes, Rhino needs to be capitalized.

Could you post an update if it works or not once you have tried it? Would be awesome for others to know without trying themselves :slight_smile:

Hi everyone, thanks for helping out. I believe I’ve set up everything correctly but still it has the same error:

1 Like

Just tested it and it works:

@sunny.ying here are a few suggestions:

  • check that you have the latest Rhino WIP installed
  • check that you have the latest rhinoinside module installed
  • restart your notebook if you’ve updated anything
  • try loading rhinoinside directly in cpython (without jupyter) and see if that works
4 Likes

Hi @DavidLeon
Thanks for your suggestions! Yes I have installed the latest Rhino WIP/rhinoinside. After restarting my notebook still it didn’t work.
But if I just run python in my Command Prompt, it did work:


Any idea why Jupyter Notebook did not work out? Must be due to some settings I believe.

Hi @dale
How can I use the Surface.NormalAt function with rhino3dm api then? I’m trying to access the Surfaces attribute of Geometry and then use the NormalAt function:


But it gave me such an error below: