Skip to content

Commit

Permalink
add publish model
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Sep 24, 2024
1 parent 5bfd869 commit 12928ba
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
40 changes: 40 additions & 0 deletions APSToolkitPython/src/aps_toolkit/BIM360.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,46 @@ def parse_url(url: str) -> dict:
'model_guid': model_guid,
}

def publish_model(self, project_id: str, item_id: str):
"""
Publish a model in Autodesk Construction Cloud (ACC)
:param project_id: the unique identifier of a project
:param item_id: the unique identifier of an item
:return: Response from the API
"""
headers = {
'Authorization': f'Bearer {self.token.access_token}',
'Content-Type': 'application/vnd.api+json'
}
url = f"{self.host}/data/v1/projects/{project_id}/commands"

payload = {
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "commands",
"attributes": {
"extension": {
"type": "commands:autodesk.bim360:C4RModelPublish",
"version": "1.0.0"
}
},
"relationships": {
"resources": {
"data": [
{
"type": "items",
"id": item_id
}
]
}
}
}
}
response = requests.post(url, headers=headers, json=payload)
return response.json() if response.status_code == 200 else response.text

def get_hubs(self) -> dict:
"""
Returns a collection of accessible hubs for this member.
Expand Down
8 changes: 7 additions & 1 deletion APSToolkitPython/src/test/test_bim360.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setUp(self):
self.token = Auth().auth2leg()
self.bim360 = BIM360(self.token)
self.hub_id = "b.1715cf2b-cc12-46fd-9279-11bbc47e72f6"
self.project_id = "b.ca790fb5-141d-4ad5-b411-0461af2e9748"
self.project_id = "b.ec0f8261-aeca-4ab9-a1a5-5845f952b17d"
self.folder_id = "urn:adsk.wipprod:fs.folder:co.sSH-pxrUR8CoAAJHS5kYIA"
self.item_id = "urn:adsk.wipprod:dm.lineage:wGXA2ljoSQaXtGOEepawIg"

Expand All @@ -23,6 +23,12 @@ def test_parse_url(self):
self.assertEqual(result['folder_urn'], "urn:adsk.wipprod:fs.folder:co.uX9MsdjjSraK_3p5qXyE_A")
self.assertEqual(result['entity_id'], "urn:adsk.wipprod:dm.lineage:wGXA2ljoSQaXtGOEepawIg")

def test_publish_model(self):
item_id = "urn:adsk.wipprod:dm.lineage:Od8txDbKSSelToVg1oc1VA"
token = Auth().auth3leg()
bim360 = BIM360(token)
result = bim360.publish_model(self.project_id, item_id)
self.assertNotEquals(result, 0)
def test_get_hubs(self):
hubs = self.bim360.get_hubs()
self.assertNotEquals(hubs, 0)
Expand Down

0 comments on commit 12928ba

Please sign in to comment.