Dead-simple REST API for the BIM-B
h
OM-BUM
This is alpha software. This website could will break in unexpected ways. You could lose data, your computer may burn down, kittens might die. Use under your own risk. :)

Using the REST-API with python from within Grasshopper

One alternative for those interested in using the REST-API from within Grasshopper is to use python. However, to run the examples shown in the REST-API Documentation, additional steps are needed to configure the python environment used by Grasshopper (IronPython). Specifically, the library requests (version 2.18.4) is needed. The steps to set up the environment are described below.

  1. Install IronPython 2.7
  2. Download IronPython from https://github.com/IronLanguages/ironpython2/releases/tag/ipy-2.7.11 and install it as any normal program. The default installation in Windows is C:\Program Files\IronPython 2.7\.

    $SYSTEM_IRONPYTHON = "C:\Program Files\IronPython 2.7\"
        
  3. Install requests library
  4. Open powershell or cmd and do:

    "C:\Program Files\IronPython 2.7\Scripts\pip.exe" install --user requests==2.18.4
          

    This command installs the request library in the IronPython installation, as well as any library required by request. These libraries are installed in the following folder: C:\Users\<User>\AppData\Roaming\Python\IronPython27\.

    $LOCAL_IRONPYTHON = "C:\Users\<User>\AppData\Roaming\Python\IronPython27\"
        
  5. Copy files to Rhino python directory
  6. Files will be copied to two folders:

    Copy the files with the following commands in powershell:

    $LOCAL_IRONPYTHON = "C:\Users\<User>\AppData\Roaming\Python\IronPython27\"
    $SYSTEM_IRONPYTHON = "C:\Program Files\IronPython 2.7\"
    $LOCAL_RHINO = "C:\Users\<User>\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (some hash)"
    $SYSTEM_RHINO = "C:\Program Files\Rhino 6\Plug-ins\IronPython"
    
    cp -r $LOCAL_IRONPYTHON/Lib/site-packages/certifi $LOCAL_RHINO/settings/lib/certify
    cp -r $LOCAL_IRONPYTHON/Lib/site-packages/idna $LOCAL_RHINO/settings/lib/idna
    cp -r $LOCAL_IRONPYTHON/Lib/site-packages/chardet $LOCAL_RHINO/settings/lib/chardet
    cp -r $LOCAL_IRONPYTHON/Lib/site-packages/requests $LOCAL_RHINO/settings/lib/requests
    cp -r $LOCAL_IRONPYTHON/Lib/site-packages/urllib3 $LOCAL_RHINO/settings/lib/urllib3
    
    cp $SYSTEM_IRONPYTHON/Lib/stringprep.py $LOCAL_RHINO/settings/lib/stringprep.py
    cp $SYSTEM_IRONPYTHON/Lib/ssl.py $LOCAL_RHINO/settings/lib/ssl.py
    
    cp $SYSTEM_IRONPYTHON/Lib/encodings/idna.py $SYSTEM_RHINO/Lib/encodings/idna.py
          

  7. Modify the python examples
  8. For some reason there is a problem with the validation of the SSL certificate of the website. To avoid an error message, modify the respective request function to add the option verify=False, i.e.

    ...
    
    res = requests.post(url=URL, json=task_data,
                        headers={"Authorization": "your-secret-key"},
                        verify=False)
        
  9. Done!