Blender World
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Help with a Blender Plugin.

Go down

Help with a Blender Plugin. Empty Help with a Blender Plugin.

Post  Zachary1234 Sun Dec 11, 2016 11:58 pm

I've been trying to get help with a plugin, such that no one has yet replied to me.
I need to use a plugin to enhance blender to be able to take indefinite numbers of layers,
instead of the maximum of 20. So I've tried to turn to the latest version of the plugin
espoused to do do this well.

The issue is that I can't enable these separate layers, named "magic layers",
so that the scene or animation rendering (Blender Render) will apprehend these
layers. I get a message that it can't find any layers, then the prior halting
of rendering operations.

-How do I enable these magic layers so that rendering will apprehend them, and proceed?

######################################################################
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
'name': 'Magic Layer',
'author': '',
'version': (0, 2),
'blender': (2, 6, 3),
'location': 'Properties > Scene > Magic Layer',
'warning': '',
'description': 'Display and Edit Layer Name',
'wiki_url': '',
'tracker_url': '',
'category': 'Object'}

import bpy

recursive = False
renaming = True
lastindex = 0
lastname = ""
lastscene = ""



#--------------------------------------------------ok
def magiclayer_checkname(name):
collection=bpy.context.scene.magiclayer
if name=="": name="Layer"

if not name in collection:
return name

pos = name.rfind(".")
if pos==-1:
name=name+".001"
pos=len(name)-4

for i in range(1, 1000):
nr="00"+str(i)
tmp=name[:pos+1]+nr[len(nr)-3:]
if not tmp in collection:
return tmp

return "Layer.???"



#--------------------------------------------------ok
def magiclayer_sort():
collection=bpy.context.scene.magiclayer
count=len(collection)
for i in range(0, count):
for j in range(i+1, count):
if collection[i].name > collection[j].name:
collection.move(j, i)



#--------------------------------------------------ok
def magiclayer_mark(name):
collection=bpy.context.scene.magiclayer
count=len(collection)
for i in range(0, count):
if collection[i].name==name:
bpy.context.scene.magiclayer_index=i
return



#--------------------------------------------------ok
def magiclayer_rename(old, new):
for o in bpy.context.scene.objects:
if o.get("magiclayer", "(undefined)")==old:
o.magiclayer=new



#--------------------------------------------------ok
def magiclayer_name(self, context):
global recursive
global renaming
global lastname
if recursive==True: return
recursive=True

tmp=self.name
self.name=self.name+"@temporaryname"
self.name=magiclayer_checkname(tmp)
tmp=self.name
if renaming==True: magiclayer_rename(lastname, tmp)
magiclayer_sort()
magiclayer_mark(tmp)

recursive=False



#--------------------------------------------------ok
def magiclayer_visible(self, context):
global recursive
if recursive==True: return
recursive=True

if self.name[len(self.name)-1]=="*":
tmp=self.name[:len(self.name)-1]
for l in bpy.context.scene.magiclayer:
if l.name.find(tmp)==0:
l.visible=self.visible
magiclayer_update()

recursive=False



#--------------------------------------------------ok
def magiclayer_index(self, context):
global recursive
if recursive==True: return
recursive=True

scene=bpy.context.scene
if scene.magiclayer_index > len(scene.magiclayer)-1:
scene.magiclayer_index = len(scene.magiclayer)-1

if scene.magiclayer_single==True: magiclayer_update()

recursive=False



#--------------------------------------------------ok
def magiclayer_layers(self, context):
magiclayer_update()



#--------------------------------------------------ok
def magiclayer_single(self, context):
magiclayer_update()



#--------------------------------------------------ok
def magiclayer_add(name=""):
global renaming
renaming=False

entry=bpy.context.scene.magiclayer.add()
entry.name=magiclayer_checkname(name)

renaming=True



#--------------------------------------------------ok
def magiclayer_delete():
index=bpy.context.scene.magiclayer_index
name=bpy.context.scene.magiclayer[index].name

for o in bpy.context.scene.objects:
if o.get("magiclayer", "(undefined)")==name:
o.magiclayer="(undefined)"

bpy.context.scene.magiclayer.remove(index)
magiclayer_update()



#--------------------------------------------------ok
def magiclayer_kill():
index=bpy.context.scene.magiclayer_index
name=bpy.context.scene.magiclayer[index].name

for o in bpy.context.scene.objects:
if o.get("magiclayer", "(undefined)")==name:
o.hide=False
o.select=True
o.layers[19]=True
else:
o.select=False

bpy.context.scene.layers[19]=True
bpy.ops.object.delete()
bpy.context.scene.layers[19]=False
magiclayer_delete()



#--------------------------------------------------ok
def magiclayer_set():
index=bpy.context.scene.magiclayer_index
name=bpy.context.scene.magiclayer[index].name
layers=bpy.context.scene.magiclayer[index].layers

for o in bpy.context.scene.objects:
if o.select==True:
o.magiclayer=name
o.layers=layers

magiclayer_update()



