forked from martijnberger/pyslapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_all_scenes_from_skp.py
64 lines (38 loc) · 1.65 KB
/
render_all_scenes_from_skp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sketchup
import tempfile
import subprocess
blender = "/Applications/blender.app/Contents/MacOS/blender"
fname = 'test layers en camera.skp'
m = sketchup.Model.from_file(fname)
todo_scenes = [s.name for s in m.scenes]
for scene_name in todo_scenes:
temp = tempfile.NamedTemporaryFile()
with open("temp_render.py", "w") as f:
fstr = """# Command "blender -b your_file.blend -P render_all_cameras.py cameras=east" will render "east.01" and "east.02" cameras.
# Command "blender -b your_file.blend -P render_all_cameras.py cameras=01" will render "east.01" and "west.01.02" cameras.
import bpy, sys
from bpy import data, ops, props, types, context
print("AA")
bpy.ops.import_scene.skp(filepath=\"{fname}\",
import_scene=\"{name}\",
scenes_as_camera=False, import_camera=True,
reuse_material=True)
print("BA")
#bpy.context.user_preferences.system.compute_device_type = 'CUDA'
#bpy.data.scenes['Scene'].render.use_border = False
bpy.data.scenes['Scene'].render.resolution_percentage = 100
bpy.data.scenes['Scene'].cycles.samples = 50
print('Setting render tile to 256x256')
bpy.data.scenes['Scene'].cycles.tile_x = 256
bpy.data.scenes['Scene'].cycles.tile_y = 256
bpy.data.scenes['Scene'].render.filepath = '{name}.png'
print(context)
print("BA")
context.scene.camera = bpy.data.objects['{name}']
bpy.ops.wm.save_as_mainfile( filepath="test.blend")
bpy.ops.render.render( write_still=True )
print('Done!')
""".format(name=scene_name, fname=fname)
f.writelines(fstr)
subprocess.call([blender, "-b", "-P", "{}".format("temp_render.py")])
print("DONE")