Grasshopper

algorithmic modeling for Rhino

Being able to use Python in Grasshopper opens up Grasshopper to tons of excellent scientific computation and simulation libraries, including NetworkX.

 

Using NetworkX for the first time, I was able to translate the topology of a Rhino Mesh into a NetworkX Graph object, and then I used a custom function to weight the edges between nodes. In this case, the weight between any two mesh vertices is the distance multiplied by the difference in height, causing a least cost path algorithm to find the shortest, flattest paths between two points.

 

The python code can be viewed here:

https://gist.github.com/1057297

 

 

Views: 8519

Replies to This Discussion

Hi Benjamin, Thanks for sharing. I'm foloowing your instruction and I get this error, any idea?

Thanks

Attachments:

really interesting work!

thank you for shareing it!

Hello Benjamin,

First, thank you very much for sharing thoses very interesting definitions.I was trying to make a definition with the same goal without sucess, and was realy pleased to discover your script.

But I am encountering a problem when the point choosen on the mesh are too low. The path calculated seems to be atracted toward the firsts (origin)points of the mesh. As soon as i choose higher points it works perfectly. Any idea how i could fix that ?

Cordialy

Maui COJAN

Attachments:

Hi Maui,

It depends on what you used to input the indices of the mesh points for the from and to nodes. Can you post a screenshot of your grasshopper definition, and how you set up the inputs?

Best,

Ben

Thank you for your answer Benjamin.

Here is how i set up the inputs.i tried to find the (from and to)nodes by moving closest points.

tell me if you prefer to have the 3dm& ghx files.

Best

Maui

Attachments:

When you create the delaunay mesh, then the mesh will have it's own internal order of points. In order to use an index that correctly corresponds to the order of the points in the mesh, you need to get index numbers from the mesh vertices.

When you create the delaunay mesh, it will not retain the same order of points.

Try using a mesh vertices component to get the index of the vertices you want to use from the delaunay mesh.

You can use weaverbird components to get all of your mesh edges, and then filter out the edges that don't match your criteria.

Once you do that, if the answer is not so obvious, then use the remaining edges to make a new mesh and run that through network x. Also, feel free to edit the code and use anything you like as a weight function.

Hi Guys,

I have attempted to use the Networkx library. I have installed the library and it works fine when I use it in IDLE (Python GUI). However, when I want to use it in Rhino/Grasshopper the following exception will be thrown: 

Message: Cannot import name minimum_edge_cut

Traceback:
line 60, in <module>, "C:\Program Files\Rhinoceros 5 (64-bit)\Plug-ins\IronPython\Lib\site-packages\networkx\algorithms\__init__.py"
line 21, in <module>, "C:\Program Files\Rhinoceros 5 (64-bit)\Plug-ins\IronPython\Lib\site-packages\networkx\generators\classic.py"
line 5, in <module>, "C:\Program Files\Rhinoceros 5 (64-bit)\Plug-ins\IronPython\Lib\site-packages\networkx\generators\__init__.py"
line 84, in <module>, "C:\Program Files\Rhinoceros 5 (64-bit)\Plug-ins\IronPython\Lib\site-packages\networkx\__init__.py"

I would inform you that I have also copied the Networkx library into "C:\Program Files\Rhinoceros 5 (64-bit)\Plug-ins\IronPython\Lib\site-packages\" and have specified this directory in "Python Options->Files->Module Search Paths" so that Rhino/Grasshopper knows where to access this library.

Could you please help me how can I sort this out?

Any comment is highly appreciated.

Shayan

Try installing networkx 1.2 instead of the latest one. You will need to uninstall the current one first.

Have reference the directory of python library in rhino editPython in the options? After that restartart rhino and it should work. As your error says that it does not find directory.
Also please attach the file you are working it is good to see how you referenced networkx in gh.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service