From f5c70a51bcd3e73d2ebed86b08e4956276239394 Mon Sep 17 00:00:00 2001 From: Ryan Sinnet Date: Fri, 1 Jul 2022 13:55:37 +0000 Subject: [PATCH] Remove special characters from part names Replace `"` with `in` in part names since it the quote breaks the generated XML. Also replace `'` with `ft` for consistency. --- onshape_to_robot/onshape_to_robot.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/onshape_to_robot/onshape_to_robot.py b/onshape_to_robot/onshape_to_robot.py index b84d4cd..523994f 100644 --- a/onshape_to_robot/onshape_to_robot.py +++ b/onshape_to_robot/onshape_to_robot.py @@ -48,11 +48,15 @@ def partIsIgnore(name): else: return name not in config['whitelist'] - # Adds a part to the current robot link - + def renamePart(name): + """Remove special characters from part names.""" + return name.replace('"', "in").replace("'", "ft") def addPart(occurrence, matrix): + """Add a part to the current robot link.""" part = occurrence['instance'] + part['name'] = renamePart(part['name']) + part['configuration'] = renamePart(part['configuration']) if part['suppressed']: return