Current layer output for use in grasshopper [SOLVED]

do you know how to do this? i would like grasshopper to know if a layer is current.

would greatly appreciate your help with this!


Hello Anika,

this is very easy: The “RhinoDocument.Layers.CurrentLayer” -property returns the current layer (Rhino 6) (3.9 KB)


cool thanks… see, im a total noob.
now i compared the your c# and my python script.

on performance c# is far superior (according to metahopper)…
is this test reliable, and in general, is c# always lighter on cpu then python script?

I don’t know,

its difficult to answer. I tend to say its not reliable.
Python is written in C and you can write Pythonmodules in C which
again can be faster than C#.Furthermore you can call C Code with ctypes library
However you can also call C/C++ code from C# and this is what the
Rhinocommon library is doing with p/Invoke mechanism.
Now it doesn’t matter if you open this library in C# or Python, its the same.
However the Python script component can have a slightly greater overhead when initialising
the script component, but thats nothing to worry about.

If you really want to measure performance of an algoritm made by yourself, you should
measure specific parts of your code only. In c# its the Stopwatch class, in Python the time module.
But thats not enough, you need to measure multiple times.
It makes also sense to flush and collect the Garbage Collection before and after measuring.
In the end its microoptimisation. Its always about the efficency of the algorithm you are using.
However, in general compiled and optimised C# Code is known to be faster as interpreted Python Code.

1 Like

By one millisecond, talk about micro optimising your code!

Just to be clear: IronPython (the .NET version of Python that Rhino/Grasshopper implements) is written entirely in C#, which is what allows us to implement .NET assemblies (such as RhinoCommon) directly.

1 Like

good to know!

apart from this scripting solution within python/grasshopper if have found something that will solve this problem and enhance my overall workflow immensely i guess…

super simple and powerful tool called OnTopReplica.

In case for Current Layer display… i just crop that screen area from down below…

one can imagine shitloads of other applications.

ok, didn’t know that its entirely written in C#… I always believed its a converter between IL and Standard-Python.

1 Like