1
$\begingroup$

I have the following code that turns on freestyle, adds a Line-Set, and adjusts parameters for that Line-Set.

What I can't figure out is how to add a new Line-Style to a Line-Set, and adjust it's parameters.

sceneR = bpy.context.scene
freestyle = sceneR.render.layers.active.freestyle_settings

sceneR.render.use_freestyle = True
sceneR.render.line_thickness = 10
sceneR.svg_export.use_svg_export = False
freestyle.use_smoothness = False

#Set a lineset for the visible lines
LineSetV = freestyle.linesets.new('VisibleLineset')
LineSetV.select_by_visibility = False
LineSetV.select_by_edge_types = True
LineSetV.select_by_face_marks = False    
LineSetV.select_by_group = False    
LineSetV.select_by_image_border = False    

#Set the lineset variables
LineSetV.select_edge_mark = True
LineSetV.select_crease = False
LineSetV.select_silhouette = False
LineSetV.select_border = False
LineSetV.select_contour = False
LineSetV.select_suggestive_contour = False
LineSetV.select_ridge_valley = False
LineSetV.select_external_contour = False
LineSetV.select_material_boundary = False
$\endgroup$

1 Answer 1

2
$\begingroup$

I hope it is not to late but everything related to the linestyle / lineset is in the documentation. Your code is right, you just missed the class member. The cool thing is that you don't need to add something :)

Blender 2.79

The Freestyle line class class bpy.types.FreestyleLineSet(bpy_struct)

https://docs.blender.org/api/2.79/bpy.types.FreestyleLineSet.html#bpy.types.FreestyleLineSet

The linestyle class class bpy.types.FreestyleLineStyle

https://docs.blender.org/api/2.79/bpy.types.FreestyleLineStyle.html#bpy.types.FreestyleLineStyle

You can even add modifier or use nodes.

import bpy
from mathutils import Color

sceneR = bpy.context.scene
freestyle = sceneR.render.layers.active.freestyle_settings

sceneR.render.use_freestyle = True
sceneR.render.line_thickness = 10
sceneR.svg_export.use_svg_export = False
freestyle.use_smoothness = False

#Set a lineset for the visible lines
LineSetV = freestyle.linesets.new('VisibleLineset')
LineSetV.select_by_visibility = False
LineSetV.select_by_edge_types = True
LineSetV.select_by_face_marks = False    
LineSetV.select_by_group = False    
LineSetV.select_by_image_border = False    

#Set the lineset variables
LineSetV.select_edge_mark = True
LineSetV.select_crease = False
LineSetV.select_silhouette = False
LineSetV.select_border = False
LineSetV.select_contour = False
LineSetV.select_suggestive_contour = False
LineSetV.select_ridge_valley = False
LineSetV.select_external_contour = False
LineSetV.select_material_boundary = False

# Set the linestyle   
LineSetV.linestyle.color = Color((1.0, 1.0, 1.0))   # Color
LineSetV.linestyle.thickness = 2.0                  # Thickness

Blender 2.80

Same with this version

FreestyleLineSet

https://docs.blender.org/api/current/bpy.types.FreestyleLineSet.html#bpy.types.FreestyleLineSet

LineStyle

https://docs.blender.org/api/current/bpy.types.FreestyleLineStyle.html#bpy.types.FreestyleLineStyle

$\endgroup$
1
  • $\begingroup$ Hoping I can get some clarity in Blender 2.93. I'm still not sure how you specify which line style you want to assign? I can see how assign colour and thickness but what about the line style? $\endgroup$ Commented Nov 8, 2021 at 14:14

You must log in to answer this question.

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