From 53dcfec7a1b37d088cd3653a87fb08436e5f04e3 Mon Sep 17 00:00:00 2001 From: csamid Date: Tue, 5 Sep 2023 14:16:30 -0700 Subject: [PATCH] Add standard content mass properties retrieval --- onshape_to_robot/onshape_api/client.py | 8 +++++++- onshape_to_robot/onshape_to_robot.py | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/onshape_to_robot/onshape_api/client.py b/onshape_to_robot/onshape_api/client.py index 37f7d33..725f0cb 100644 --- a/onshape_to_robot/onshape_api/client.py +++ b/onshape_to_robot/onshape_api/client.py @@ -352,4 +352,10 @@ def part_mass_properties(self, did, mid, eid, partid, configuration = 'default') def invoke(): return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+escape_slash(partid)+'/massproperties', query={'configuration': configuration, 'useMassPropertyOverrides': True}) - return json.loads(self.cache_get('massproperties', (did, mid, eid, self.hash_partid(partid), configuration), invoke, True)) + return json.loads(self.cache_get('part_massproperties', (did, mid, eid, self.hash_partid(partid), configuration), invoke, True)) + + def standard_cont_mass_properties(self, did, vid, eid, partid, linkDocumentId, configuration): + def invoke(): + return self._api.request('get', '/api/parts/d/' + did + '/v/' + vid + '/e/' + eid + '/partid/'+escape_slash(partid)+'/massproperties', query={'configuration': configuration, 'useMassPropertyOverrides': True, "linkDocumentId": linkDocumentId, "inferMetadataOwner": True}) + + return json.loads(self.cache_get('standard_massproperties', (did, vid, eid, self.hash_partid(partid), configuration), invoke, True)) diff --git a/onshape_to_robot/onshape_to_robot.py b/onshape_to_robot/onshape_to_robot.py index 9d81035..15cd1e7 100644 --- a/onshape_to_robot/onshape_to_robot.py +++ b/onshape_to_robot/onshape_to_robot.py @@ -133,8 +133,12 @@ def addPart(occurrence, matrix): com = entry['com'] inertia = entry['inertia'] else: - massProperties = client.part_mass_properties( - part['documentId'], part['documentMicroversion'], part['elementId'], part['partId'], part['configuration']) + if part['isStandardContent']: + massProperties = client.standard_cont_mass_properties( + part['documentId'], part['documentVersion'], part['elementId'], part['partId'],config['documentId'], part['configuration']) + else: + massProperties = client.part_mass_properties( + part['documentId'], part['documentMicroversion'], part['elementId'], part['partId'], part['configuration']) if part['partId'] not in massProperties['bodies']: print(Fore.YELLOW + 'WARNING: part ' +