0
$\begingroup$

I'm trying to do a library override on a material linked from an external blend file.

It can be done manually through the outliner by right clicking on the material -> Library Override / Make / Selected

How to do this by script ?

I tried this :

myLinkedMaterial.override_hierarchy_create(bpy.context.scene,bpy.context.view_layer,do_fully_editable = True)

but it does nothing... override_create() doesn't work either...

I also have this piece of code which is working on the override part, but only if the material has been manually selected in the outliner :

import bpy

def get_outliner_area():
    if bpy.context.area.type!='OUTLINER':
        for w in bpy.context.window_manager.windows:
            s = w.screen
            for a in s.areas:
                if a.type == "OUTLINER":
                    return a

area = get_outliner_area()
region = next(region for region in area.regions if region.type == "WINDOW")

with bpy.context.temp_override(area=area, region=region):    
    for item in bpy.context.selected_ids:
        if isinstance(item , bpy.types.Material):
            bpy.ops.outliner.liboverride_operation()

I'm looking for a way to do this override on any linked material, without the need of selecting it manually beforehand in the outliner. Is it possible ?

A workaround would be to iterate on all the items listed in the outliner, but I can't find any clue on how to get access to this list... It seems that only the list of selected items are available, through bpy.context.selected_ids :(

$\endgroup$
5
  • $\begingroup$ override_hierarchy_create should return the override if myLinkedMaterial is effectively linked. $\endgroup$
    – lemon
    Commented Jan 25 at 12:58
  • $\begingroup$ override_hierarchy_create () does strictly nothing in this case :( Bu maybe I'm issing something. If you have a more detailed explanation on how to use it, I'm interested. $\endgroup$ Commented Jan 27 at 16:41
  • $\begingroup$ nothing more, really. Just it works for me... so if not for you maybe something is different in other parts of your code ? $\endgroup$
    – lemon
    Commented Jan 27 at 16:47
  • $\begingroup$ in my case I have an object which is local to the scene, and its mesh data and material are linked from an external file. In the python console, with my object selected, I type : C.view_layer.objects.active.material_slots[0].material.override_hierarchy_create(C.scene,C.view_layer) This is creating a duplicate of my material, but this is not overriding the material on the object in blender 3.6.5. Doing nothing on blender 4.0. $\endgroup$ Commented Jan 27 at 17:15
  • $\begingroup$ I'm also having an issue with this as well. Looking into this now. I'll post here if I find anything useful $\endgroup$ Commented Mar 22 at 11:43

0

You must log in to answer this question.

Browse other questions tagged .