-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderMacro.py
46 lines (39 loc) · 1.26 KB
/
renderMacro.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
import bpy
import os
def RenderObj(pattern,hide):
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_pattern(pattern="%s*" % pattern)
obs = bpy.context.selected_objects
for ob in obs:
ob.hide_render = hide
neuronList = []
areas = ["root"]
outputFolder = os.path.join(os.path.dirname(bpy.context.space_data.text.filepath),"renders")
# Get Neuronlist.
bpy.ops.object.select_pattern(pattern="AA*")
neurons = bpy.context.selected_objects
neuronList = []
for neuron in neurons:
neuronList = neuronList + [neuron.name[0:6]]
neuronList = list(set(neuronList))
print(neuronList)
# generate output dir.
if os.path.isdir(outputFolder)==False:
os.makedirs(outputFolder)
# Turn off all objects.
RenderObj("*",True)
# turn on areas.
for area in areas:
RenderObj("Area_%s*" % area,False)
# Go through neurons.
count = 0
for neuron in neuronList:
count =count+1
print("Neuron %s [%i\\%i]" % (neuron, count, len(neuronList)))
# Turn on neuron
RenderObj("%s*" % neuron,False)
# Render
bpy.context.scene.render.filepath = os.path.join(outputFolder,"%s.png" % neuron)
bpy.ops.render.render( write_still=True )
# Turn off neuron
RenderObj("%s*" % neuron,True)