#--------------------------------------------------ok
def magiclayer_unset():
for o in bpy.context.scene.objects:
if o.select==True:
o.magiclayer="(undefined)"
magiclayer_update()



#--------------------------------------------------ok
def magiclayer_check(mode):
for layer in bpy.context.scene.magiclayer:
layer.visible=mode
magiclayer_update()



#--------------------------------------------------ok
def magiclayer_show(mode, value):
index=bpy.context.scene.magiclayer_index
name=bpy.context.scene.magiclayer[index].name

for o in bpy.context.scene.objects:
if o.get("magiclayer", "(undefined)")==name:
if mode==0: o.hide=value
if mode==1: o.hide_select=value
if mode==2: o.hide_render=value



#--------------------------------------------------ok
def magiclayer_sync():
for o in bpy.context.scene.objects:
o.hide=o.hide_render



#--------------------------------------------------ok
def magiclayer_select():
index=bpy.context.scene.magiclayer_index
name=bpy.context.scene.magiclayer[index].name
for o in bpy.context.scene.objects:
o.select=(o.get("magiclayer", "(undefined)")==name)



#--------------------------------------------------ok
def magiclayer_update(quick=True):
scene=bpy.context.scene
collection=scene.magiclayer
index=scene.magiclayer_index
select=""
if scene.magiclayer_index <= len(scene.magiclayer)-1:
select=bpy.context.scene.magiclayer[index].name
modif=0

#reset layer counter
if quick==False:
for layer in collection:
layer.count=0

#update objects
for o in bpy.context.scene.objects:
name=o.get("magiclayer", "(undefined)")
layer=collection.get(name)

if quick==False:
if layer==None:
magiclayer_add(name)
layer=collection.get(name)
modif=modif+1

if layer!=None:
layer.count=layer.count+1

if (scene.magiclayer_single==False and layer!=None and layer.visible==True) or (scene.magiclayer_single==True and name==select):
o.layers=layer.layers
else:
o.layers=[False]*19+[True]

#delete unused layers, sort
if quick==False:
# for i in range(len(collection)-1, -1, -1):
# if collection[i].count==0:
# collection.remove(i)
# modif=modif+1
magiclayer_sort()
if scene.magiclayer_single==True and modif>0: magiclayer_update()

bpy.context.scene.layers[19]=False



#--------------------------------------------------ok
@bpy.app.handlers.persistent
def magiclayer_scan(context):
global lastindex
global lastscene

scene=bpy.context.scene
objects=scene.objects
collection=scene.magiclayer

if lastscene!=scene.name:
if scene.magiclayer_auto==True and lastscene!="": magiclayer_update(False)
lastscene=scene.name

if lastindex>len(objects)-1:
for layer in collection:
layer.count=layer.count2
layer.count2=0
lastindex=0
else:
o=objects[lastindex]
name=o.get("magiclayer", "(undefined)")
layer=collection.get(name)

if layer==None:
magiclayer_add(name)
layer=collection.get(name)

if layer!=None:
layer.count2=layer.count2+1
lastindex=lastindex+1

if scene.magiclayer_auto==True:
if (scene.magiclayer_single==False and layer!=None and layer.visible==True) or (scene.magiclayer_single==True and name==select):
o.layers=layer.layers
else:
o.layers=[False]*19+[True]



#--------------------------------------------------ok
@bpy.app.handlers.persistent
def magiclayer_refresh(context):
if bpy.context.scene.magiclayer_auto==True:
magiclayer_update(False)



#--------------------------------------------------ok
class magiclayer(bpy.types.PropertyGroup):
name =bpy.props.StringProperty(update=magiclayer_name)
visible =bpy.props.BoolProperty(name="", default=True, update=magiclayer_visible)
layers =bpy.props.BoolVectorProperty(name="", size=20, default=[True] + [False]*19, update=magiclayer_layers)
count =bpy.props.IntProperty(name="", default=0)
count2 =bpy.props.IntProperty(name="", default=0)
controls=bpy.props.StringProperty(default="visible")



#--------------------------------------------------ok
class SCENE_OT_magiclayer(bpy.types.Operator):
bl_label ="Magic Layer Action"
bl_idname="magiclayer.action"

button=bpy.props.StringProperty(default="")

def execute(self, context):
button=self.button

if button=="add": magiclayer_add()
elif button=="kill": magiclayer_kill()
elif button=="delete": magiclayer_delete()
elif button=="unset": magiclayer_unset()

elif button=="select": magiclayer_select()
elif button=="update": magiclayer_update(False)
elif button=="sync": magiclayer_sync()
elif button=="set": magiclayer_set()

elif button=="check": magiclayer_check(True)
elif button=="nocheck": magiclayer_check(False)
elif button=="show": magiclayer_show(0, False)
elif button=="noshow": magiclayer_show(0, True)
elif button=="edit": magiclayer_show(1, False)
elif button=="noedit": magiclayer_show(1, True)
elif button=="render": magiclayer_show(2, False)
elif button=="norender": magiclayer_show(2, True)

scene=bpy.context.scene
if scene.magiclayer_index > len(scene.magiclayer)-1:
scene.magiclayer_index = len(scene.magiclayer)-1

