Added "Grasshopper to Jupyter" notebook.
This commit is contained in:
Родитель
096cc9852f
Коммит
0c74ce125b
|
@ -0,0 +1,149 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"id": "17e1ee48",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Working with GH Data in Jupyter via SpecklePy🐍"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"id": "b19579d1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Notebook requirements👇"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "d3d134f5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture\n",
|
||||
"# capture turns off the output for this cell which is the install log\n",
|
||||
"%pip install specklepy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"id": "78e9c592",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Boilerplate for a basic specklepy script."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"id": "023504e7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from specklepy.api.client import SpeckleClient\n",
|
||||
"from specklepy.api.wrapper import StreamWrapper\n",
|
||||
"from specklepy.api import operations\n",
|
||||
"\n",
|
||||
"# speckle server url 👇\n",
|
||||
"HOST_SERVER = \"https://speckle.xyz\"\n",
|
||||
"# Your Speckle Stream URL goes here 👇\n",
|
||||
"stream_url = \"https://speckle.xyz/streams/275f928307\"\n",
|
||||
"\n",
|
||||
"#wrapper\n",
|
||||
"wrapper = StreamWrapper(stream_url)\n",
|
||||
"#speckle client\n",
|
||||
"client = wrapper.get_client()\n",
|
||||
"#transport\n",
|
||||
"transport = wrapper.get_transport()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4108c1e6",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Receiving GH Data from Speckle server"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e64ea704",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Receive data in Python\n",
|
||||
"commit = client.commit.list(wrapper.stream_id, limit=1)[0]\n",
|
||||
"# get obj id from commit\n",
|
||||
"obj_id = commit.referencedObject\n",
|
||||
"# receive objects from speckle\n",
|
||||
"commit_data = operations.receive(obj_id=obj_id,remote_transport=transport)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"id": "b234c231",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Working with the commit data 👇"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "2aa0fc73",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[0, 20, 40, 60, 80, 100, 120, 140, 160, 180]"
|
||||
]
|
||||
},
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Describe what \"@\" does\n",
|
||||
"gh_data = commit_data[\"@Data\"][\"@{0;0}\"]\n",
|
||||
"#print out the result\n",
|
||||
"gh_data"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.1"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "3e11e7655d454b698ddf48653c0d53a36ba1baee337ad9c629b69c92c41d12c3"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
Загрузка…
Ссылка в новой задаче