Skip to content

Commit

Permalink
Using /metadata API path (see #46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregwar committed Feb 4, 2023
1 parent 91e3d42 commit ea2f26c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion onshape_to_robot/onshape_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def invoke():

def part_get_metadata(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)+'/metadata', query={'configuration': configuration})
return self._api.request('get', '/api/metadata/d/' + did + '/m/' + mid + '/e/' + eid + '/p/'+escape_slash(partid), query={'configuration': configuration})

return json.loads(self.cache_get('metadata', (did, mid, eid, self.hash_partid(partid), configuration), invoke, True))

Expand Down
15 changes: 9 additions & 6 deletions onshape_to_robot/onshape_to_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ def addPart(occurrence, matrix):
else:
metadata = client.part_get_metadata(
part['documentId'], part['documentMicroversion'], part['elementId'], part['partId'], part['configuration'])
if 'appearance' in metadata:
colors = metadata['appearance']['color']
color = np.array(
[colors['red'], colors['green'], colors['blue']])/255.0
else:
color = [0.5, 0.5, 0.5]

color = [0.5, 0.5, 0.5]

# XXX: There must be a better way to retrieve the part color
for entry in metadata['properties']:
if 'value' in entry and type(entry['value']) is dict and 'color' in entry['value']:
rgb = entry['value']['color']
color = np.array(
[rgb['red'], rgb['green'], rgb['blue']])/255.0

# Obtain mass properties about that part
if config['noDynamics']:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="onshape-to-robot",
version="0.3.17",
version="0.3.18",
author="Rhoban team",
author_email="[email protected]",
description="Converting OnShape assembly to robot definition (SDF or URDF) through OnShape API ",
Expand Down

0 comments on commit ea2f26c

Please sign in to comment.