return {"FINISHED"}



#--------------------------------------------------ok
class SCENE_PT_magiclayer(bpy.types.Panel):
bl_label ="Magic Layer"
bl_space_type ="PROPERTIES"
bl_region_type="WINDOW"
bl_context ="scene"

def draw(self, context):
global lastname

scene=context.scene
count=len(scene.magiclayer)

layout=self.layout
row=layout.row()
#row.template_list("UI_UL_list", "", scene, "magiclayer", scene, "magiclayer_index", prop_list="controls", rows=15, maxrows=15)
row.template_list("UI_UL_list", "magiclayer", scene, "magiclayer", scene, "magiclayer_index", rows=15, maxrows=15)

col=row.column()
col.operator("magiclayer.action", icon="ZOOMIN", text="").button="add"

if count==0:
lastname=""
col.operator("magiclayer.action", icon="FILE_REFRESH", text="").button="update"

if count>0:
entry=scene.magiclayer[scene.magiclayer_index]
lastname=entry.name
col2=row.column()

col2.operator("magiclayer.action", icon="RADIO", text="").button="kill"
col.operator("magiclayer.action", icon="ZOOMOUT", text="").button="delete"
col2.operator("magiclayer.action", icon="PANEL_CLOSE", text="").button="unset"
col.separator()
col2.separator()

col.operator("magiclayer.action", icon="HAND", text="").button="select"
col2.operator("magiclayer.action", icon="FILE_REFRESH", text="").button="update"
col.operator("magiclayer.action", icon="ARROW_LEFTRIGHT", text="").button="sync"
col2.operator("magiclayer.action", icon="FILE_TICK", text="").button="set"
col.separator()
col2.separator()

col.operator("magiclayer.action", icon="CHECKBOX_HLT", text="").button="check"
col2.operator("magiclayer.action", icon="CHECKBOX_DEHLT", text="").button="nocheck"
col.operator("magiclayer.action", icon="RESTRICT_VIEW_OFF", text="").button="show"
col2.operator("magiclayer.action", icon="RESTRICT_VIEW_ON", text="").button="noshow"
col.operator("magiclayer.action", icon="RESTRICT_SELECT_OFF", text="").button="edit"
col2.operator("magiclayer.action", icon="RESTRICT_SELECT_ON", text="").button="noedit"
col.operator("magiclayer.action", icon="RESTRICT_RENDER_OFF", text="").button="render"
col2.operator("magiclayer.action", icon="RESTRICT_RENDER_ON", text="").button="norender"
col.separator()
col2.separator()

col.prop(scene, "magiclayer_single", toggle=True, icon="RENDERLAYERS", text="")
col2.prop(scene, "magiclayer_auto", toggle=True, icon="AUTO", text="")

row=layout.row()
row.template_layers(entry, "layers", entry, "layers", 0)

col=row.column()
if entry.count==0: col.prop(entry, "name", text="", icon="GHOST_ENABLED")
if entry.count> 0: col.prop(entry, "name", text="")

row=layout.row()
row.label(str(entry.count)+" Object(s)", icon="INFO")

if bpy.context.scene.objects.active != None:
name=bpy.context.scene.objects.active.get("magiclayer", "(undefined)")
col=row.column()
col.label(name, icon="EDIT")



#--------------------------------------------------ok
def register():
bpy.utils.register_class(magiclayer)
bpy.utils.register_class(SCENE_OT_magiclayer)
bpy.utils.register_class(SCENE_PT_magiclayer)
bpy.types.Scene.magiclayer = bpy.props.CollectionProperty(type=magiclayer)
bpy.types.Scene.magiclayer_index = bpy.props.IntProperty(min=0, default=0, update=magiclayer_index)
bpy.types.Scene.magiclayer_single = bpy.props.BoolProperty(default=False, update=magiclayer_single)
bpy.types.Scene.magiclayer_auto = bpy.props.BoolProperty(default=False)
bpy.types.Object.magiclayer = bpy.props.StringProperty()
bpy.app.handlers.scene_update_pre.append(magiclayer_scan)
bpy.app.handlers.load_post.append(magiclayer_refresh)
bpy.app.handlers.render_pre.append(magiclayer_refresh)



#--------------------------------------------------ok
def unregister():
bpy.utils.unregister_class(magiclayer)
bpy.utils.unregister_class(SCENE_OT_magiclayer)
bpy.utils.unregister_class(SCENE_PT_magiclayer)
bpy.app.handlers.scene_update_pre.remove(magiclayer_scan)
bpy.app.handlers.load_post.remove(magiclayer_refresh)
bpy.app.handlers.render_pre.remove(magiclayer_refresh)


if __name__ == "__main__":
register()

#http://www.blender.org/documentation/blender_python_api_2_63_release/bpy.types.UILayout.html
#http://blenderartists.org/forum/showthread.php?201093-Icon-Enumeration-Script-%28Blender-2.5%29&s=1f1c52004036708d2c0d7971619fa9a4
######################################################################

Zachary1234

Posts : 20
Join date : 2013-10-31

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum