diff --git a/APSToolkitPython/setup.py b/APSToolkitPython/setup.py index 25a9f27..2375ee6 100644 --- a/APSToolkitPython/setup.py +++ b/APSToolkitPython/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name="aps-toolkit", - version="1.1.0", + version="1.1.1", author="chuong mep", author_email="chuongpqvn@gmail.com", description="A Toolkit Autodesk Platform Services for Python", diff --git a/APSToolkitPython/src/aps_toolkit/Derivative.py b/APSToolkitPython/src/aps_toolkit/Derivative.py index 5763c1b..33bbaf9 100644 --- a/APSToolkitPython/src/aps_toolkit/Derivative.py +++ b/APSToolkitPython/src/aps_toolkit/Derivative.py @@ -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: @@ -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//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 @@ -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' diff --git a/APSToolkitPython/src/test/test_derivative.py b/APSToolkitPython/src/test/test_derivative.py index c87e362..1bfca29 100644 --- a/APSToolkitPython/src/test/test_derivative.py +++ b/APSToolkitPython/src/test/test_derivative.py @@ -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)