TechDraw Template Autocompletion

Discussions about the development of the TechDraw workbench
catman
Posts: 232
Joined: Fri Jan 11, 2019 10:42 pm

TechDraw Template Autocompletion

Postby catman » Mon Jul 27, 2020 1:28 am

With the tutorial in the wiki I have now a very nice custom template for drawings which I am very fond of. :D

Now I have looked for ways to automatically fill in some of those fields. Obvious candiates would be
* sheet number
* filename
* scale
* creation date
* author

I found this post about changing it from script, but this was for a different use case.

I am looking for those values being filled automatically every time when I load a template for a file. Did anyone achive something like this and can tell how this can be done?
User avatar
Kunda1
Posts: 7679
Joined: Thu Jan 05, 2017 9:03 pm

Re: TechDraw Template Autocompletion

Postby Kunda1 » Mon Jul 27, 2020 2:23 am

Mod edit: Moved thread to TD subforum
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
wandererfan
Posts: 4041
Joined: Tue Nov 06, 2012 5:42 pm

Re: TechDraw Template Autocompletion

Postby wandererfan » Mon Jul 27, 2020 2:26 pm

catman wrote:
Mon Jul 27, 2020 1:28 am
Now I have looked for ways to automatically fill in some of those fields.
issue #3911. No ETA.
cadcam
Posts: 43
Joined: Thu Apr 02, 2020 10:39 am

Re: TechDraw Template Autocompletion

Postby cadcam » Mon Jul 27, 2020 2:58 pm

Relatedly I have been looking at trying to simplify the filling in of a template
from a spreadsheet, which inturn is auto filled from defaults, using a Macro. I would like to know if I am
approaching this the correct way or so if someone has already done this, or more probably neater/better way, before?

Some of the problems still to be solved, in no particular order

1) Ensuring that each page is automatically associated with a specific spreadsheet, without having
obtain the page number/same in macro.

2) Is it possible to copy/paste and attach User_info to a page, rather than overall file.

3) Make spreadsheet more general by Auto loading with system known parareters, e.g. user name, pagesize, part weight but still allow
included file to be edited

4) Extend for Assembly drawings

+ plenty of others..


Many Thanks

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22111 (Git)
Build type: Release
Branch: master
Hash: cb2099aa6bb287a8d7843eb70684cce79bdef26b
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)
Attachments
dut_Drawing_Update_template.FCMacro
(2.96 KiB) Downloaded 3 times
fitting2_demo.FCStd
(691.09 KiB) Downloaded 3 times
catman
Posts: 232
Joined: Fri Jan 11, 2019 10:42 pm

Re: TechDraw Template Autocompletion

Postby catman » Mon Jul 27, 2020 4:04 pm

cadcam wrote:
Mon Jul 27, 2020 2:58 pm
Relatedly I have been looking at trying to simplify the filling in of a template
from a spreadsheet, which inturn is auto filled from defaults, using a Macro. I would like to know if I am
approaching this the correct way or so if someone has already done this, or more probably neater/better way, before?
interesting approach. How do you generate the spreadsheet in the first place? For example if you need to generate a new part, starting with a blank sheet, where does it take its data from?
cadcam
Posts: 43
Joined: Thu Apr 02, 2020 10:39 am

Re: TechDraw Template Autocompletion

Postby cadcam » Mon Jul 27, 2020 4:39 pm

Currently working with 'startparts', with spreadsheets/associated drawings, material,.... etc preset,
so that when you select new part, via a macro, it loads it and then changes the filename etc.
so that you don't override etc. Thus the basic spreadsheet is pre-loaded, however as noted still not sure how to generate for multiple drawing sheets, although I am thinking as a backup to store the info in the spreadsheet and get the macro to cope with finding the
correct template

Best Wishes
catman
Posts: 232
Joined: Fri Jan 11, 2019 10:42 pm

Re: TechDraw Template Autocompletion

Postby catman » Fri Jul 31, 2020 10:11 am

When swapping the template to another one with the property field value Tempalte/Template today all edited filed parameters are lost.
Since the data has been added manually and is stored in TechDraw, is that situation something to not thow away the edited values, so if a new template is loaded (that likely has the same value names) the stored values could be applied?

Use case: Allows to switch format any time.
Description: When "MyFormat_A4" is getting too small, its possible to switch to "MyFormat_A3" without loosing all edited data. This is because its very likely that most people use in all "MyFormat" templates the same fields.
User avatar
wandererfan
Posts: 4041
Joined: Tue Nov 06, 2012 5:42 pm

Re: TechDraw Template Autocompletion

Postby wandererfan » Fri Jul 31, 2020 1:16 pm

catman wrote:
Fri Jul 31, 2020 10:11 am
Since the data has been added manually and is stored in TechDraw, is that situation something to not thow away the edited values, so if a new template is loaded (that likely has the same value names) the stored values could be applied?
This would be nice. The first obstacle is that there is no guarantee the field names in template A are the same as the field names in Template B.

This could be done via a 2 part macro along these lines:

Code: Select all

# part1:  macro to save values
>>> p = App.ActiveDocument.Page
>>> t = p.Template
>>> fieldDict = t.EditableTexts
## save fieldDict somewhere

# change templates

## part2:  macro to replace values
# retrieve fieldDict from somewhere 
>>> fieldDict['AUTHOR_NAME'] = 'James Bond'
>>> t.EditableTexts = fieldDict
catman
Posts: 232
Joined: Fri Jan 11, 2019 10:42 pm

Re: TechDraw Template Autocompletion

Postby catman » Sat Aug 01, 2020 9:41 am

wandererfan wrote:
Fri Jul 31, 2020 1:16 pm
The first obstacle is that there is no guarantee the field names in template A are the same as the field names in Template B.
That is true, but if some are not present, nothing is lost except a few bytes unused data. If the behaviour is know, however its easy for people doing their own templates to just use the same names. And I guess, most people who are serious about their models are going to customize the default templates anyway.

I'll check out the code, thanks
User avatar
vanuan
Posts: 179
Joined: Wed Oct 24, 2018 9:49 pm

Re: TechDraw Template Autocompletion

Postby vanuan » Sat Aug 01, 2020 7:08 pm

Let's think at the higher level.

Should there be a concept of TechDraw "documents/workbooks"? Could anyone provide a use case where user would want a single TechDraw page, say sheet 19 of 30 designed in FreeCAD?

Are there any standards/file formats of technical drawing documents other than sheet-level graphical symbols like title block, line width, dimensions, etc?

Is it realistic to prepare all technical drawings in FreeCAD?

Depending on the answers, we could design a "workbook" object which would have a single template and guarantee field names to be the same, provide automatic numbering, the title page, legends, consistent scale, and so on

In addition, it's possible to ship embedded templates, where field names are standardized. Or we could validate templates and force users to design them so that they have predefined fields

Unfortunately, I have a feeling that FreeCAD has a different philosophy - it doesn't help users with enforcing standards or consistency. Instead, FreeCAD provides some tooling on top of which you build your own software. I think this philosophy sucks