How to accept wonky strings as featurescript inputs?

imants_smidchens
imants_smidchens Member Posts: 84 PRO
edited January 2023 in FeatureScript
Hi! I'm writing a Featurescript that will (hopefully) take an SVG string input, and parse it/convert it into Onshape sketch features, letting users essentially import SVGs through a configuration input. (This would let you integrate configurable logos into your designs, where a user can just upload an SVG in string form, or even have an automated 3rd party application do this through the API!) Unfortunately, the two parameter predicates I had hopes for,
definition.whatever is string
and
isAnything(definition.whatever)

both fail, for different reasons. SVGs contain paired inequalities such as "<path>" but these are invalid string inputs: they just vanish as soon as there's text between two inequality brackets. As far as I can tell, this is true for all string parameter inputs in the featurescript UI, as well as configuration variables set to "text".
The isAnything() predicate can't take an SVG because it's not a featurescript-syntax-approved formula, so that also doesn't work. Enclosing the SVG string with quote marks also doesn't work, since there are nested strings as a part of the SVG, and this would necessitate that users manually replace every " with \" (also not really an option)

Suggestions?

Answers