1
$\begingroup$

I'm trying to use id_remap on some materials, but Blender crashes when I try to use the operator. I've tried many different ways to invoke it. Right now I have:

area = bpy.context.area

old_type = area.type

area.type = 'OUTLINER'

bpy.ops.outliner.id_remap(id_type='MATERIAL', old_id='material_2', new_id='material_SM_2')

area.type = old_type

What's the correct way to use this operator?

Thank you!

$\endgroup$
  • $\begingroup$ Do you get any error message before Blender crashes? If so, what is it? And if not, copy the path of your Blender directory (where blender.exe is located), open a command prompt (type cmd in the search bar), then type "cd " (without the quotation marks) and paste the path, then hit enter. Finally type blender.exe and hit enter. Now the command prompt will stay open and you can see the error message after the crash. This method works on Windows. $\endgroup$ – palkonimo Jan 14 at 20:16
0
$\begingroup$

The following should work with Blender 2.7x.

import bpy


def AssembleOverride(atype, rtype):
    for oWindow in bpy.context.window_manager.windows:
        oScreen = oWindow.screen
        for oArea in oScreen.areas:
            if oArea.type == atype:
                for oRegion in oArea.regions:
                    if oRegion.type == rtype:
                        oContextOverride = {
                                'window': oWindow,
                                'screen': oScreen,
                                'area': oArea,
                                'region': oRegion,
                                'scene': bpy.context.scene,
                                'edit_object': bpy.context.edit_object,
                                'active_object': bpy.context.active_object,
                                'selected_objects': bpy.context.selected_objects
                                }
                        print("-AssembleOverride() created override context: ", oContextOverride)
                        return oContextOverride
    raise Exception("ERROR: AssembleOverride()")
# ['EMPTY', 'VIEW_3D', 'TIMELINE', 'GRAPH_EDITOR', 'DOPESHEET_EDITOR',
# 'NLA_EDITOR', 'IMAGE_EDITOR', 'CLIP_EDITOR', 'SEQUENCE_EDITOR',
# 'NODE_EDITOR', 'TEXT_EDITOR', 'LOGIC_EDITOR', 'PROPERTIES', 'OUTLINER',
# 'USER_PREFERENCES', 'INFO', 'FILE_BROWSER', 'CONSOLE']
atype = 'OUTLINER'
# ['WINDOW', 'HEADER', 'CHANNELS', 'TEMPORARY', 'UI', 'TOOLS',
# 'TOOL_PROPS', 'PREVIEW']
rtype = 'WINDOW'

override = AssembleOverride(atype, rtype)
# old_id and  new_id must be pre-existing or operator will fail
bpy.ops.outliner.id_remap(
        override,
        id_type='MATERIAL',
        old_id='Material.002',
        new_id='Material.001'
        )
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.