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.
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
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__)