== Tracker urls formatting ==
[blender-addons-contrib.git] / render_to_print.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 bl_addon_info = {
20     'name': 'Render to Print',
21     'author': 'Marco Crippa <thekrypt77@tiscali.it>',
22     'version': (0,1),
23     'blender': (2, 5, 4),
24     'location': 'Render > Render to Print',
25     'description': 'Set the size of the render for a print',
26     'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/'\
27         'Scripts/Render/Render to Print',
28     'tracker_url': 'https://projects.blender.org/tracker/index.php?'\
29         'func=detail&aid=24219',
30     'category': 'Render'}
31
32
33 import bpy
34 import math
35 from bpy.props import *
36
37 class RenderButtonsPanel():
38     bl_space_type = 'PROPERTIES'
39     bl_region_type = 'WINDOW'
40     bl_context = 'render'
41
42 class RENDER_PT_Print(RenderButtonsPanel, bpy.types.Panel):
43     bl_label = "Render to Print"
44
45     bpy.types.Scene.Preset = EnumProperty(
46         name="Select preset",
47         description="Select from preset",
48         items=(
49             ("custom_1_1", "custom", ""),
50             ("A0_84.1_118.9", "A0 (84.1x118.9 cm)", ""),
51             ("A1_59.4_84.1", "A1 (59.4x84.1 cm)", ""),
52             ("A2_42.0_59.4", "A2 (42.0x59.4 cm)", ""),
53             ("A3_29.7_42.0", "A3 (29.7 42.0 cm)", ""),
54             ("A4_21.0_29.7", "A4 (21.0x29.7 cm)", ""),
55             ("A5_14.8_21.0", "A5 (14.8x21.0 cm)", ""),
56             ("A6_10.5_14.8", "A6 (10.5x14.8 cm)", ""),
57             ("A7_7.4_10.5", "A7 (7.4x10.5 cm)", ""),
58             ("A8_5.2_7.4", "A8 (5.2x7.4 cm)", ""),
59             ("A9_3.7_5.2", "A9 (3.7x5.2 cm)", ""),
60             ("A10_2.6_3.7", "A10 (2.6x3.7 cm)", ""),
61
62             ("B0_100.0_141.4", "B0 (100.0x141.4 cm)", ""),
63             ("B1_70.7_100.0", "B1 (70.7x100.0 cm)", ""),
64             ("B2_50.0_70.7", "B2 (50.0x70.7 cm)", ""),
65             ("B3_35.3_50.0", "B3 (35.3x50.0 cm)", ""),
66             ("B4_25.0_35.3", "B4 (25.0x35.3 cm)", ""),
67             ("B5_17.6_25.0", "B5 (17.6x25.0 cm)", ""),
68             ("B6_12.5_17.6", "B6 (12.5x17.6 cm)", ""),
69             ("B7_8.8_12.5", "B7 (8.8x12.5 cm)", ""),
70             ("B8_6.2_8.8", "B8 (6.2x8.8 cm)", ""),
71             ("B9_4.4_6.2", "B9 (4.4x6.2 cm)", ""),
72             ("B10_3.1_4.4", "B10 (3.1x4.4 cm)", ""),
73
74             ("C0_91.7_129.7", "C0 (91.7x129.7 cm)", ""),
75             ("C1_64.8_91.7", "C1 (64.8x91.7 cm)", ""),
76             ("C2_45.8_64.8", "C2 (45.8x64.8 cm)", ""),
77             ("C3_32.4_45.8", "C3 (32.4x45.8 cm)", ""),
78             ("C4_22.9_32.4", "C4 (22.9x32.4 cm)", ""),
79             ("C5_16.2_22.9", "C5 (16.2x22.9 cm)", ""),
80             ("C6_11.4_16.2", "C6 (11.4x16.2 cm)", ""),
81             ("C7_8.1_11.4", "C7 (8.1x11.4 cm)", ""),
82             ("C8_5.7_8.1", "C8 (5.7x8.1 cm)", ""),
83             ("C9_4.0_5.7", "C9 (4.0x5.7 cm)", ""),
84             ("C10_2.8_4.0", "C10 (2.8x4.0 cm)", ""),
85
86             ("Letter_21.6_27.9", "Letter (21.6x27.9 cm)", ""),
87             ("Legal_21.6_35.6", "Legal (21.6x35.6 cm)", ""),
88             ("Legal junior_20.3_12.7", "Legal junior (20.3x12.7 cm)", ""),
89             ("Ledger_43.2_27.9", "Ledger (43.2x27.9 cm)", ""),
90             ("Tabloid_27.9_43.2", "Tabloid (27.9x43.2 cm)", ""),
91
92             ("ANSI C_43.2_55.9", "ANSI C (43.2×55.9 cm)", ""),
93             ("ANSI D_55.9_86.4", "ANSI D (55.9×86.4 cm)", ""),
94             ("ANSI E_86.4_111.8", "ANSI E (86.4×111.8 cm)", ""),
95
96             ("Arch A_22.9_30.5", "Arch A (22.9×30.5 cm)", ""),
97             ("Arch B_30.5_45.7", "Arch B (30.5×45.7 cm)", ""),
98             ("Arch C_45.7_61.0", "Arch C (45.7×61.0 cm)", ""),
99             ("Arch D_61.0_91.4", "Arch D (61.0×91.4 cm)", ""),
100             ("Arch E_91.4_121.9", "Arch E (91.4×121.9 cm)", ""),
101             ("Arch E1_76.2_106.7", "Arch E1 (76.2×106.7 cm)", ""),
102             ("Arch E2_66.0_96.5", "Arch E2 (66.0x96.5 cm)", ""),
103             ("Arch E3_68.6_99.1", "Arch E3 (68.6x99.1 cm)", "")
104         ),
105         default="custom_1_1"
106     )
107
108     bpy.types.Scene.Orientation = EnumProperty(
109         name="Set orientation", 
110         description="Set orientation", 
111         items=(
112             ("Portrait", "Portrait", "Portrait"),
113             ("Landscape", "Landscape", "Landscape")
114         ),
115         default="Portrait")
116
117     bpy.types.Scene.From = EnumProperty(
118         name="Set from",
119         description="Set from",
120         items=(
121             ("Cm--->Pixel", "Cm--->Pixel", "Cm--->Pixel"),
122             ("Pixel--->Cm", "Pixel--->Cm", "Pixel--->Cm")
123         ),
124         default="Cm--->Pixel")
125
126     bpy.types.Scene.Width = FloatProperty(
127         name = "Width",
128         description = "Width",
129         default = 5.0,
130         min = 1.0,
131         max = 100000.0)
132     bpy.types.Scene.Height = FloatProperty(
133         name = "Height",
134         description = "Height",
135         default = 3.0,
136         min = 1.0,
137         max = 100000.0)
138
139     bpy.types.Scene.DPI = IntProperty(
140         name = "DPI",
141         description = "DPI",
142         default = 300,
143         min = 1,
144         max = 100000)
145
146     bpy.types.Scene.PWidth = IntProperty(
147         name = "Pixel Width",
148         description = "Pixel Width",
149         default = 900,
150         min = 4,
151         max = 10000)
152     bpy.types.Scene.PHeight = IntProperty(
153         name = "Pixel Height",
154         description = "Pixel Height",
155         default = 600,
156         min = 4,
157         max = 10000)
158
159     bpy.types.Scene.WInch = StringProperty(
160         name = "Inch Width",
161         description = "",
162         default = "AAA")
163     bpy.types.Scene.HInch = StringProperty(
164         name = "Inch Height",
165         description = "",
166         default = "AAA")
167
168     def draw(self, context):
169         layout = self.layout
170
171         scn = context.scene
172
173         row = layout.row(align=True)
174         row1 = layout.row(align=True)
175         row2 = layout.row(align=True)
176         row3 = layout.row(align=True)
177         row4 = layout.row(align=True)
178         row5 = layout.row(align=True)
179         row6 = layout.row(align=True)
180         row7 = layout.row(align=True)
181         col = layout.column(align=True)
182
183         row.prop(scn, "From")
184         row1.prop(scn, "Orientation")
185         row2.prop(scn, "Preset")
186
187         col.separator()
188         row3.prop(scn, "Width")
189         row3.separator()
190         row3.prop(scn, "Height")
191         col.separator()
192         row4.prop(scn, "DPI")
193         col.separator()
194         row5.prop(scn, "PWidth")
195         row5.separator()
196         row5.prop(scn, "PHeight")
197
198         col.separator()
199         row6.prop(scn, "WInch")
200         row6.prop(scn, "HInch")
201         row6.active=False
202         row6.enabled=False
203         col.separator()
204
205         row7.operator("Do_P2R", text="SET RENDER!", icon="RENDER_STILL")
206         
207         tipo,dim_w,dim_h=scn.Preset.split("_")
208
209         if scn.From == "Cm--->Pixel":
210             row5.active=False
211             row5.enabled=False
212
213             if tipo=="custom":
214                 row3.active=True
215                 row3.enabled=True
216                 row1.active=False
217                 row1.enabled=False
218                 dim_w=scn.Width
219                 dim_h=scn.Height
220                 scn.Width=float(dim_w)
221                 scn.Height=float(dim_h)
222             elif tipo!="custom" and scn.Orientation=="Landscape":
223                 row3.active=False
224                 row3.enabled=False
225                 row1.active=True
226                 row1.enabled=True
227                 scn.Width=float(dim_h)
228                 scn.Height=float(dim_w)
229             elif tipo!="custom" and scn.Orientation=="Portrait":
230                 row3.active=False
231                 row3.enabled=False
232                 row1.active=True
233                 row1.enabled=True
234                 scn.Width=float(dim_w)
235                 scn.Height=float(dim_h)
236
237             scn.PWidth=math.ceil((scn.Width*scn.DPI)/2.54)
238             scn.PHeight=math.ceil((scn.Height*scn.DPI)/2.54)
239         else:
240             row3.active=False
241             row3.enabled=False
242
243             if tipo=="custom":
244                 row1.active=False
245                 row1.enabled=False
246             elif tipo!="custom" and scn.Orientation=="Landscape":
247                 row1.active=True
248                 row1.enabled=True
249                 row5.active=False
250                 row5.enabled=False
251                 scn.Width=float(dim_h)
252                 scn.Height=float(dim_w)
253                 scn.PWidth=math.ceil((scn.Width*scn.DPI)/2.54)
254                 scn.PHeight=math.ceil((scn.Height*scn.DPI)/2.54)
255             elif tipo!="custom" and scn.Orientation=="Portrait":
256                 row1.active=True
257                 row1.enabled=True
258                 row5.active=False
259                 row5.enabled=False
260                 scn.Width=float(dim_w)
261                 scn.Height=float(dim_h)
262                 scn.PWidth=math.ceil((scn.Width*scn.DPI)/2.54)
263                 scn.PHeight=math.ceil((scn.Height*scn.DPI)/2.54)
264
265
266             scn.Width=float(scn.PWidth/scn.DPI)*2.54
267             scn.Height=float(scn.PHeight/scn.DPI)*2.54
268
269         scn.WInch="%.2f" % (scn.Width/2.54)
270         scn.HInch="%.2f" % (scn.Height/2.54)
271
272
273 class DoP2R(bpy.types.Operator):
274     bl_idname = "Do_P2R"
275     bl_label = "Run P2R"
276     bl_description = "Set the render dimension"
277
278     def execute(self, context):
279         scn = context.scene
280         rnd = context.scene.render
281         #set render resolution
282         rnd.resolution_x=scn.PWidth
283         rnd.resolution_y=scn.PHeight
284
285         return {'FINISHED'}
286
287
288 def register():
289     pass
290
291 def unregister():
292     pass
293
294 if __name__ == "__main__":
295     register()