I want to copy Linesets from one file to another. I appended the required scene from the source file to the target file. Then following THIS ANSWER from blenderartists.org, I tried copy-pasting the shared code in the text editor. But an error is reported that I can't comprehend. The "Attribute error" in the system console reads : "Rendersettings" object has no attribute "layers". Also the answer seems to have been posted in 2016. Does it still work in the latest blender versions - 2.9x? Please help!


View Layers

One of the changes in 2.8 from prior is the use of view layers. This is where Freestyle settings now reside

Change up to script (compare with original to see changes)

  • Use the context view layer as the source, ie make the the source scene context when running script. (If more convenient swap this around and have a hardcoded source and copy into context)

Test script, current default is to Copy settings of view layer with context into view layer named "View Layer" in scene named "Scene.001"

import bpy
from bpy import context 

excludes = ('__doc__', '__module__', '__slots__', 'bl_rna', 'rna_type')

# get the freestyle of context view layer
linesetsFrom = context.view_layer.freestyle_settings.linesets

# copy to scene                 
to_scene  = bpy.data.scenes.get("Scene.001")
# into freestyle settings of its "View Layer"
linesetsTo = to_scene.view_layers['View Layer'].freestyle_settings.linesets

for name in linesetsFrom.keys():
    src = linesetsFrom[name]
    dest = linesetsTo.get(name)
    if dest is None:
        dest = linesetsTo.new(name)
    for attr in dir(dest):
        if attr not in excludes:
            setattr(dest, attr, getattr(src, attr))

Your Answer

