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.

line break in string?

Evan_ReeseEvan_Reese Member Posts: 1,420 PRO
how do I add a line break to a string in FS? Is there a place I can go to see all of the formatting options available?
Evan Reese / Principal and Industrial Designer with Ovyl
Website: ovyl.io

Best Answers

Answers

  • _anton_anton Member, Onshape Employees Posts: 77
    edited October 2021 Answer ✓
    \n
    println("Once upon a midnight dreary, while I pondered, weak and weary,\nOver many a quaint...");
  • Evan_ReeseEvan_Reese Member Posts: 1,420 PRO
    ah! I had a backslash not forward. Thanks!
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Evan_ReeseEvan_Reese Member Posts: 1,420 PRO
    hmm I thought that would solve it, but I'm still getting something else wrong. Here's what I'm trying to do, but it's still all one line:
    reportFeatureInfo(context, id, toString(roundToPrecision(wrapCount, 3) ~ " wraps. \n" ~ toString(roundToPrecision(wrappedDiameter/inch, 3) ~ " in wrapped diameter.")));

    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Alex_KempenAlex_Kempen Member Posts: 219 EDU
    Answer ✓
    reportFeatureInfo and reportFeatureWarning messages don't handle line breaks and other methods of formatting like \b (for bold). On the other hand, it is possible to use template strings to display units properly, but that doesn't really help a whole lot with your use case.
  • Evan_ReeseEvan_Reese Member Posts: 1,420 PRO
    Didn't know about template strings. Thanks, Alex! I feel as though I've seen features with line breaks in the reportFeatureInfo(), but it was a while ago and maybe that's changed. I think it's nice to have the option to format those.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Evan_ReeseEvan_Reese Member Posts: 1,420 PRO
    @Alex_Kempen
    I'm trying to implement the templateString, but it doesn't seem to respect the document units. I'm still getting meters. This is the code and result. Any ideas?
            var wrappedDiaString = templateString({'template' : '#dia#  wrapped diameter.', 'dia' : wrappedDiameter});
    
            // creating the messages
            reportFeatureInfo(context, id, toString(roundToPrecision(wrapCount, 3) ~ " wraps. " ~ toString(wrappedDiaString)));

    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,120
    Sorry, TemplateString is for tables only.  And in any case, as soon as you call toString on it, it becomes a plain old string.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Alex_KempenAlex_Kempen Member Posts: 219 EDU
    Yeah, @ilya_baran is right. I guess I saw someone using template strings to format output once and assumed it worked without personally trying it.
  • Evan_ReeseEvan_Reese Member Posts: 1,420 PRO
    Got it. So is the best way to display valueWithUnits in a human way to just divide the value by whatever units I want to display and round it?
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,120
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Evan_ReeseEvan_Reese Member Posts: 1,420 PRO
    Thanks, Ilya
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • chadstoltzfuschadstoltzfus Member, Developers Posts: 81 PRO
    I suppose if you really want to have error info to sift through you could throw out some println() or debug statements to neatly display the information you want. However since this display in the FeatureScript notices panel it's really more useful for the dev as opposed to the user, which it looks like is your target with this error message.   
  • Evan_ReeseEvan_Reese Member Posts: 1,420 PRO
    Yep. this is meant to be user-facing. We're working on a fabric that wraps around a spindle and I'm calculating how many rotations a given length of fabric takes to roll up and the diameter of the final spooled fabric. I'm using FS to do some calculations since it sounded easier to me than trying to set up a spreadsheet for it, and it's nice to have it right in Onshape where we're working. I'm not actually using the feature for modeling or setting variables.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.