Go Solo (aka Isolate Selection) without zooming on the object

Hey guys, I could really use some help on a script …
Well, actually it is not “help” but more someone who can code this for me :o

I would like to have a toggle script that moves the selected objects to an empty layer and activates that layer.
If I execute the script again the objects should be moved back to the original layer.

Do you guys think this is possible at all?

Cheers Christian

import bpy

lay20 = [False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,True]


sc_status = bpy.context.scene.get('iso')
if sc_status == 0 or sc_status == None:
    bpy.context.scene["iso"]=1
    bpy.context.scene["old_lay"]=bpy.context.scene.layers
    for i in bpy.context.selected_objects:
        i["old_lay"]=i.layers
        i.layers = lay20
        bpy.context.scene.layers = lay20
elif sc_status == 1:
    for i in bpy.data.objects:
        ol_tag = i.get('old_lay')
        if ol_tag != None:
            old_lay = []
            for j in i['old_lay']:
                if j == 0:old_lay.append(False)
                else:old_lay.append(True)
            i.layers = old_lay
    old_lay = []
    for j in bpy.context.scene['old_lay']:
        if j == 0:old_lay.append(False)
        else:old_lay.append(True)
    bpy.context.scene.layers = old_lay
    bpy.context.scene["iso"]=0

Awesome, works perfectly :slight_smile:
Many many thanks for the quick help!!

Best wishes
Christian

I was trying to make a .py script out of that to be able to assign a hotkey to it and wrote the following.
Unfortunately I get an error message when trying to activate the script in the addons menu.
Does anyone know how to make this work correctly?

Cheers Christian


bl_info = {
    "name": "IsolateSelection",
    "category": "Mesh",
}


import bpy


class isolate(bpy.types.Operator):  
    bl_idname = "object.isolate"  
    bl_label = "Isolate Selection"
    bl_options = {'REGISTER', 'UNDO'} 


    lay20 = [False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,True]


    sc_status = bpy.context.scene.get('iso')
    if sc_status == 0 or sc_status == None:
        bpy.context.scene["iso"]=1
        bpy.context.scene["old_lay"]=bpy.context.scene.layers
        for i in bpy.context.selected_objects:
            i["old_lay"]=i.layers
            i.layers = lay20
            bpy.context.scene.layers = lay20
    elif sc_status == 1:
        for i in bpy.data.objects:
            ol_tag = i.get('old_lay')
            if ol_tag != None:
                old_lay = []
                for j in i['old_lay']:
                    if j == 0:old_lay.append(False)
                    else:old_lay.append(True)
                i.layers = old_lay
        old_lay = []
        for j in bpy.context.scene['old_lay']:
            if j == 0:old_lay.append(False)
            else:old_lay.append(True)
        bpy.context.scene.layers = old_lay
        bpy.context.scene["iso"]=0


def register():
    bpy.utils.register_module(__name__)


def unregister():
    bpy.utils.unregister_module(__name__)

If anyone has an idea why this is not working please let me know.

Cheers Christian

Running the script the first time to register it requires some extra sanitation with running code and context. Here is the corrected code.

bl_info = {    "name": "IsolateSelection",
    "category": "Mesh",
}




import bpy




def main(context):
    
    lay20 = [False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,True]




    sc_status = bpy.context.scene.get('iso')
    if sc_status == 0 or sc_status == None:
        bpy.context.scene["iso"]=1
        bpy.context.scene["old_lay"]=bpy.context.scene.layers
        for i in bpy.context.selected_objects:
            i["old_lay"]=i.layers
            i.layers = lay20
            bpy.context.scene.layers = lay20
    elif sc_status == 1:
        for i in bpy.data.objects:
            ol_tag = i.get('old_lay')
            if ol_tag != None:
                old_lay = []
                for j in i['old_lay']:
                    if j == 0:old_lay.append(False)
                    else:old_lay.append(True)
                i.layers = old_lay
        old_lay = []
        for j in bpy.context.scene['old_lay']:
            if j == 0:old_lay.append(False)
            else:old_lay.append(True)
        bpy.context.scene.layers = old_lay
        bpy.context.scene["iso"]=0


    


class isolate(bpy.types.Operator):  
    bl_idname = "object.isolate"  
    bl_label = "Isolate Selection"
    bl_options = {'REGISTER', 'UNDO'} 


    def execute(self,context):
        main(context)
        return {'FINISHED'}




def register(): 
    bpy.utils.register_module(__name__)




def unregister():
    bpy.utils.unregister_module(__name__)

thank you so much for the help! its a lot better like this :smiley: