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

Cool!

Thanks Chris. I also just edited it so that you can adjust how important flatness is vs. shortest distance with a slider.

I removed the previous version and have attached a better one. This one has a slider for flatness bias. At 0, it simply finds the shortest path, at 1, it tries to find paths that slope as little as possible. (you can enter any floating point value you want though)

Attachments:

Hi,

Thanks for your code, it's very interesting.

 

It's possible using  NetworkX for geodesic courbe in respecting geometric conditions.

The conditions may, for example on straight or curved.

 

Thanks for share

Hi,

An error occurs.
looking at your code I understand that I can not access this:

pathbits = [
        'C:\\Program Files (x86)',
        'Python26',
        'Lib',
        'site-packages'
        ]

There are a few things that you need to do before you can use the script:

 

  1. install the latest Rhino 5 wip
  2. install the python for grasshopper component
  3. download and/or install networkx.
  4. edit the pathbits list you pasted above to point to the folder that contains the 'networkx' folder. Mine was in C:\Program files (x86)\Python26\Lib\site-packages. This folder may not exist on your computer.

Thanks,

But where I can download Networkx...

Thanks benjamin,

The file is: networkx-1.5-py3.2.egg ?

 

 

If all you want to do is get this working, and you don't want to learn to use python outside of Rhino (which is of course what networkx was made for), then you should just try downloading the source: networkx-1.5, unzip it, and then look inside for the folder named 'networkx'. You can move this folder where you want, but be sure to edit the 'pathbits' portion of the script to point to the folder that contains the folder called 'networkx'.

 

If you want to understand how to use python packages in general, you should do some googling, and install your own version of CPython, then setuptools, and pip. Maybe later I will write a tutorial on this topic.

Sorry,

I've download netwokx and to place to folder :

C:\Program Files\Rhinoceros 4.0\Plug-ins\RhinoDeveloppements\RhinoRoad\Script\Python\networkx-1.5

and i've writen in the code python:

pathbits = [
        'C:\\Program Files\\Rhinoceros 4.0\\Plug-ins\\RhinoDeveloppements\\RhinoRoad\\Script\\networkx-1.5\\networkx'
        ]

importPath = os.path.join(*pathbits)
sys.path.append( importPath )

import networkx

G = networkx.Graph()
G.add_nodes_from(range(mesh.Vertices.Count))

 

And i've change GH file for read a file in the good folder.

But don't working, runitme error: 1.Solution expetion: EOL while scanning a single line quote string.

 

Thanks for share it

pathbits = [
        'C:\\Program Files',

'Rhinoceros 4.0',

'Plug-ins',

'RhinoDeveloppements',

'RhinoRoad',

'Script',

'networkx-1.5',

'networkx'
        ]

importPath = os.path.join(pathbits)

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