Grasshopper

algorithmic modeling for Rhino

I just started a new github repo for sharing python scripts for Rhino and Grasshopper:
www.github.com/localcode/rhinopythonscripts

If you'd be interested in sharing scripts, please feel free to check it out (or fork it, as the case may be).
I'd love to share ideas about how to work with python in Rhino, using a shared repository. You can also fork it and edit the documentation, add examples, or whatever you want. I was simply hoping to start a somewhat informal way to share scripts that could grow into something really helpful.

I just put it up within the past few hours, so what I've done so far is poorly documented and incomplete, but I'll certainly be adding to this on a regular basis.


Cheers,

Ben

Views: 1450

Comment

You need to be a member of Grasshopper to add comments!

Comment by Andy Murray on November 17, 2022 at 11:12pm

I am a software developer, and I have a large collection of open-source Python scripts. I used to keep them in my Github repository, but it is hard to find the right script when I need it. Go to web maintenance marietta for best reviews. The only solution that I found so far was to keep the scripts in my Dropbox folder. I would use it for Python scripts. It's not really good for other languages though, because there are no categories for them.

Comment by Andy Murray on October 27, 2022 at 2:26am

Python Scripts are a great way to automate certain tasks. I've been using them for years and have had great success with them. I'm not sure if you're familiar with them, but there are many different kinds of Python scripts that can be used for a variety of different things. Go to Urgent Care Covington la for best reviews. The documentation is excellent and the community is very helpful. I would recommend it as a first language for anyone who has any interest in computer science or engineering.

Comment by Benjamin Golder on March 21, 2013 at 5:45pm

hmm. I'm not sure what is causing that bug. I'm glad you got things working to some degree.

If you send me a working sample that can repeat the bug, I can figure out what is the cause at a later date. You could just send a grasshopper file and a sample of the data.

I'm excite to see more people using spatial data in their designs. I am curious what type of data you are trying to import and what the project is for. Would you be willing to explain?

Comment by Saeran Vasanthakumar on March 20, 2013 at 6:01pm

Thanks Ben for responding so quickly!

So I tried out what you suggested:

f = open('test_3.geojson').read() # returns a string
data = geojson.load(f)
print data['features']

but I'm getting the following error message: 

"Message: Unable to translate bytes [C3] at index 0 from specified code page to Unicode."

I added some print statements to the start of the load function in the GeoJson2Rhino.py script but none of them are appearing so it looks like its still just not accepting the f parameter - even when it is a string. 

Alternatively, I copied the modules you imported in the GeoJson2Rhino.py file, and then used the json.load like so:

f = open('test_3.geojson').read() # returns a string
data = json.loads(f)

print data['features']

And this worked perfectly. So now I can load my geojson file and use its dictionaries. But I'm still not sure why it's not working through the GeoJson2Rhino.py module.

Comment by Benjamin Golder on March 20, 2013 at 12:02am

Hi Saeran,

The problem is here:

f = open('test_3.geojson')
gj_data
= geojson.load(f)

In python open returns a file object, not text. To read the text from the file, you only need to add:

file_obj = geojson.load(f)

gj_data = file_obj.read() # reads the entire file, returns the file contents as one string.

you can also chain the methods together like this:

gj_data = open('test_3.geojson').read() # returns a string

    

Comment by Saeran Vasanthakumar on March 19, 2013 at 9:43am

This is a great resource. I've been trying to work around the fact that I can't install the geojson module directly into RhinoPython, and finding this should save me a lot of trouble. Thanks for starting this. 

But before I can engage - I'm having some trouble trying to load a geojson file using your GeoJson2Rhino function.

Right now my script looks like this:

import rhinoscriptsyntax as rs  
import sys rp_scripts = "rhinopythonscripts"
sys.path.append(rp_scripts)
import rhinopythonscripts
import GeoJson2Rhino as geojson

layer_1 = rs.GetLayer(layer='Layer 01')
layer_color = rs.LayerColor(layer_1)

f = open('test_3.geojson')
gj_data = geojson.load(f,layer_1,layer_color)
f.close()

 

In particular:

 f = open('test_3.geojson')  
gj_data
= geojson.load(f)

works fine when I'm trying to extract geojson data from regular python 2.7. However in RhinoPython I'm getting the following error message: "Message: expected string for parameter 'text' but got 'file'"; in reference to the "gj_data = geojson.load(f)" line.

I've been looking at the GeoJson2Rhino script and I think I've set the parameters for the function correctly. Is the issue the way I'm trying to open the file?

Comment by Benjamin Golder on May 24, 2011 at 6:37pm

Added GeoJson2Rhino script which translates GeoJSON objects (a common data format for GIS) into Rhino Objects. It still needs some testing, but most of the work is done. Please try it out if you have any GeoJSON data around.

GeoJSON format:

http://geojson.org/geojson-spec.html

also, this will hopefully play nice with the PostSites module I've been working on, for importing GIS site data from a database using PostGIS.

PostSites module:

https://github.com/bengolder/postsites

Comment by Benjamin Golder on May 19, 2011 at 4:09pm

Added a bit more.

There's a nice new module called "RunCPythonScript" for running scripts that don't work too well in IronPython. It let's you run scripts on other versions of python that you have installed on your computer.

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