Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
How to accept wonky strings as featurescript inputs?
imants_smidchens
Member Posts: 63 EDU
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?
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?
Tagged:
0
Answers
Really neat idea! Looking forward to using it.
Looks like you already tried the first two things that came to my mind.
You could use a 3rd party to replace every " with \". Here is a 3rd party that can do it:
https://tools.knowledgewalls.com/online-escape-single-or-double-quotes-from-string
In the feature, you can have a pop up message with a link to the conversion site.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