Page 1 of 3

Editable texts in SVG templates

Posted: Fri Dec 30, 2011 12:38 am
by yorik
I just added editable texts support in SVG templates, use it like this:

- in your SVG templates, add freecad:editable="TextName" attributes to <text> entities, to mark them as editable
- Page objects in FreeCAD have a "EditableTexts" property, that contain strings, 1 for each editable text
- When changing the template of a page, available editable texts are picked and added to the above property automatically
- Edit the property, change the texts, and press recompute, and the texts are updated in the SVG view

I also added editable texts to the default A3_Landscape template, but, for some reason I still didn't find out, you need to edit the Template property, and put the complete path to the A3_Landscape.svg file, just leaving "A3_Landscape.svg" doesn't work. There might still be more bugs, but I think it's in shape for testing already.

Hope you'll like!

Re: Editable texts in SVG templates

Posted: Fri Dec 30, 2011 1:27 am
by yorik
already fixed some bugs, it now picks the strings correctly when loading the template the first time... Here is how it works:

Image

Re: Editable texts in SVG templates

Posted: Fri Dec 30, 2011 5:31 pm
by NormandC
Nice! :)

Can't wait to try that, but at the moment it has not been copied to SVN and the Ubuntu PPA is still based on it. I won't change it for now, since a few people are still working in SVN and Git does not have their commits...

Re: Editable texts in SVG templates

Posted: Fri Dec 30, 2011 7:48 pm
by yorik
Yes, I think for a couple of weeks we'll be a bit "inbetween"...

Re: Editable texts in SVG templates

Posted: Tue Jan 03, 2012 12:46 am
by NormandC
OK, it finally got into the Ubuntu PPA. Cool! :) I can now stop my feeble attempts to produce a python script for that! :lol:

Re: Editable texts in SVG templates

Posted: Tue Jan 03, 2012 9:05 pm
by xav83
greeting,
how to make a macro to fill " editable texts " automatically for instance?
to publish the Name for example .

Thanks
Xavier G.

Re: Editable texts in SVG templates

Posted: Tue Jan 03, 2012 9:37 pm
by yorik
Well, if you always use the same template, it's easy. You must just know the order of the words. For example if you want to change the first word, you use texts[0] below. The second word, texts[1], etc... (Later we can do a better interface for that)

Code: Select all

# this macro must be run with the Page object selected
import FreeCAD, FreeCADGui
page = FreeCADGui.Selection.getSelection()[0]
texts = page.EditableTexts
texts[0] = "My New Name"
texts[1] = "03 Jan 2012"
texts[7] = ""
texts[8] = "My Drawing"
# etc...
page.EditableTexts = texts
FreeCAD.ActiveDocument.recompute()

Re: Editable texts in SVG templates

Posted: Fri Jan 06, 2012 1:08 am
by triplus
Hi!

I just tested this with my custom A4 drawing template that i created in Inkscape and it works great! It's so easy to change information "on the fly" in template now. Thanks!

Re: Editable texts in SVG templates

Posted: Fri Jan 06, 2012 1:36 am
by NormandC
Hi triplus,

How about sharing your template (if you don't mind)? :)

The Drawing Templates wiki page could use some A4 templates! ;)

(and some A and B too for people in North America, but I'm slowly working on it!)

Re: Editable texts in SVG templates

Posted: Sun Jan 08, 2012 2:27 pm
by triplus
- in your SVG templates, add freecad:editable="TextName" attributes to <text> entities, to mark them as editable
I did noticed one thing.
"XML Parsing Error: prefix not bound to a namespace"
FireFox seems to be very strict it does not show SVG image and complains.