[SOLVED] Macro or Function to change the Font for every Dimension

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Cuq
Posts: 145
Joined: Tue Jul 06, 2021 10:07 am

[SOLVED] Macro or Function to change the Font for every Dimension

Post by Cuq »

Hello,

I'm looking for a Function (Sorry I Haven't find the option or function to do that) or A macro to Change the Font for every existing Label or Dimension existing in a TechDraw DrawPage.

Thanks a lot
Last edited by Cuq on Wed Apr 26, 2023 1:26 pm, edited 1 time in total.
chrisb
Veteran
Posts: 53939
Joined: Tue Mar 17, 2015 9:14 am

Re: macro or Function to change the Font for every Dimension

Post by chrisb »

It's not an answer but rather a workaround: You can select all these entities and change all their common properties in a single step.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Cuq
Posts: 145
Joined: Tue Jul 06, 2021 10:07 am

Re: macro or Function to change the Font for every Dimension

Post by Cuq »

It's a WorkAround but you cannot select everything with a Ctrl+A , You need to select Each Dimension/Ballon One By one or use a MAcro.

ChatGPT is my new friends :

Code: Select all

import FreeCADGui

# browse all objects in the view
for obj in FreeCADGui.ActiveDocument.Document.Objects:
    if obj.isDerivedFrom("TechDraw::DrawViewDimension"):
       FreeCADGui.Selection.addSelection(obj)
    elif obj.isDerivedFrom("TechDraw::DrawViewLabel"):
       FreeCADGui.Selection.addSelection(obj)
    elif obj.isDerivedFrom("TechDraw::DrawViewBalloon"):
       FreeCADGui.Selection.addSelection(obj)
I'm closed to the result but I cannot modify the value of the Font in this Macro : obj.Font
Last edited by Cuq on Wed Apr 26, 2023 2:06 pm, edited 1 time in total.
chrisb
Veteran
Posts: 53939
Joined: Tue Mar 17, 2015 9:14 am

Re: macro or Function to change the Font for every Dimension

Post by chrisb »

Cuq wrote: Wed Apr 26, 2023 12:53 pm It's a WorkAround but you cannot select eveything with a Ctrl+A , You need to select Each Dimension/Ballon One By one or use a MAcro.
Ctrl+A sure is too much, single selection too tedious. An intermediate possibility is to select ranges with Shift+click, possibly augmented by deselecting single items.
Nevertheless, a macro is the way to go.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Cuq
Posts: 145
Joined: Tue Jul 06, 2021 10:07 am

Re: macro or Function to change the Font for every Dimension

Post by Cuq »

Ok Got It !

Code: Select all

import FreeCADGui

# browse all objects in the view
for obj in FreeCADGui.ActiveDocument.Document.Objects:
	if obj.isDerivedFrom("TechDraw::DrawViewDimension") or obj.isDerivedFrom("TechDraw::DrawViewBalloon"):
		_name=obj.Name
		FreeCADGui.ActiveDocument.getObject(_name).Font = "osifont"
	elif obj.isDerivedFrom("TechDraw::DrawViewAnnotation") :
		_name=obj.Name
		FreeCAD.ActiveDocument.getObject(_name).Font = "osifont"
User avatar
Cuq
Posts: 145
Joined: Tue Jul 06, 2021 10:07 am

Re: [SOLVED] Macro or Function to change the Font for every Dimension

Post by Cuq »

Final Release
ChangeFont.png
ChangeFont.png (5.71 KiB) Viewed 821 times
Copy the two files ChangeFontTechDraw.FCMacro and TaskChangeFont.ui into your macro directory.
Attachments
ChangeFontTechDraw.FCMacro
(4.13 KiB) Downloaded 34 times
TaskChangeFont.ui
(816 Bytes) Downloaded 34 times
User avatar
bensay
Posts: 202
Joined: Wed Dec 22, 2021 8:14 pm
Location: Danmark
Contact:

Re: [SOLVED] Macro or Function to change the Font for every Dimension

Post by bensay »

@wandererfan

What do you think about a buttons for:
- Select all dimensions on page
- Select all dimensions on view
- Select all views

And similar like that?
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [SOLVED] Macro or Function to change the Font for every Dimension

Post by wandererfan »

bensay wrote: Sat Apr 29, 2023 9:20 am
related: issue #6017 and issue #7039
Post Reply