update mesh versions, add gpl block

This commit is contained in:
meta-androcto
2017-04-22 18:04:16 +10:00
parent bade96e86b
commit 9307990db5

View File

@ -1,7 +1,25 @@
# ##### 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": "KTX Mesh Versions",
"author": "Roel Koster, @koelooptiemanna, irc:kostex",
"version": (1, 4),
"version": (1, 4, 2),
"blender": (2, 7, 0),
"location": "View3D > Properties",
"category": "Object"}
@ -9,29 +27,22 @@ bl_info = {
import bpy,time
from datetime import datetime
from bpy.types import Menu, Panel
from bpy.props import StringProperty, BoolProperty, IntProperty
from bpy.props import StringProperty, BoolProperty
class KTX_MeshInit(bpy.types.Operator):
bl_label = "Initialise Mesh Versioning"
bl_idname = "ktx.meshversions_init"
bl_description = "Initialise the current object to support versioning (Rename object/mesh to unique name)"
bl_description = "Initialise the current object to support versioning"
def execute(self, context):
c_mode=bpy.context.object.mode
if c_mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
obj = context.object
dt = datetime.now().strftime('_%y%m%d%H%M%S')
obj.name=obj.name+dt
obj.data.name=obj.name
bpy.ops.object.mode_set(mode=c_mode)
unique_id=str(time.time())
context.object.data.ktx_mesh_id=context.object.ktx_object_id=unique_id
return {'FINISHED'}
class KTX_MeshSelect(bpy.types.Operator):
bl_label = "select mesh"
bl_label = "Select Mesh"
bl_idname = "ktx.meshversions_select"
bl_description = "Change the current mesh to this version"
bl_description = "Link the selected mesh to the current object"
m_index = StringProperty()
@ -45,9 +56,9 @@ class KTX_MeshSelect(bpy.types.Operator):
return {'FINISHED'}
class KTX_MeshRemove(bpy.types.Operator):
bl_label = "remove mesh"
bl_label = "Remove Mesh"
bl_idname = "ktx.meshversions_remove"
bl_description = "Remove the current mesh"
bl_description = "Remove/Delete the selected mesh"
m_index = StringProperty()
@ -55,29 +66,12 @@ class KTX_MeshRemove(bpy.types.Operator):
bpy.data.meshes.remove(bpy.data.meshes[self.m_index])
return {'FINISHED'}
class KTX_MeshFake(bpy.types.Operator):
bl_label = "mesh fake user"
bl_idname = "ktx.meshversions_fakeuser"
bl_description = "If pinned (FAKE_USER=TRUE) this mesh will be saved in the blend file\nIf unpinned (FAKE_USER=FALSE) this mesh will be discarded when saving the blend file"
m_index = StringProperty()
def execute(self, context):
me=bpy.data.meshes
if me[self.m_index].use_fake_user:
me[self.m_index].use_fake_user=False
else:
me[self.m_index].use_fake_user=True
return {'FINISHED'}
class KTX_MeshCreate(bpy.types.Operator):
bl_label = "Create Mesh Version"
bl_idname = "ktx.meshversions_create"
bl_description=("Create a copy of the mesh data of the current object\n"
"and set it as active")
def execute(self, context):
defpin = bpy.context.scene.ktx_defpin
obj = context.object
@ -90,10 +84,8 @@ class KTX_MeshCreate(bpy.types.Operator):
obj.data=new_mesh
obj.data.use_fake_user=defpin
bpy.ops.object.mode_set(mode=c_mode)
return {'FINISHED'}
class KTX_Mesh_Versions(bpy.types.Panel):
bl_label = "KTX Mesh Versions"
bl_idname = "ktx.meshversions"
@ -103,57 +95,58 @@ class KTX_Mesh_Versions(bpy.types.Panel):
def draw(self, context):
scene = context.scene
obj = context.object
layout = self.layout
col = layout.column()
if obj == None:
col.label('Select/Create something first!')
layout.label('No Object Selected')
else:
if obj.type == 'MESH':
if len(obj.name) > 14:
if obj.name[-13] == '_' and obj.name[-12:].isdigit():
col.operator("ktx.meshversions_create")
col.prop(scene, "ktx_defpin")
box = layout.box()
box.label("Versions of Active Object: " + obj.name)
len_obj=len(obj.name)
for m in bpy.data.meshes:
len_m=len(m.name)
if m.name[:len_obj] == obj.name:
row = box.row()
row.operator("ktx.meshversions_select",text=m.name).m_index = m.name
if m.users == 0:
row.operator("ktx.meshversions_remove",text="",icon="X").m_index = m.name
if bpy.data.meshes[m.name].use_fake_user:
row.operator("ktx.meshversions_fakeuser", text="",icon="PINNED").m_index = m.name
else:
row.operator("ktx.meshversions_fakeuser", text="",icon="UNPINNED").m_index = m.name
if obj.ktx_object_id != '' and (obj.data.ktx_mesh_id == obj.ktx_object_id):
icon='PINNED' if scene.ktx_defpin else 'UNPINNED'
row=layout.row(align=True)
row.prop(scene, "ktx_defpin",text="", icon=icon)
row.operator("ktx.meshversions_create")
box = layout.box()
box.scale_y=0.65
box.label("Currently active mesh: " + obj.data.name)
for m in bpy.data.meshes:
if m.ktx_mesh_id == obj.ktx_object_id:
mesh_name=m.name
row = box.row(align=True)
row.operator("ktx.meshversions_select",text="",icon='RIGHTARROW').m_index = mesh_name
row.prop(m,"name",text="",icon='MESH_DATA')
if m.users == 0:
row.operator("ktx.meshversions_remove",text="",icon="X").m_index = mesh_name
icon='PINNED' if m.use_fake_user else 'UNPINNED'
row.prop(m,"use_fake_user", text="", icon=icon)
box.label()
else:
col.operator("ktx.meshversions_init")
layout.operator("ktx.meshversions_init")
else:
col.label('Select a Mesh Object in the Scene!')
box = layout.box()
box.label('Or either remove unwanted or pin important meshes:')
for m in bpy.data.meshes:
row = box.row()
row.label(m.name)
if m.users == 0:
row.operator("ktx.meshversions_remove",text="",icon="X").m_index = m.name
if bpy.data.meshes[m.name].use_fake_user:
row.operator("ktx.meshversions_fakeuser", text="",icon="PINNED").m_index = m.name
else:
row.operator("ktx.meshversions_fakeuser", text="",icon="UNPINNED").m_index = m.name
if bpy.data.meshes.items() != []:
layout.label('All Meshes (Cleanup/Pin):')
box = layout.box()
box.scale_y=0.65
for m in bpy.data.meshes:
mesh_name=m.name
row = box.row(align=True)
row.prop(m,"name",text="",icon='MESH_DATA')
if m.users == 0:
row.operator("ktx.meshversions_remove",text="",icon="X").m_index = mesh_name
icon='PINNED' if m.use_fake_user else 'UNPINNED'
row.prop(m,"use_fake_user", text="", icon=icon)
box.label()
def register():
bpy.types.Scene.ktx_defpin = bpy.props.BoolProperty(name="Auto Pinning", description="When creating a copy set pinning to ON automatically (FAKE_USER=TRUE)", default=False)
bpy.types.Object.ktx_object_id = bpy.props.StringProperty(name="KTX Object ID", description="Unique ID to 'link' one object to multiple meshes")
bpy.types.Mesh.ktx_mesh_id = bpy.props.StringProperty(name="KTX Mesh ID", description="Unique ID to 'link' multiple meshes to one object")
bpy.types.Scene.ktx_defpin = bpy.props.BoolProperty(name="Auto Pinning", description="When creating a new version, set pinning to ON automatically (FAKE_USER=TRUE)", default=False)
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Mesh.ktx_mesh_id
del bpy.types.Object.ktx_object_id
del bpy.types.Scene.ktx_defpin
if __name__ == "__main__":