Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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 can I use FeatureScript to split a string into each letter to make a new extrusion for each?

hayley_felkinshayley_felkins Member Posts: 2
This is for a very particular project, I am trying to make a program that will translate typed print letters into Braille. I have a rough translation of the 26 lowercase English alphabet letters, and I can move the starting point by changing the X, Y, Z coordinates. However I am stuck when I try to split multiple letters up to make it into a translated phrase.

I'm not great with FeatureScript yet, so I've probably done things a very roundabout way, but does anyone have ideas for how I can split the phrases up to translate each letter at a time?

I found document a while back with a script that turned it into a matrix, but I couldn't make it work, and I'm really not sure what to do next.

Here is the file with just the current trial, the tab labeled "Braille Letter" is most recent, with just lowercase letter translation, where "Braille String" has my past attempt at splitting the string, copied from some random foum document.

https://cad.onshape.com/documents/59ff6e21c0a8d4246c988a2e/w/ecb6957e6d41000642221781/e/4e757e51df525a4b34eaccfe


Full disclosure: this is for a university assignment, but honestly I'm going well beyond the requirements by making this script, and my prof doesn't know how to solve this problem either! Any help will be appreciated and disclosed to the professor so it's not plagiarism :)

Best Answer

  • Alex_KempenAlex_Kempen Member Posts: 244 EDU
    Answer ✓
    To take things a step further, if you do want to print out entire strings at once, you're probably going to want to use a for loop to make your code more readable. Furthermore, simplifying your code using loops is probably a good idea. So, here's one way to do it:
    https://cad.onshape.com/documents/4c21d0c3c89c0a81aadfdac6/w/a7ccf556a74ce09cd04151e0/e/92fb63693c2c0fdd2445dd9e

    Obviously, my code is a bit complicated, but it also greatly simplifies your ~500 lines of code into about 20 or so. You might have a bit easier of a time understanding what is going on if you first take a look at the info on maps and arrays here, and try to see how those principles are applied in the code I wrote. You can also brush up on for loops and for each loops, and take a look at some of the other code examples I have in my utilities document. Hopefully this helps a bit!
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



Answers

  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    There's a splitIntoCharacters function that sounds like what you want. It makes an array out of the characters, so you could process them with a for loop or something.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Alex_KempenAlex_Kempen Member Posts: 244 EDU
    Answer ✓
    To take things a step further, if you do want to print out entire strings at once, you're probably going to want to use a for loop to make your code more readable. Furthermore, simplifying your code using loops is probably a good idea. So, here's one way to do it:
    https://cad.onshape.com/documents/4c21d0c3c89c0a81aadfdac6/w/a7ccf556a74ce09cd04151e0/e/92fb63693c2c0fdd2445dd9e

    Obviously, my code is a bit complicated, but it also greatly simplifies your ~500 lines of code into about 20 or so. You might have a bit easier of a time understanding what is going on if you first take a look at the info on maps and arrays here, and try to see how those principles are applied in the code I wrote. You can also brush up on for loops and for each loops, and take a look at some of the other code examples I have in my utilities document. Hopefully this helps a bit!
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • hayley_felkinshayley_felkins Member Posts: 2
    To take things a step further, if you do want to print out entire strings at once, you're probably going to want to use a for loop to make your code more readable. Furthermore, simplifying your code using loops is probably a good idea. So, here's one way to do it:
    https://cad.onshape.com/documents/4c21d0c3c89c0a81aadfdac6/w/a7ccf556a74ce09cd04151e0/e/92fb63693c2c0fdd2445dd9e

    Obviously, my code is a bit complicated, but it also greatly simplifies your ~500 lines of code into about 20 or so. You might have a bit easier of a time understanding what is going on if you first take a look at the info on maps and arrays here, and try to see how those principles are applied in the code I wrote. You can also brush up on for loops and for each loops, and take a look at some of the other code examples I have in my utilities document. Hopefully this helps a bit!
    Alex this is EXACTLY what I meant! Thank you so much. This will help me learn a lot. 

Sign In or Register to comment.