[Improvement] Autofill name and date in template

Discussions about the development of the TechDraw workbench
User avatar
wandererfan
Posts: 3319
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Improvement] Autofill name and date in template

Postby wandererfan » Mon Jan 21, 2019 4:38 pm

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
Posts: 2328
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Autofill name and date in template

Postby vocx » Wed Mar 20, 2019 2:08 am

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.
vocx
Posts: 2328
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Autofill name and date in template

Postby vocx » Wed Mar 20, 2019 2:23 am

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
reox
Posts: 684
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [Improvement] Autofill name and date in template

Postby reox » 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 :)
vocx
Posts: 2328
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Autofill name and date in template

Postby vocx » Sat Sep 21, 2019 4:17 pm

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.
User avatar
wandererfan
Posts: 3319
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Improvement] Autofill name and date in template

Postby wandererfan » Sat Sep 21, 2019 5:58 pm

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: 684
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [Improvement] Autofill name and date in template

Postby reox » Sat Sep 21, 2019 6:03 pm

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
Posts: 2328
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Autofill name and date in template

Postby vocx » Sat Sep 21, 2019 6:04 pm

Awesome!

As I said, just ask wandererfan, he knows!
reox
Posts: 684
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [Improvement] Autofill name and date in template

Postby reox » 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.
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
Posts: 3319
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Improvement] Autofill name and date in template

Postby wandererfan » Sun Sep 22, 2019 4:07 pm

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.