FreeCAD-macros
65 строк · 3.2 Кб
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# ***************************************************************************
5# * *
6# * Copyright (c) 2022 - Wanderer Fan <wandererfan@gmail.com> *
7# * *
8# * This program is free software; you can redistribute it and/or modify *
9# * it under the terms of the GNU Lesser General Public License (LGPL) *
10# * as published by the Free Software Foundation; either version 2 of *
11# * the License, or (at your option) any later version. *
12# * for detail see the LICENCE text file. *
13# * *
14# * This program is distributed in the hope that it will be useful, *
15# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17# * GNU Library General Public License for more details. *
18# * *
19# * You should have received a copy of the GNU Library General Public *
20# * License along with this program; if not, write to the Free Software *
21# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22# * USA *
23# * *
24# ***************************************************************************
25"""Migrates Annotation Text made in FreeCAD v0.18 to v0.19."""
26
27__Name__ = 'TechDrawAnnoTextFromv018'
28__Comment__ = 'Convert v018 Annotation Text size to v019'
29__Author__ = 'WandererFan'
30__Version__ = '0.1.0'
31__License__ = 'CC-BY-3.0'
32__Web__ = 'http://www.freecadweb.org/'
33__Wiki__ = 'http://www.freecadweb.org/wiki/Macro_TechDrawAnnoTextFromv018'
34__Icon__ = ''
35__Help__ = 'Open a v018 file in v019, execute'
36__Status__ = 'Alpha'
37__Requires__ = ''
38__Communication__ = 'https://github.com/FreeCAD/FreeCAD-macros/issues/'
39__Files__ = ''
40
41# font sizes were once set using QFont.setPointSize but are now set using QFont.setPixelSize.
42# text set the old way will be bigger than text set the new way since points are bigger than
43# pixels. This macro adjusts the text size in old files to give approximately the same size
44# result.
45
46import FreeCAD as App
47import TechDraw
48
49def TechDrawAnnoTextFromv018():
50factor = 96.0/72.0 # pixels/inch vs points/inch
51for obj in App.ActiveDocument.Objects:
52if obj.isDerivedFrom("TechDraw::DrawViewAnnotation"):
53oldSize = obj.TextSize
54obj.TextSize = oldSize * factor
55if obj.isDerivedFrom("TechDraw::DrawViewDimension"):
56oldSize = obj.ViewObject.Fontsize
57obj.ViewObject.Fontsize = oldSize * factor
58if obj.isDerivedFrom("TechDraw::DrawViewBalloon"):
59oldSize = obj.ViewObject.Fontsize
60obj.ViewObject.Fontsize = oldSize * factor
61
62
63if __name__ == '__main__':
64TechDrawAnnoTextFromv018()
65App.ActiveDocument.recompute()
66
67