Skip to content

Commit

Permalink
improve default run export ifc
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Oct 22, 2024
1 parent f116e29 commit 51a1edd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion APSToolkitPython/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="aps-toolkit",
version="1.1.0",
version="1.1.1",
author="chuong mep",
author_email="[email protected]",
description="A Toolkit Autodesk Platform Services for Python",
Expand Down
30 changes: 23 additions & 7 deletions APSToolkitPython/src/aps_toolkit/Derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,21 @@ def translate_job(self, root_file_name: str, type: str = "svf", generate_master_
response = requests.post(url, headers=headers, data=payload)
return response.text

def download_stream_ifc(self,ifc_setting_name="IFC4 Reference View"):
def download_stream_ifc(self,ifc_setting_name="IFC 2x3 GSA Concept Design BIM 2010",is_translate=False):
"""
Download IFC file from the model
:param ifc_setting_name: the setting name of IFC format, see more at : https://help.autodesk.com/view/RVT/2024/ENU/?guid=GUID-E029E3AD-1639-4446-A935-C9796BC34C95
:param is_translate: True if you want post a translation job for convert to IFC format (Cost Will be charged)
:return:
"""
response = self.check_job_status()
process = response["progress"]
while process != "complete" and response['status'] == 'inprogress':
time.sleep(5)
response = self.check_job_status()
process = response["progress"]
derivatives = response["derivatives"]
# find any outputType is "ifc"
flag = any(derivative["outputType"] == "ifc" for derivative in derivatives)
if not flag:
if is_translate:
# start call translate job
response = self.translate_to_ifc(ifc_setting_name)
if response.status_code != 200:
Expand Down Expand Up @@ -115,10 +124,16 @@ def download_stream_ifc(self,ifc_setting_name="IFC4 Reference View"):
stream = self.download_stream_resource(resource)
return {"file_name": manifest_item.path_info.root_file_name, "stream": stream}
return None
def download_ifc(self, file_path=None,ifc_setting_name="IFC4 Reference View"):
def download_ifc(self, file_path=None,ifc_setting_name="IFC2x3 Coordination View 2.0"):
"""
Download IFC file from the model and save it to the file path
:param file_path: the path to save the IFC file e.g: "C:/Users/<your name>/Downloads/IFC.ifc"
:param ifc_setting_name: the setting name of IFC format, see more at : https://help.autodesk.com/view/RVT/2024/ENU/?guid=GUID-E029E3AD-1639-4446-A935-C9796BC34C95
:return:
"""
result_dict = self.download_stream_ifc(ifc_setting_name)
if result_dict is None:
raise Exception("Can not download IFC file.")
raise Exception("Can not download IFC file.Please check stream download process.")
if file_path is None:
file_path = result_dict["file_name"]
# in case file exits, remove it
Expand All @@ -132,10 +147,11 @@ def download_ifc(self, file_path=None,ifc_setting_name="IFC4 Reference View"):
f.write(bytes_io.read())
return file_path

def translate_to_ifc(self, ifc_setting_name="IFC4 Reference View")-> requests.Response:
def translate_to_ifc(self, ifc_setting_name="IFC 2x3 GSA Concept Design BIM 2010")-> requests.Response:
"""
Run a Job to translate the model to IFC format:
https://aps.autodesk.com/blog/export-ifc-rvt-using-model-derivative-api
More about ifc setting name : https://help.autodesk.com/view/RVT/2024/ENU/?guid=GUID-E029E3AD-1639-4446-A935-C9796BC34C95
:return:
"""
url = 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job'
Expand Down
6 changes: 3 additions & 3 deletions APSToolkitPython/src/test/test_derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def test_translate_to_ifc(self):
## Right Urn
self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLmRnRkswLXZqVFlLRS1tUDA3Z3o3WUE_dmVyc2lvbj0z"
derivative = Derivative(self.urn, self.token)
response = derivative.translate_to_ifc()
response = derivative.translate_to_ifc("IFC 2x3 GSA Concept Design BIM 2010")
status_code = response.status_code
self.assertEqual(status_code, 200)
def test_download_ifc(self):
self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLnc3cjBxY1BRUzNXVDczeGV6dC13SEE_dmVyc2lvbj0z"
self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLmRnRkswLXZqVFlLRS1tUDA3Z3o3WUE_dmVyc2lvbj0z"
derivative = Derivative(self.urn, self.token)
filepath = derivative.download_ifc()
filepath = derivative.download_ifc("gsa_report.ifc")
# check size
self.assertNotEqual(os.path.getsize(filepath), 0)

Expand Down

0 comments on commit 51a1edd

Please sign in to comment.