Access template fields from console?

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
ChemicalCoal
Posts: 24
Joined: Sun May 09, 2021 3:38 am

Access template fields from console?

Post by ChemicalCoal »

After inserting a template, there is the green button to edit the text inside the template.

Is there a way to edit this text from the console?
I might have completely missed something.
Useful for a macro that inputs creation date, description, sheet number, etc.

Might also be interesting if these values are provided as a property under the "Page" object.
For instance two templates with the same TextNames could be swapped seamlessly.
Or could be controlled from a spreadsheet, maybe weight from Body.Shape.Volume as an example.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Access template fields from console?

Post by Roy_043 »

Code: Select all

doc = App.ActiveDocument
obj = doc.getObject("Template")
dict = obj.EditableTexts
dict["Designed_by_Name"] = "Xyz"
obj.EditableTexts = dict
dan-miel
Posts: 391
Joined: Thu Sep 13, 2018 12:29 am
Location: Spokane WA. USA

Re: Access template fields from console?

Post by dan-miel »

ChemicalCoal wrote: Tue Nov 15, 2022 5:46 am Is there a way to edit this text from the console?
@ChemicalCoal
This post might be of interest to you. https://forum.freecadweb.org/viewtopic.php?f=22&t=73936
ChemicalCoal
Posts: 24
Joined: Sun May 09, 2021 3:38 am

Re: Access template fields from console?

Post by ChemicalCoal »

dan-miel wrote: Sun Nov 27, 2022 12:26 am This post might be of interest to you. https://forum.freecadweb.org/viewtopic.php?f=22&t=73936
@Roy_043
Interesting to see your approach on this,
I'm thinking about storing Part Number, Material, etc. In a spreadsheet under the part container and using a macro to update the drawing(s) upon needing to print them. But doing something slightly less "free-form" like what you've done might be better.

As I see it there end up being a variety of things that need updating in the drawing but don't really work in the template. For example the revision block works much better being inserted from a spreadsheet than part of the template, allowing it to expand as needed.

Updating scales, sheet numbers, adding the scale to captions for views that don't match the sheet scale, re-label section views so they are in alphabetical order.

Maybe something fancy like verifying any anodize/coating is compatible with the material, or adding a draft watermark if the drawing is not "reviewed/approved" for release.
dan-miel
Posts: 391
Joined: Thu Sep 13, 2018 12:29 am
Location: Spokane WA. USA

Re: Access template fields from console?

Post by dan-miel »

ChemicalCoal wrote: Sun Nov 27, 2022 6:05 am I'm thinking about storing Part Number, Material, etc. In a spreadsheet under the part container and using a macro to update the drawing(s) upon needing to print them. But doing something slightly less "free-form" like what you've done might be better.
Hi ChemicalCoal,
There are several ways to do this. When I was working on this it was a PDM project which I've given up on. From my experience, properties need to be able to be used in several programming languages and databases. As we saw that was failing here. so I modified the program so if a property name has an illegal character, it will error out and let a person change the name using a text editor, I found that was pretty easy.
I'm not sure if your other comments were for me.
I put the FileProperties on Github, you can download the code here. https://github.com/DanMiel/FileProperties.
Dan
dan-miel
Posts: 391
Joined: Thu Sep 13, 2018 12:29 am
Location: Spokane WA. USA

Re: Access template fields from console?

Post by dan-miel »

ChemicalCoal wrote: Sun Nov 27, 2022 6:05 am As I see it there end up being a variety of things that need updating in the drawing but don't really work in the template. For example the revision block works much better being inserted from a spreadsheet than part of the template, allowing it to expand as needed.

Updating scales, sheet numbers, adding the scale to captions for views that don't match the sheet scale, re-label section views so they are in alphabetical order.
OK CC, I added some sheets and I see what you mean. I can/have written the code to add Sheet numbers formatted "Sheet 2 of 4" and update sheet scales, but they will only work on your files if you use the same variable name as I have. Same as updating the view scales. IMO These should be tied to the sheets and views themself.
Dan
dan-miel
Posts: 391
Joined: Thu Sep 13, 2018 12:29 am
Location: Spokane WA. USA

Re: Access template fields from console?

Post by dan-miel »

I don’t know if anyone will find this useful, but it updates the properties on all the pages. Maybe the spread sheets are better.
To use.
Unzip the File Properties folder from the zip file and copy it to your FreeCAD/Mod folder.
Open a FreeCAD file and add one or more Tech Drawings to it.
Select File Properties from the Workbench dropdown. The icon is four red squares.
A dialog with an empty table will show.
Press the “Read from Drawing” button.
The table will fill with properties from your page 1 drawing.
To fill in the file name, select a row and press “File Name, same with Date.
Change other values and press Write to “drawing”, Fields in all pages will be updated.
To get the sheet numbers and sheets scales to populate: When you started the program there where two objects made, one is called Properties and the other is AliasIDs, they are a gray square Icon in the tree. Highlight the AliasIds and in the Data tab change the value to the name you have in your drawing for that property. They should update when you run the Write to drawing.
To copy the properties to another file just copy the two objects and paste them into the next file.
Dan
Attachments
Dialog.JPG
Dialog.JPG (43.7 KiB) Viewed 926 times
FileProperties Rev7.zip
(46.44 KiB) Downloaded 41 times
Post Reply