Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created November 4, 2022 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/c7a4d3abe138f1c9b0e15ad80190af2f to your computer and use it in GitHub Desktop.
Save chuongmep/c7a4d3abe138f1c9b0e15ad80190af2f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Installer Package"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: autodesk_forge_sdk in c:\\users\\vho2\\appdata\\local\\programs\\python\\python39\\lib\\site-packages (0.1.2)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"[notice] A new release of pip available: 22.2.2 -> 22.3\n",
"[notice] To update, run: python.exe -m pip install --upgrade pip\n"
]
}
],
"source": [
"!pip install autodesk_forge_sdk"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"FORGE_CLIENT_ID = os.environ[\"FORGE_CLIENT_ID\"]\n",
"FORGE_CLIENT_SECRET= os.environ[\"FORGE_CLIENT_SECRET\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'type': 'hubs',\n",
" 'id': 'b.b24a4792-e097-4f91-9cc1-3af2c21e57cb',\n",
" 'attributes': {'name': 'chuongmep',\n",
" 'extension': {'type': 'hubs:autodesk.bim360:Account',\n",
" 'version': '1.0',\n",
" 'schema': {'href': 'https://developer.api.autodesk.com/schema/v1/versions/hubs:autodesk.bim360:Account-1.0'},\n",
" 'data': {}},\n",
" 'region': 'US'},\n",
" 'links': {'self': {'href': 'https://developer.api.autodesk.com/project/v1/hubs/b.b24a4792-e097-4f91-9cc1-3af2c21e57cb'}},\n",
" 'relationships': {'projects': {'links': {'related': {'href': 'https://developer.api.autodesk.com/project/v1/hubs/b.b24a4792-e097-4f91-9cc1-3af2c21e57cb/projects'}}}}}]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n",
"from autodesk_forge_sdk import AuthenticationClient, Scope, DataManagementClient,OAuthTokenProvider\n",
"client = DataManagementClient(OAuthTokenProvider(os.environ[\"FORGE_CLIENT_ID\"], os.environ[\"FORGE_CLIENT_SECRET\"]))\n",
"hubs = client.get_all_hubs()\n",
"hubs"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'https://developer.api.autodesk.com/project/v1'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.base_url"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"hubidb = hubs[0][\"id\"]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"projests = client.get_projects(hubidb)\n",
"len(projests)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'type': 'projects',\n",
" 'id': 'b.ad33088f-5e47-48aa-956d-836a1b055580',\n",
" 'attributes': {'name': 'Sample Project - Seaport Civic Center',\n",
" 'scopes': ['b360project.ad33088f-5e47-48aa-956d-836a1b055580',\n",
" 'O2tenant.32914228'],\n",
" 'extension': {'type': 'projects:autodesk.bim360:Project',\n",
" 'version': '1.0',\n",
" 'schema': {'href': 'https://developer.api.autodesk.com/schema/v1/versions/projects:autodesk.bim360:Project-1.0'},\n",
" 'data': {'projectType': 'ACC'}}},\n",
" 'links': {'self': {'href': 'https://developer.api.autodesk.com/project/v1/hubs/b.b24a4792-e097-4f91-9cc1-3af2c21e57cb/projects/b.ad33088f-5e47-48aa-956d-836a1b055580'},\n",
" 'webView': {'href': 'https://acc.autodesk.com/docs/files/projects/ad33088f-5e47-48aa-956d-836a1b055580'}},\n",
" 'relationships': {'hub': {'data': {'type': 'hubs',\n",
" 'id': 'b.b24a4792-e097-4f91-9cc1-3af2c21e57cb'},\n",
" 'links': {'related': {'href': 'https://developer.api.autodesk.com/project/v1/hubs/b.b24a4792-e097-4f91-9cc1-3af2c21e57cb'}}},\n",
" 'rootFolder': {'data': {'type': 'folders',\n",
" 'id': 'urn:adsk.wipprod:fs.folder:co.4hsS5TXQR_-3xumyuHZPMg'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/data/v1/projects/b.ad33088f-5e47-48aa-956d-836a1b055580/folders/urn:adsk.wipprod:fs.folder:co.4hsS5TXQR_-3xumyuHZPMg'}}},\n",
" 'topFolders': {'links': {'related': {'href': 'https://developer.api.autodesk.com/project/v1/hubs/b.b24a4792-e097-4f91-9cc1-3af2c21e57cb/projects/b.ad33088f-5e47-48aa-956d-836a1b055580/topFolders'}}},\n",
" 'issues': {'data': {'type': 'issueContainerId',\n",
" 'id': 'ad33088f-5e47-48aa-956d-836a1b055580'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/issues/v1/containers/ad33088f-5e47-48aa-956d-836a1b055580/issues'}}},\n",
" 'submittals': {'data': {'type': 'submittalContainerId',\n",
" 'id': 'ad33088f-5e47-48aa-956d-836a1b055580'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/submittals/v1/containers/ad33088f-5e47-48aa-956d-836a1b055580/items'}}},\n",
" 'rfis': {'data': {'type': 'rfisContainerId',\n",
" 'id': 'ad33088f-5e47-48aa-956d-836a1b055580'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/bim360/rfis/v1/containers/ad33088f-5e47-48aa-956d-836a1b055580/rfis'}}},\n",
" 'markups': {'data': {'type': 'markupsContainerId',\n",
" 'id': 'ad33088f-5e47-48aa-956d-836a1b055580'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/issues/v1/containers/ad33088f-5e47-48aa-956d-836a1b055580/markups'}}},\n",
" 'checklists': {'data': {'type': 'checklistsContainerId',\n",
" 'id': 'ad33088f-5e47-48aa-956d-836a1b055580'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/bim360/checklists/v1/containers/ad33088f-5e47-48aa-956d-836a1b055580/instances'}}},\n",
" 'cost': {'data': {'type': 'costContainerId',\n",
" 'id': 'ad33088f-5e47-48aa-956d-836a1b055580'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/cost/v1/containers/ad33088f-5e47-48aa-956d-836a1b055580/budgets'}}},\n",
" 'locations': {'data': {'type': 'locationsContainerId',\n",
" 'id': 'ad33088f-5e47-48aa-956d-836a1b055580'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/bim360/locations/v2/containers/ad33088f-5e47-48aa-956d-836a1b055580/trees/default/nodes'}}}}},\n",
" {'type': 'projects',\n",
" 'id': 'b.b7bf0384-be62-4da7-ac49-f64f8c4e2fff',\n",
" 'attributes': {'name': 'Component Library Project f6a6c5c7-7f89-4080-bc68-009c5f3dd29b',\n",
" 'scopes': ['b360project.b7bf0384-be62-4da7-ac49-f64f8c4e2fff',\n",
" 'O2tenant.32914228'],\n",
" 'extension': {'type': 'projects:autodesk.bim360:Project',\n",
" 'version': '1.0',\n",
" 'schema': {'href': 'https://developer.api.autodesk.com/schema/v1/versions/projects:autodesk.bim360:Project-1.0'},\n",
" 'data': {'projectType': 'ACC'}}},\n",
" 'links': {'self': {'href': 'https://developer.api.autodesk.com/project/v1/hubs/b.b24a4792-e097-4f91-9cc1-3af2c21e57cb/projects/b.b7bf0384-be62-4da7-ac49-f64f8c4e2fff'},\n",
" 'webView': {'href': 'https://acc.autodesk.com/docs/files/projects/b7bf0384-be62-4da7-ac49-f64f8c4e2fff'}},\n",
" 'relationships': {'hub': {'data': {'type': 'hubs',\n",
" 'id': 'b.b24a4792-e097-4f91-9cc1-3af2c21e57cb'},\n",
" 'links': {'related': {'href': 'https://developer.api.autodesk.com/project/v1/hubs/b.b24a4792-e097-4f91-9cc1-3af2c21e57cb'}}},\n",
" 'rootFolder': {'data': {'type': 'folders',\n",
" 'id': 'urn:adsk.wipprod:fs.folder:co.yVHIthSZSJWuPlFM8bF3Vg'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/data/v1/projects/b.b7bf0384-be62-4da7-ac49-f64f8c4e2fff/folders/urn:adsk.wipprod:fs.folder:co.yVHIthSZSJWuPlFM8bF3Vg'}}},\n",
" 'topFolders': {'links': {'related': {'href': 'https://developer.api.autodesk.com/project/v1/hubs/b.b24a4792-e097-4f91-9cc1-3af2c21e57cb/projects/b.b7bf0384-be62-4da7-ac49-f64f8c4e2fff/topFolders'}}},\n",
" 'issues': {'data': {'type': 'issueContainerId',\n",
" 'id': 'b7bf0384-be62-4da7-ac49-f64f8c4e2fff'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/issues/v1/containers/b7bf0384-be62-4da7-ac49-f64f8c4e2fff/issues'}}},\n",
" 'submittals': {'data': {'type': 'submittalContainerId',\n",
" 'id': 'b7bf0384-be62-4da7-ac49-f64f8c4e2fff'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/submittals/v1/containers/b7bf0384-be62-4da7-ac49-f64f8c4e2fff/items'}}},\n",
" 'rfis': {'data': {'type': 'rfisContainerId',\n",
" 'id': 'b7bf0384-be62-4da7-ac49-f64f8c4e2fff'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/bim360/rfis/v1/containers/b7bf0384-be62-4da7-ac49-f64f8c4e2fff/rfis'}}},\n",
" 'markups': {'data': {'type': 'markupsContainerId',\n",
" 'id': 'b7bf0384-be62-4da7-ac49-f64f8c4e2fff'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/issues/v1/containers/b7bf0384-be62-4da7-ac49-f64f8c4e2fff/markups'}}},\n",
" 'checklists': {'data': {'type': 'checklistsContainerId',\n",
" 'id': 'b7bf0384-be62-4da7-ac49-f64f8c4e2fff'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/bim360/checklists/v1/containers/b7bf0384-be62-4da7-ac49-f64f8c4e2fff/instances'}}},\n",
" 'cost': {'data': {'type': 'costContainerId',\n",
" 'id': 'b7bf0384-be62-4da7-ac49-f64f8c4e2fff'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/cost/v1/containers/b7bf0384-be62-4da7-ac49-f64f8c4e2fff/budgets'}}},\n",
" 'locations': {'data': {'type': 'locationsContainerId',\n",
" 'id': 'b7bf0384-be62-4da7-ac49-f64f8c4e2fff'},\n",
" 'meta': {'link': {'href': 'https://developer.api.autodesk.com/bim360/locations/v2/containers/b7bf0384-be62-4da7-ac49-f64f8c4e2fff/trees/default/nodes'}}}}}]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"projests[\"data\"]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>type</th>\n",
" <th>id</th>\n",
" <th>attributes</th>\n",
" <th>links</th>\n",
" <th>relationships</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>projects</td>\n",
" <td>b.ad33088f-5e47-48aa-956d-836a1b055580</td>\n",
" <td>{'name': 'Sample Project - Seaport Civic Cente...</td>\n",
" <td>{'self': {'href': 'https://developer.api.autod...</td>\n",
" <td>{'hub': {'data': {'type': 'hubs', 'id': 'b.b24...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>projects</td>\n",
" <td>b.b7bf0384-be62-4da7-ac49-f64f8c4e2fff</td>\n",
" <td>{'name': 'Component Library Project f6a6c5c7-7...</td>\n",
" <td>{'self': {'href': 'https://developer.api.autod...</td>\n",
" <td>{'hub': {'data': {'type': 'hubs', 'id': 'b.b24...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" type id \\\n",
"0 projects b.ad33088f-5e47-48aa-956d-836a1b055580 \n",
"1 projects b.b7bf0384-be62-4da7-ac49-f64f8c4e2fff \n",
"\n",
" attributes \\\n",
"0 {'name': 'Sample Project - Seaport Civic Cente... \n",
"1 {'name': 'Component Library Project f6a6c5c7-7... \n",
"\n",
" links \\\n",
"0 {'self': {'href': 'https://developer.api.autod... \n",
"1 {'self': {'href': 'https://developer.api.autod... \n",
"\n",
" relationships \n",
"0 {'hub': {'data': {'type': 'hubs', 'id': 'b.b24... \n",
"1 {'hub': {'data': {'type': 'hubs', 'id': 'b.b24... "
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"# dictionary to dataframe\n",
"pd.DataFrame(projests[\"data\"])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SpeckleClient( server: https://speckle.xyz, authenticated: True )\n"
]
}
],
"source": [
"from specklepy.api.wrapper import StreamWrapper\n",
"streamid = \"0cc1692ab7\"\n",
"commitid = \"7617918499\"\n",
"# provide any stream, branch, commit, object, or globals url\n",
"wrapper = StreamWrapper(\"https://speckle.xyz/streams/0cc1692ab7/commits/7617918499\")\n",
"\n",
"# get an authenticated SpeckleClient if you have a local account for the server\n",
"client = wrapper.get_client()\n",
"print(client)\n",
"# get an authenticated ServerTransport if you have a local account for the server\n",
"transport = wrapper.get_transport()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>id</td>\n",
" <td>a7313af2cf</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>name</td>\n",
" <td>ForgeProjects</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>role</td>\n",
" <td>stream:owner</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>isPublic</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>description</td>\n",
" <td>No description provided</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>createdAt</td>\n",
" <td>2022-11-04 05:58:29.936000+00:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>updatedAt</td>\n",
" <td>2022-11-04 05:58:29.943000+00:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>collaborators</td>\n",
" <td>[id='334b30b791' name='Hồ Văn Chương' role='st...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>branches</td>\n",
" <td>totalCount=1 cursor=datetime.datetime(2022, 11...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>commit</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>object</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>commentCount</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>favoritedDate</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>favoritesCount</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1\n",
"0 id a7313af2cf\n",
"1 name ForgeProjects\n",
"2 role stream:owner\n",
"3 isPublic True\n",
"4 description No description provided\n",
"5 createdAt 2022-11-04 05:58:29.936000+00:00\n",
"6 updatedAt 2022-11-04 05:58:29.943000+00:00\n",
"7 collaborators [id='334b30b791' name='Hồ Văn Chương' role='st...\n",
"8 branches totalCount=1 cursor=datetime.datetime(2022, 11...\n",
"9 commit None\n",
"10 object None\n",
"11 commentCount 0\n",
"12 favoritedDate None\n",
"13 favoritesCount 0"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"# create a stream\n",
"new_stream_id = client.stream.create(name=\"ForgeProjects\")\n",
"# get a stream\n",
"new_stream = client.stream.get(id=new_stream_id)\n",
"pd.DataFrame(new_stream)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done\n"
]
}
],
"source": [
"from specklepy.transports.memory import MemoryTransport\n",
"from specklepy.api import operations\n",
"from specklepy.transports.server import ServerTransport\n",
"from specklepy.objects import Base\n",
"class Projects(Base,speckle_type=\"testproject\"):\n",
" type: object\n",
" id: object\n",
" attributes: object\n",
" links: object\n",
" relationships: object\n",
" def __init__(self, type, id, attributes, links, relationships):\n",
" self.type = type\n",
" self.id = id\n",
" self.attributes = attributes\n",
" self.links = links\n",
" self.relationships = relationships\n",
"allprojects = []\n",
"for i in range(len(projests[\"data\"])):\n",
" type = projests[\"data\"][i][\"type\"]\n",
" id = projests[\"data\"][i][\"id\"]\n",
" attributes = projests[\"data\"][i][\"attributes\"]\n",
" links = projests[\"data\"][i][\"links\"]\n",
" relationships = projests[\"data\"][i][\"relationships\"]\n",
" project = Projects(type, id, attributes, links, relationships)\n",
" allprojects.append(project)\n",
"myobj = Base(speckle_type=\"AllProject\", data=allprojects)\n",
" # next create a server transport - this is the vehicle through which you will send and receive\n",
"transport = ServerTransport(client=client, stream_id=new_stream_id)\n",
" # this serialises the block and sends it to the from specklepy.transports.server import ServerTransport\n",
"hash = operations.send(base=myobj, transports=[transport])\n",
" # you can now create a commit on your stream with this object\n",
"commid_id = client.commit.create(\n",
" stream_id=new_stream_id, \n",
" object_id=hash, \n",
" message=\"this is a project I made in speckle-py\",\n",
" )\n",
"print(\"Done\")"
]
}
],
"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.9.13"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "45a96ae95fccfe4d6dd9595689015a1b740d7e3280cd227ef2d6b427f5864e6e"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment