1
$\begingroup$

I'm using python scripting in blender to create scenes, with static scenes rendered in freestyle. I am aiming to be able to use freestyle style modules (eg japanese_bigbrush.py or user defined) to control freestyle output. I have a function

bpy.context.scene.render.layers["RenderLayer"].use_solid = False
bpy.context.scene.render.layers["RenderLayer"].use_halo = False
bpy.context.scene.render.layers["RenderLayer"].use_zmask = False
bpy.context.scene.render.layers["RenderLayer"].use_all_z = False
bpy.context.scene.render.layers["RenderLayer"].use_ztransp = False
bpy.context.scene.render.layers["RenderLayer"].invert_zmask = False
bpy.context.scene.render.layers["RenderLayer"].use_sky = False
bpy.context.scene.render.layers["RenderLayer"].use_edge_enhance = False
bpy.context.scene.render.layers["RenderLayer"].use_strand = False

bpy.context.scene.render.use_freestyle = True

bpy.context.scene.render.resolution_y = 1500 
bpy.context.scene.render.resolution_x = aspectRatio *1500
bpy.context.scene.render.resolution_percentage =100

#change to script mode
rl = bpy.context.scene.render.layers.active
rl.freestyle_settings.mode = 'SCRIPT'

#add freestyle style module
bpy.ops.scene.freestyle_module_add()    

#open freestyle style module
bpy.ops.scene.freestyle_module_open(PathToModuleHere)

#render image
bpy.context.scene.render.filepath = PathToRenderedImageHere + fileName + '.jpg'
bpy.ops.render.render( write_still=True )

When calling the freestyle_module_open function I get an error

'expected a string enum in [list of strings eg INVOKE_DEFAULT, INVOKE_REGION_WIN]

I have also tried incorporating the python code from the style module straight into my function. Also adding the style module as a code block in blender. No joy.

I can get it to work if I add the style module manually in blender then run the function, but can't work out how to do this programatically.

$\endgroup$

1 Answer 1

1
$\begingroup$

You will most likely want to enable freestyle in your render layers settings

bpy.context.scene.render.layers["RenderLayer"].use_freestyle = True

To add a module and set the script you can use -

#open freestyle style module
text_block = bpy.data.texts.load(PathToModuleHere)

#add freestyle style module
freestyle_module = rl.freestyle_settings.modules.new()

#set the script to use
freestyle_module.script = text_block
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .