Annotation does not accept double quote character

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
BrettCA
Posts: 9
Joined: Thu Jun 20, 2019 9:28 pm

Annotation does not accept double quote character

Post by BrettCA »

The TechDraw annotation text field does not accept the double quote character. Report View shows the following error:

Code: Select all

<class 'SyntaxError'>: ('invalid syntax', ('<string>', 1, 91, 'FreeCAD.getDocument("fan_bock_rev_E___TechDraw").getObject("Annotation").Text = [u"1/4" NPT", ]\n'))
I was trying to add a call out for a 1/4" NPT thread and it choked on the ".

Interestingly, the text field does accept a single quote character without throwing an error and automatically escapes it to \'

Since the double quote character " is often used to indicate inches, this could be kinda important.

OS: macOS Sierra (10.12)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18213 (Git)
Build type: Release
Branch: master
Hash: 22babc09954ac6fda9135ee71d68550921659b1c
Python version: 3.7.3
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)
Syres
Veteran
Posts: 2902
Joined: Thu Aug 09, 2018 11:14 am

Re: Annotation does not accept double quote character

Post by Syres »

Purely as a workaround, you could use the Python Console and copy the following into it to correct your example:

Code: Select all

FreeCAD.getDocument("fan_bock_rev_E___TechDraw").getObject("Annotation").Text = [u'1/4" NPT', u'', ]
Syres
Veteran
Posts: 2902
Joined: Thu Aug 09, 2018 11:14 am

Re: Annotation does not accept double quote character

Post by Syres »

A further workaround, if I had numerous Annotations to input, then I would use something like 'inch' when inputting them in the GUI and when complete, save the file (so you can always step back) and then run the following macro to iterate through them and change them to a double quote.

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD
doc = FreeCAD.ActiveDocument
objs = FreeCAD.ActiveDocument.Objects

for obj in objs:
    if obj.TypeId == "TechDraw::DrawViewAnnotation":
        res = [sub.replace('inch', '"') for sub in obj.Text] 
        obj.Text = res
OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18234 (Git)
Build type: Release
Branch: master
Hash: 3af5d97e9b2a60823815f662aba25422c4bc45bb
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Annotation does not accept double quote character

Post by wandererfan »

BrettCA wrote: Mon Sep 16, 2019 12:58 am The TechDraw annotation text field does not accept the double quote character. Report View shows the following error:
All I can offer short term is a work around: &quot; will display as " without breaking anything.

< and > also mess up the internal HTML representation and must be entered as &lt; and &gt;.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Annotation does not accept double quote character

Post by reox »

There is something similar going on with the templates.
If you enter something like "&" as text for a template field, it will be displayed as HTML:
2019-09-16-214919_577x374_scrot.png
2019-09-16-214919_577x374_scrot.png (19.83 KiB) Viewed 1684 times
(sorry for stealing the thread but it looks to be the same topic ;))
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Annotation does not accept double quote character

Post by wandererfan »

reox wrote: Mon Sep 16, 2019 7:50 pm If you enter something like "&" as text for a template field, it will be displayed as HTML
Same behaviour in v0.18. I'll take a look.
Syres
Veteran
Posts: 2902
Joined: Thu Aug 09, 2018 11:14 am

Re: Annotation does not accept double quote character

Post by Syres »

wandererfan wrote: Tue Sep 17, 2019 12:19 am
reox wrote: Mon Sep 16, 2019 7:50 pm If you enter something like "&" as text for a template field, it will be displayed as HTML
Same behaviour in v0.18. I'll take a look.
@wandererfan, maybe I'm being a little paranoid (I just saw your PR2530) but I'm guessing @reox is on a Linux box because I went back to the last 0.19 build I have that the templates were behaving on Windows and I get a polar opposite result. In that, if I enter Test & Draw into the template field editor, the change is accepted and is displayed correctly. It's only when I open the field again to change the contents that the HTML is shown as per screenshot:
TemplateFieldHTML.jpg
TemplateFieldHTML.jpg (26.27 KiB) Viewed 1623 times
I wouldn't want a compounded problem on top of the existing one if you can appreciate when I'm coming from.

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.16935 (Git)
Build type: Release
Branch: master
Hash: aa9cd0d91c1db88bf2999a08987a31894e67f7f1
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Annotation does not accept double quote character

Post by wandererfan »

Syres wrote: Tue Sep 17, 2019 3:22 pm In that, if I enter Test & Draw into the template field editor, the change is accepted and is displayed correctly. It's only when I open the field again to change the contents that the HTML is shown as per screenshot:
Yes, that is the behaviour all the way back to v0.18 (maybe even v0.17). The pop-up dialog is converting the "special" characters to the HTML substitutes. You have to do it twice to see the error.
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Annotation does not accept double quote character

Post by wandererfan »

BrettCA wrote: Mon Sep 16, 2019 12:58 am The TechDraw annotation text field does not accept the double quote character. Report View shows the following error:
This should be fixed by git commit dbf0644b6.
doubleQuoteInAnnotation.png
doubleQuoteInAnnotation.png (7.56 KiB) Viewed 1542 times
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Annotation does not accept double quote character

Post by wandererfan »

reox wrote: Mon Sep 16, 2019 7:50 pm If you enter something like "&" as text for a template field, it will be displayed as HTML
This should be fixed by git commit c04a823d23.
AmpersandInPopUp.png
AmpersandInPopUp.png (11.5 KiB) Viewed 1538 times
AmpersandInTemplate.png
AmpersandInTemplate.png (32.07 KiB) Viewed 1538 times
Post Reply