Quotation marks in Shape from text

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
mfraz74
Posts: 158
Joined: Mon Apr 05, 2021 9:19 am
Contact:

Re: Quotation marks in Shape from text

Post by mfraz74 »

mfraz74 wrote: Tue Oct 04, 2022 4:50 pm Just tried to use a quotation mark in the Draft WB's Shape from text tool and get the error:

1.12302 <asm3.main> init_gui.py(14): no solver backend found

Code: Select all

Traceback (most recent call last):
  File "/tmp/.mount_FreeCAdOZlpR/usr/Mod/Draft/drafttaskpanels/task_shapestring.py", line 216, in accept
    Gui.doCommand(o+".String=\"" + string + "\"")
<class 'SyntaxError'>: ('unterminated string literal (detected at line 1)', ('<string>', 1, 65, 'FreeCAD.ActiveDocument.getObject("ShapeString").String="1 x 1/2""', 1, 65))
^CTraceback (most recent call last):
  File "/tmp/.mount_FreeCAdOZlpR/usr/Mod/Tux/NavigationIndicatorGui.py", line 50, in changeEvent
    def changeEvent(self, event):
KeyboardInterrupt

Code: Select all

OS: Ubuntu 22.04.1 LTS (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.21.30492 (Git) AppImage
Build type: Release
Branch: master
Hash: b4578fb3eae842eb510a1bc055d07d369a67ce94
Python 3.10.6, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * sheetmetal 0.2.57
  * Manipulator 1.4.9
  * lattice2 1.0.0
  * fcgear 1.0.0
  * Curves 0.5.8
  * Assembly4 0.11.8
  * fasteners
  * A2plus 0.4.59d
  * ThreadProfile 1.84.0
  * Assembly3 0.11.3
  * VendorParts
Looks like you need to escape the " with a '\'
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Quotation marks in Shape from text

Post by Roy_043 »

https://github.com/FreeCAD/FreeCAD/pull/7558

Workaround for the current (and older) versions: Add the double quotes later by editing the String property in the Property editor.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Quotation marks in Shape from text

Post by onekk »

Only a suggestion to avoid substitution with "escape sequences"

Code: Select all

string = """ " """
print(string)
It usually suffice, without escaping, but you have to see how the string is used.

triple quotes are used around when as example dealing with formatted text with "single quotes" and "double quote" in it.

you could use ''' or """ as terminator, Python is clever enough to detect the Start and end pattern, the problem is that """"""" (in other word a single "double quote" enclosed in "a triple double quote" separator sequence is giving error)

But this is a corner case.

Hope it helps.

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Quotation marks in Shape from text

Post by Roy_043 »

There is probably another corner case: a triple double quote might occur in the string. AFIACT escaping the double quotes does not have similar corner cases.
Post Reply