[Improvement] Autofill name and date in template

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Autofill name and date in template

Post by wandererfan »

carbonblueGTS wrote: Mon Jan 21, 2019 3:23 pm Is there a work-around for this?
No work around. Needs a code change (use Gui::InputField instead of QLineEdit).
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Autofill name and date in template

Post by vocx »

carbonblueGTS wrote: Sun Jan 20, 2019 5:33 am
vocx wrote: Sat Oct 20, 2018 7:37 am A Preference object associated with a model. Or as I suggested, a Spreadsheet that has key-value pairs with different information. Then the specific workbenches would read the information off this spreadsheet.
How would you go about doing that? I have a spreadsheet with all the information. I was following this template: https://www.freecadweb.org/wiki/Manual: ... readsheets but for it to work, I have to be able to enter an expression. Editable fields don't allow for expressions, so I'm stuck. Thoughts?
To clarify, at the moment (March 2019) it's not possible to use Spreadsheet values to populate the editable fields of the Techdraw templates. This is a desired feature that could be added eventually.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Autofill name and date in template

Post by vocx »

wandererfan wrote: Mon Jan 21, 2019 2:24 pm Could somebody make a Feature Request for this so it doesn't get overlooked in v0.19 development?
It has been opened as issue #3911.
Author and Company are available in Preferences>General>Document. Date is easy, but it shouldn't update automatically, just when the Page is changed? Page number could be the sequence number of the Page in the Document, but I'm not sure that is necessarily the desired Page number.
Yes, I think Date is especially sensitive. You wouldn't want to automatically overwrite an old date in the template, as you'd probably want to see when the drawing was originally created. The user should confirm through a button or interface option whether he or she wants to update the Date and other editable fields. Auto-filling the date makes sense for documents in progress, as the document may be modified over several days. On the other hand, drawings that are "finished" and not subject to further modification should have an option to disable auto-filling so the date and other parameters aren't auto-filled.
Not sure how we can enforce using the correct names for Template fields. I guess if you don't use the right names in your custom template then you don't get to use the auto-entry feature.
Exactly as you say. You can't force people to use the template fields. However, in the wiki, you'd write the necessary documentation and instruct the user to use the standard field names with their own templates, in order for the auto filling to work. This could be mentioned in a tutorial or some clear instructions that describe the creation of custom templates. https://www.freecadweb.org/wiki/TechDraw_TemplateHowTo
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [Improvement] Autofill name and date in template

Post by reox »

Is it possible right now to fill the fields of the template via a python macro?
If I edit a field, I do not see it in the python console. Maybe a python interface for the template fields should be added as well :)
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Autofill name and date in template

Post by vocx »

reox wrote: Sat Sep 21, 2019 4:11 pm Is it possible right now to fill the fields of the template via a python macro?
If I edit a field, I do not see it in the python console. Maybe a python interface for the template fields should be added as well :)
The templates are SVGs, which are text files, so I think it's pretty possible to have an interface to edit them directly. Maybe using sax.xml, which is what importSVG in Draft uses to parse an SVG.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Autofill name and date in template

Post by wandererfan »

vocx wrote: Sat Sep 21, 2019 4:17 pm The templates are SVGs, which are text files, so I think it's pretty possible to have an interface to edit them directly. Maybe using sax.xml, which is what importSVG in Draft uses to parse an SVG.
No need for the elephant gun! :)
reox wrote: Sat Sep 21, 2019 4:11 pm Is it possible right now to fill the fields of the template via a python macro?
Sure.

Code: Select all

>>> p = App.ActiveDocument.Page
>>> t = p.Template
>>> et = t.EditableTexts
>>> et["FC-Title"] = "The title of my page"
>>> t.EditableTexts = et
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [Improvement] Autofill name and date in template

Post by reox »

wandererfan wrote: Sat Sep 21, 2019 5:58 pm

Code: Select all

>>> p = App.ActiveDocument.Page
>>> t = p.Template
>>> et = t.EditableTexts
>>> et["FC-Title"] = "The title of my page"
>>> t.EditableTexts = et
Nice! I had to create many drawings lately with almost equal settings, that would have saved me some time :mrgreen:
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Autofill name and date in template

Post by vocx »

Awesome!

As I said, just ask wandererfan, he knows!
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [Improvement] Autofill name and date in template

Post by reox »

Btw are the keys for the EditableText always the same in all templates? Is this defined somewhere in the Wiki?
If there were some standard keys, you could easily use a macro to fill the fields. I wrote something like that yesterday.
The macro itself is very unspectacular, but maybe this is something not everyone knows:

Code: Select all

from fractions import Fraction
t = App.ActiveDocument.Template  # FIXME this might not always be the case!
page = t.InList[0]  # FIXME: is the page always the only one in the InList?
scale = Fraction.from_float(1.0 / page.Scale)
t.EditableTexts['SCALE'] = '{} : {}'.format(scale.numerator, scale.denominator)
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Autofill name and date in template

Post by wandererfan »

reox wrote: Sun Sep 22, 2019 2:45 pm Btw are the keys for the EditableText always the same in all templates? Is this defined somewhere in the Wiki?
If there were some standard keys, you could easily use a macro to fill the fields. I wrote something like that yesterday.
I like the macro!

The keys are up to the Template author. I don't know of any way except persuasion to convince people to use standard names.

Then you run into different languages. If a French user wants to use Titre, Auteur, Numero de Piece, etc the macro is not going to find anything.

Having said that, the various standards do define what's supposed to appear in the text block, but they probably don't specify what to call the field.
Post Reply