Using the NodeInCode namespace

A few questions:

  1. By "node" do you mean "component"?
  2. Do you need grasshopper opened in order to access a component from Rhino PythonEditor?
  3. Do you need component to be instantiated (placed in the canvas) before you can access it this way?

“NodeInCode” is the trademark name of this feature. We do not mean something in particular. I guess whoever thought of this, could have had this in mind.

The answer is no. It was designed so that GH is started upon need.

Everything is handled automatically by the system.

1 Like

@piac, correct me if I’m wrong, but ideally this library will allow us to transform a GH algorithm into Rhino.python script. If developed further so it also can detect links between the components.

Also, create GH algorithm from Rhino PythonEditor.

That would be cool :slight_smile:

Yes it can be used with that purpose in mind.

This, it doesn’t currently do. Nor it creates a definition from a script.

How about this?
image

In the standardization process to give all components Python-compatible names, the space is removed. You can use auto-completion like so (this returns functions, not “ComponentInfo” objects):

image

So, print(rh.NodeInCode.Components.FindComponent("CullPattern") ) should work

1 Like

Thanks that’s it!

1 Like

Hello Everyone, and as always thanks to Giulio for your work.

I have a very silly question (not so silly for me sorry)… if I call a grasshopper component in C# and for instance, I get one of the different results that the component provides (through your point 1) example), I have some difficulties in using the “result”.

I mean if I want to recall the ConvexHull component and I want to grab the result[2] ( it is a list of integers)…

dynamic GHConvexHull ( Point3d Pts, Plane Plane)
{
    at some point in the code...
    var index=results[2]; 
 }
    return (index)

in the Main Code at some point:

var idPt=ConvexHull (Pts, Pl);

Now if I want to know the idPt length in the main code and apply the “.Count” definition (idPt.Count), I get this error below:

  1. ‘Grasshopper.DataTree’ does not contain a definition for ‘Count’ (line: 0)

So the “result” appears as Grasshopper.DataTree type, although I see this “result” as a list in the output variable.

This behaviour is extendible to all the object types that come by the Rhino NodeInCode function to recall the GH components inside a C# code (the C# GH component).

In Python, everything works like a charm (by importing ghpythonlib).

***I hope that some experts can share with me tips or solutions. ***
Thank you very much in advance!

It’s true, in fact DataTree(T) Class does not contain a definition of Count. You can get autocompletion by casting to the right type. I think this is going to be DataTree, if memory serves.

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Hello Everyone.
I use NodeinCode name DivideCurve but i have a problems. I want to used result[0] as List but it didn’t work. So how i can fix it, please tell me. Thanks


Hi @ngthanhlong82,

Instead of this:

foreach (var obj in result[0])

Try this:

foreach (var obj in result)

– Dale

Hi @dale . Thanks for helping me but i modifiled my code. The Result sitll problems.

Hi @ngthanhlong82,

Sorry - I am unable to read your screen capture.

I know NodeInCode is “cool”, but why not just call Curve.DivideByCount or Curve.DivideByLength, which is what GH does…

test_divide_curve.gh (8.0 KB)

– Dale

1 Like

Hi @dale . Thanks for answers me. I know 2 component as you told . But i want use this code to make something for me. I can use Method of Rhino" DivideByCount", but I curious about the NodeInCode. How to used it, so i try. Thanks.

I’d start by searching Discourse for NodeInCode.

Also, here are a couple of simple samples you can review. These scripts call the QuickHull component found in RhinoPolyhedra.

test_quickhull1.py (874 Bytes)

test_quickhull2.py (1.2 KB)

– Dale

Thanks @dale !


The result type is IronPython.Runtime.List,how to Convert to C#LIst?

Hi @dale . I had a problem when i used NodeInCode. When i used it in C# SCript, the result return type ( ex : surface). But when i used it in Visual studio ( component Grasshopper ), the result return : IronPython.Runtime.List. I don’t understand. How to convert to Rhino. Please help me. Thanks

Hi @ngthanhlong82,

A screen capture doesn’t really help anyone help you. If you still need assistance, then please post a .GH file.

– Dale

Thanks @dale . I found result.