Skip to content

Commit

Permalink
Merge pull request #110 from csamid/standard-content
Browse files Browse the repository at this point in the history
Add standard content mass properties retrieval
  • Loading branch information
Gregwar authored Jun 3, 2024
2 parents 03b041b + 53dcfec commit 10cebbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion onshape_to_robot/onshape_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_url(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))
8 changes: 6 additions & 2 deletions onshape_to_robot/onshape_to_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down

0 comments on commit 10cebbc

Please sign in to comment.