A Place to Share Python Scripts

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

Load Previous Comments
  • Benjamin Golder

    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

        

  • Saeran Vasanthakumar

    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.

  • Benjamin Golder

    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?