Paste Code
Paste Blends
Paste Images
# ##### 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 #####
#
# ----
# NOT: "hk_" ile baslayan islevler program icinde tanimlanmis islevlerdir.
# ----
#
# Programmed by: Hikmet Koyuncu @07-2013
# #####

bl_info = {
"name": "Group Editor",
"author": "Hikmet Koyuncu",
"version": (0, 3),
"blender": (2, 6, 6),
"location": "Properties > Group Editor",
"description": "Group editor.",
"category": "Object",
'wiki_url': '',
'tracker_url': ''}

import bpy


# GROUP LISTESI ICIN KULLANACAGIMIZ "TYPE" SINIFI
class GroupList(bpy.types.PropertyGroup):
pass
#name = bpy.props.StringProperty()
#value = bpy.props.IntProperty()

# "GroupList" sinifi register ediliyor
bpy.utils.register_class(GroupList)


# OBJECTS LISTESI ICIN KULLANACAGIMIZ "TYPE" SINIFI
class GroupObjectList(bpy.types.PropertyGroup):
pass
#name = bpy.props.StringProperty()
#value = bpy.props.IntProperty()

# "GroupObjectList" sinifi register ediliyor
bpy.utils.register_class(GroupObjectList)


# GROUP LISTESINI TEMIZLER
def clearGroupList():
list = bpy.context.scene.hk_group_list
for grp in list.items():
list.remove(0)


# OBJECT LISTESINI TEMIZLER
def clearGroupObjectList():
list = bpy.context.scene.hk_group_object_list
for obj in list.items():
list.remove(0)


# GROUP LISTESINI DOLDURUR
def loadGroupList():
# Listeye elemanlar ekleniyor
if "hk_group_list" in dir(bpy.context.scene):
list = bpy.context.scene.hk_group_list
index = bpy.context.scene.hk_group_list_index

# Liste temizleniyor
clearGroupList()

if len(bpy.data.groups) == 0: return

for grp in bpy.data.groups:
if grp != None and grp.users > 0:
grp_member = list.add()
grp_member.name = grp.name
grp_member.value = grp.name

# Listeden en sondaki eleman silindiginde,
# bir onceki elemanin secilmesini saglar.
count = len(list)
if count > 0 and index == count:
bpy.context.scene.hk_group_list_index = index - 1


# GROUP OBJECTS LISTESINI DOLDURUR
def loadGroupObjectList():
# Listeye elemanlar ekleniyor
if "hk_group_object_list" in dir(bpy.context.scene):
list = bpy.context.scene.hk_group_object_list
listGrp = bpy.context.scene.hk_group_list
index = bpy.context.scene.hk_group_object_list_index
indexGrp = bpy.context.scene.hk_group_list_index

# Liste temizleniyor
clearGroupObjectList()

grp = bpy.data.groups[listGrp[indexGrp].name]
if grp.objects == 0: return

for obj in grp.objects:
if obj != None:
obj_member = list.add()
obj_member.name = obj.name
obj_member.value = obj.name

# Listeden en sondaki eleman silindiginde,
# bir onceki elemanin secilmesini saglar.
count = len(list)
if count > 0 and index == count:
bpy.context.scene.hk_group_object_list_index = index - 1


# GROUP SILER
def unlinkGroup(isRemove):
list = bpy.context.scene.hk_group_list

if len(list) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_list_index
grp = bpy.data.groups[list[index].name]

bpy.context.user_preferences.edit.use_global_undo = False


# Group'u objelerden koparir
if len(grp.objects) > 0:
for o in grp.objects:
grp.objects.unlink(o)


if isRemove == True:
grp.user_clear() # Group'u siler

loadGroupObjectList() # Group Object listesini gunceller

bpy.context.user_preferences.edit.use_global_undo = True

loadGroupList() # Group listesi guncelleniyor


#======================================================================


# GROUP LISTESINI GUNCELLER
class HK_RefreshGroupList(bpy.types.Operator):
bl_label = "Refresh Group List"
bl_description = "Refresh Group list."
bl_idname = "scene.hk_refresh_group_list"

def execute(self, context):
loadGroupList()
return {"FINISHED"}


# OBJECT LISTESINI GUNCELLER
class HK_RefreshObjectList(bpy.types.Operator):
bl_label = "Refresh Group Object List"
bl_description = "Refresh Group Object list."
bl_idname = "scene.hk_refresh_group_object_list"

def execute(self, context):
loadGroupObjectList()
return {"FINISHED"}


# GROUP LISTESINDEKI SECILI GRUBUN ICINDEKI OBJELERI LISTELER
class HK_GetSelectedNameList(bpy.types.Operator):
bl_label = "Get Selected Group Name from List"
bl_description = "Get selected group contents (Look 'Object List')."
bl_idname = "scene.hk_get_group_contents_list"

def execute(self, context):
list = bpy.context.scene.hk_group_list

if len(list) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_list_index
grp = bpy.data.groups[list[index].name]

# Listeden secili elemanin ismi textbox'a aktariliyor...
bpy.context.scene.hk_group_name_txt = grp.name

loadGroupObjectList()

return {"FINISHED"}


# SECILI GROUP'UN ISMINI DEGISTIRIR
class HK_RenameGroup(bpy.types.Operator):
bl_label = "Rename Group"
bl_description = "Rename Group."
bl_idname = "scene.hk_rename_group_list"

def execute(self, context):
list = bpy.context.scene.hk_group_list

if len(list) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_list_index
grp = bpy.data.groups[list[index].name]

grp.name = bpy.context.scene.hk_group_name_txt # Group rename

# Group'un listedeki ismi degistiriliyor
list[index].name = grp.name

return {"FINISHED"}


# YENI BIR GRUP OLUSTURUR
class HK_CreateNewGroup(bpy.types.Operator):
bl_label = "Create New Group"
bl_description = "Create new group."
bl_idname = "scene.hk_create_new_group_list"

def execute(self, context):
bpy.data.groups.new(name="Group") # Yeni bir grup olusturuluyor

loadGroupList() # Group listesi guncelleniyor

return {"FINISHED"}


# SECILI OBJEYI LISTEDE SECILI GRUBA EKLER
class HK_AddObjectGroup(bpy.types.Operator):
bl_label = "Add Object Group List"
bl_description = "Add selected object to group."
bl_idname = "scene.hk_add_object_group_list"

def execute(self, context):
list = bpy.context.scene.hk_group_list

if len(list) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_list_index

# Secili obje group'a baglaniyorz
bpy.ops.object.group_link(group=list[index].name)
bpy.ops.group.objects_add_active(group=list[index].name)

loadGroupObjectList() # Object listesi guncelleniyor

return {"FINISHED"}


# SECILI OBJEYI LISTEDE SECILI GRUBTAN AYIRIR
class HK_RemoveObjectGroup(bpy.types.Operator):
bl_label = "Remove Object Group List"
bl_description = "Remove selected object from selected group."
bl_idname = "scene.hk_remove_object_group_list"

def execute(self, context):
list = bpy.context.scene.hk_group_list

if len(list) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_list_index

# Secili obje listede secili gruptan ayriliyor
bpy.ops.group.objects_remove(group=list[index].name)

loadGroupObjectList() # Object listesi guncelleniyor

return {"FINISHED"}


# OBJE LISTESINDEN SECILI OBJEYI GRUPTAN AYIRIR
class HK_UnlinkObjectListGroup(bpy.types.Operator):
bl_label = "Unlink Object Group List"
bl_description = "Unlink selected object from selected group."
bl_idname = "scene.hk_unlink_object_group_list"

def execute(self, context):
list = bpy.context.scene.hk_group_object_list
listGrp = bpy.context.scene.hk_group_list

if len(list) == 0 or len(listGrp) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_object_list_index
indexGrp = bpy.context.scene.hk_group_list_index


bpy.ops.object.select_all(action='DESELECT') # Tum secimleri kaldirir

# Object listesinde secili obje Group listesinde secili gruptan ayriliyor
print( bpy.data.objects[list[index].name] )
print( listGrp[indexGrp].name )

o = bpy.data.objects[list[index].name]
o.select = True # Obje seciliyor
bpy.context.scene.objects.active = o # Obje aktiflestiriliyor
bpy.ops.group.objects_remove(group=listGrp[indexGrp].name)

loadGroupObjectList()


return {"FINISHED"}


# GROUP LISTESINDE SECILI GROUP'UN TUM BAGINI KOPARIR (UNLINK)
class HK_UnlinkSelGrp(bpy.types.Operator):
bl_label = "Unlink Selected Group"
bl_description = "Unlink selected group."
bl_idname = "scene.hk_unlink_selected_group"

def execute(self, context):
unlinkGroup(False)

return {"FINISHED"}


# GROUP LISTESINDE SECILI GROUP'U SILER (REMOVE)
class HK_RemoveSelGrp(bpy.types.Operator):
bl_label = "Remove Selected Group"
bl_description = "Remove selected group."
bl_idname = "scene.hk_remove_selected_group"

def execute(self, context):
# Show Message Box
if len(bpy.context.scene.hk_group_list) > 0:
bpy.ops.error.hk_msgbox('INVOKE_DEFAULT')

return {"FINISHED"}


# SECILI GROUP'A BAGLI TUM OBJELERI SECIME EKLER
class HK_SelectGroup(bpy.types.Operator):
bl_label = "Select Group"
bl_description = "Select group."
bl_idname = "scene.hk_select_group_list"

def execute(self, context):
list = bpy.context.scene.hk_group_list

if len(list) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_list_index
grp = bpy.data.groups[list[index].name]


if len(grp.objects) > 0:
for o in grp.objects:
o.select = True # Seciliyor, ama aktif obje olmuyor

return {"FINISHED"}


# SECILI GROUP'A BAGLI TUM OBJELERIN SECIMINI KALDIRIR
class HK_DeselectGroup(bpy.types.Operator):
bl_label = "Deselect Group"
bl_description = "Deselect group."
bl_idname = "scene.hk_deselect_group_list"

def execute(self, context):
list = bpy.context.scene.hk_group_list

if len(list) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_list_index
grp = bpy.data.groups[list[index].name]


if len(grp.objects) > 0:
for o in grp.objects:
o.select = False # Secim kaldiriliyor, aktiflige karisilmiyor

return {"FINISHED"}


# OBJE LISTESINDEN SECILI OBJEYI SECER
class HK_SelectObjectListGroup(bpy.types.Operator):
bl_label = "Select Object Group List"
bl_description = "Select object from object list."
bl_idname = "scene.hk_select_object_group_list"

def execute(self, context):
list = bpy.context.scene.hk_group_object_list

if len(list) == 0:
return {"FINISHED"}

index = bpy.context.scene.hk_group_object_list_index

bpy.ops.object.select_all(action='DESELECT') # Tum secimleri kaldirir

# Object seciliyor (Object listesinde secili olan)
o = bpy.data.objects[list[index].name]
o.select = True # Obje seciliyor
bpy.context.scene.objects.active = o # Obje aktiflestiriliyor

return {"FINISHED"}


#======================================================================


iIndexTmp = 0

class SCENE_PT_HK_GroupEditor_ItemList(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
layout.label(item.name)

#iIndex = getattr(data, active_propname)
#if hasattr(data, active_propname) and iIndex >= 0:
#loadGroupObjectList()


class HK_MsgBox(bpy.types.Operator):
bl_idname = "error.hk_msgbox"
bl_label = "Remove Group"

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

def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self, width=200)

def draw(self, context):
self.layout.label("Are you sure?", icon="CANCEL")


bpy.utils.register_class(HK_MsgBox)


# GROUP EDITOR PANEL GUI - GROUPS KISMI
#
# NOT: Blender ayni panelde iki listenin olmasini desteklemiyor.
# Bu yuzden listeler iki ayri panele yerlestirildi.
class SCENE_PT_HK_GroupEditor_Groups(bpy.types.Panel):
bl_label = "Group Editor - Groups"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'DEFAULT_CLOSED'}


# Liste icin ozellikler tanimlaniyor. "bpy.types.Scene" kisminda ne
# kullanilmissa, "row.template_list" kisminda da onunla ilgili bir deger
# kullanilmali. "bpy.context.scene" gibi.
#
# Burada "hk_group_list" group listesinden secilen elemani,
# "hk_group_list_index" ise listeden secilen elemanin sira numarasini tutar.
bpy.types.Scene.hk_group_list = bpy.props.CollectionProperty(type=GroupList)
bpy.types.Scene.hk_group_list_index = bpy.props.IntProperty()

# Group Name TextBox
bpy.types.Scene.hk_group_name_txt = bpy.props.StringProperty(name="")


def draw(self, context):
scn = bpy.context.scene

layout = self.layout

row = layout.row()
row.template_list( "SCENE_PT_HK_GroupEditor_ItemList",
"",
context.scene,
"hk_group_list",
context.scene,
"hk_group_list_index"
) # Group List

row = layout.row()
row.operator("scene.hk_rename_group_list", text="", icon="OUTLINER_DATA_FONT")
row.operator("scene.hk_select_group_list", text="", icon="SPACE2")
row.operator("scene.hk_deselect_group_list", text="", icon="SPACE3")
row.operator("scene.hk_refresh_group_list", text="Refresh", icon="FILE_REFRESH")

row = layout.row()
row.prop(context.scene, "hk_group_name_txt")

row = layout.row()
row.operator("scene.hk_get_group_contents_list", text="", icon="STYLUS_PRESSURE")
row.operator("scene.hk_create_new_group_list", text="", icon="NEW")
row.operator("scene.hk_add_object_group_list", text="", icon="ZOOMIN")
row.operator("scene.hk_remove_object_group_list", text="", icon="ZOOMOUT")
row.operator("scene.hk_unlink_selected_group", text="", icon="X")
row.operator("scene.hk_remove_selected_group", text="", icon="CANCEL")


# GROUP EDITOR PANEL GUI - OBJECTS KISMI
class OBJECT_PT_HK_GroupEditor_Objects(bpy.types.Panel):
bl_label = "Group Editor - Objects"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'DEFAULT_CLOSED'}


# Liste icin ozellikler tanimlaniyor. "bpy.types.Scene" kisminda ne
# kullanilmissa, "row.template_list" kisminda da onunla ilgili bir deger
# kullanilmali. "bpy.context.scene" gibi.
#
# Burada "hk_group_object_list" object listesinden secilen elemani,
# "hk_group_object_list_index" ise listeden secilen elemanin sira numarasini tutar.
bpy.types.Scene.hk_group_object_list = bpy.props.CollectionProperty(type=GroupObjectList)
bpy.types.Scene.hk_group_object_list_index = bpy.props.IntProperty()


def draw(self, context):
layout = self.layout

row = layout.row()

row.template_list( "SCENE_PT_HK_GroupEditor_ItemList",
"",
context.scene,
"hk_group_object_list",
context.scene,
"hk_group_object_list_index"
) # Group Object List

row = layout.row()
row.operator("scene.hk_unlink_object_group_list", text="Unlink", icon="X")
row.operator("scene.hk_select_object_group_list", text="Select", icon="SPACE2")


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


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


# MAIN
if __name__ == "__main__":
register()
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. #  This program is free software; you can redistribute it and/or
  4. #  modify it under the terms of the GNU General Public License
  5. #  as published by the Free Software Foundation; either version 2
  6. #  of the License, or (at your option) any later version.
  7. #
  8. #  This program is distributed in the hope that it will be useful,
  9. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #  GNU General Public License for more details.
  12. #
  13. #  You should have received a copy of the GNU General Public License
  14. #  along with this program; if not, write to the Free Software Foundation,
  15. #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. #
  19. # ----
  20. # NOT: "hk_" ile baslayan islevler program icinde tanimlanmis islevlerdir.
  21. # ----
  22. #
  23. # Programmed by: Hikmet Koyuncu @07-2013
  24. # #####
  25.  
  26. bl_info = {
  27.     "name": "Group Editor",
  28.     "author": "Hikmet Koyuncu",
  29.     "version": (0, 3),
  30.     "blender": (2, 6, 6),
  31.     "location": "Properties > Group Editor",
  32.     "description": "Group editor.",
  33.     "category": "Object",
  34.     'wiki_url': '',
  35.     'tracker_url': ''}
  36.  
  37. import bpy
  38.  
  39.  
  40. # GROUP LISTESI ICIN KULLANACAGIMIZ "TYPE" SINIFI
  41. class GroupList(bpy.types.PropertyGroup):
  42.     pass
  43.     #name = bpy.props.StringProperty()
  44.     #value = bpy.props.IntProperty()
  45.  
  46. # "GroupList" sinifi register ediliyor
  47. bpy.utils.register_class(GroupList)
  48.  
  49.  
  50. # OBJECTS LISTESI ICIN KULLANACAGIMIZ "TYPE" SINIFI
  51. class GroupObjectList(bpy.types.PropertyGroup):
  52.     pass
  53.     #name = bpy.props.StringProperty()
  54.     #value = bpy.props.IntProperty()
  55.  
  56. # "GroupObjectList" sinifi register ediliyor
  57. bpy.utils.register_class(GroupObjectList)
  58.  
  59.  
  60. # GROUP LISTESINI TEMIZLER
  61. def clearGroupList():
  62.     list = bpy.context.scene.hk_group_list
  63.     for grp in list.items():
  64.         list.remove(0)
  65.        
  66.        
  67. # OBJECT LISTESINI TEMIZLER
  68. def clearGroupObjectList():
  69.     list = bpy.context.scene.hk_group_object_list
  70.     for obj in list.items():
  71.         list.remove(0)
  72.        
  73.        
  74. # GROUP LISTESINI DOLDURUR
  75. def loadGroupList():
  76.     # Listeye elemanlar ekleniyor
  77.     if "hk_group_list" in dir(bpy.context.scene):
  78.         list = bpy.context.scene.hk_group_list
  79.         index = bpy.context.scene.hk_group_list_index
  80.        
  81.         # Liste temizleniyor
  82.         clearGroupList()
  83.        
  84.         if len(bpy.data.groups) == 0: return
  85.        
  86.         for grp in bpy.data.groups:
  87.             if grp != None and grp.users > 0:
  88.                 grp_member = list.add()
  89.                 grp_member.name  = grp.name
  90.                 grp_member.value = grp.name
  91.                
  92.         # Listeden en sondaki eleman silindiginde,
  93.         # bir onceki elemanin secilmesini saglar.
  94.         count = len(list)
  95.         if count > 0 and index == count:
  96.             bpy.context.scene.hk_group_list_index = index - 1
  97.            
  98.            
  99. # GROUP OBJECTS LISTESINI DOLDURUR
  100. def loadGroupObjectList():
  101.     # Listeye elemanlar ekleniyor
  102.     if "hk_group_object_list" in dir(bpy.context.scene):
  103.         list = bpy.context.scene.hk_group_object_list
  104.         listGrp = bpy.context.scene.hk_group_list
  105.         index = bpy.context.scene.hk_group_object_list_index
  106.         indexGrp = bpy.context.scene.hk_group_list_index
  107.        
  108.         # Liste temizleniyor
  109.         clearGroupObjectList()
  110.        
  111.         grp = bpy.data.groups[listGrp[indexGrp].name]
  112.         if grp.objects == 0: return
  113.        
  114.         for obj in grp.objects:
  115.             if obj != None:
  116.                 obj_member = list.add()
  117.                 obj_member.name  = obj.name
  118.                 obj_member.value = obj.name
  119.                
  120.         # Listeden en sondaki eleman silindiginde,
  121.         # bir onceki elemanin secilmesini saglar.
  122.         count = len(list)
  123.         if count > 0 and index == count:
  124.             bpy.context.scene.hk_group_object_list_index = index - 1
  125.                      
  126.            
  127. # GROUP SILER
  128. def unlinkGroup(isRemove):
  129.     list = bpy.context.scene.hk_group_list
  130.  
  131.     if len(list) == 0:
  132.         return {"FINISHED"}
  133.        
  134.     index = bpy.context.scene.hk_group_list_index
  135.     grp = bpy.data.groups[list[index].name]
  136.  
  137.     bpy.context.user_preferences.edit.use_global_undo = False
  138.    
  139.            
  140.     # Group'u objelerden koparir
  141.     if len(grp.objects) > 0:
  142.         for o in grp.objects:              
  143.             grp.objects.unlink(o)
  144.    
  145.    
  146.     if isRemove == True:
  147.         grp.user_clear() # Group'u siler
  148.    
  149.     loadGroupObjectList() # Group Object listesini gunceller
  150.    
  151.     bpy.context.user_preferences.edit.use_global_undo = True
  152.    
  153.     loadGroupList() # Group listesi guncelleniyor
  154.            
  155.            
  156. #======================================================================
  157.        
  158.        
  159. # GROUP LISTESINI GUNCELLER
  160. class HK_RefreshGroupList(bpy.types.Operator):
  161.     bl_label = "Refresh Group List"
  162.     bl_description = "Refresh Group list."
  163.     bl_idname = "scene.hk_refresh_group_list"
  164.    
  165.     def execute(self, context):
  166.         loadGroupList()
  167.         return {"FINISHED"}
  168.    
  169.    
  170. # OBJECT LISTESINI GUNCELLER
  171. class HK_RefreshObjectList(bpy.types.Operator):
  172.     bl_label = "Refresh Group Object List"
  173.     bl_description = "Refresh Group Object list."
  174.     bl_idname = "scene.hk_refresh_group_object_list"
  175.    
  176.     def execute(self, context):
  177.         loadGroupObjectList()
  178.         return {"FINISHED"}
  179.    
  180.  
  181. # GROUP LISTESINDEKI SECILI GRUBUN ICINDEKI OBJELERI LISTELER
  182. class HK_GetSelectedNameList(bpy.types.Operator):
  183.     bl_label = "Get Selected Group Name from List"
  184.     bl_description = "Get selected group contents (Look 'Object List')."
  185.     bl_idname = "scene.hk_get_group_contents_list"
  186.    
  187.     def execute(self, context):
  188.         list = bpy.context.scene.hk_group_list
  189.        
  190.         if len(list) == 0:
  191.             return {"FINISHED"}
  192.        
  193.         index = bpy.context.scene.hk_group_list_index
  194.         grp = bpy.data.groups[list[index].name]
  195.        
  196.         # Listeden secili elemanin ismi textbox'a aktariliyor...
  197.         bpy.context.scene.hk_group_name_txt = grp.name
  198.        
  199.         loadGroupObjectList()
  200.        
  201.         return {"FINISHED"}
  202.  
  203.  
  204. # SECILI GROUP'UN ISMINI DEGISTIRIR
  205. class HK_RenameGroup(bpy.types.Operator):
  206.     bl_label = "Rename Group"
  207.     bl_description = "Rename Group."
  208.     bl_idname = "scene.hk_rename_group_list"
  209.    
  210.     def execute(self, context):
  211.         list = bpy.context.scene.hk_group_list
  212.        
  213.         if len(list) == 0:
  214.             return {"FINISHED"}
  215.        
  216.         index = bpy.context.scene.hk_group_list_index
  217.         grp = bpy.data.groups[list[index].name]
  218.        
  219.         grp.name = bpy.context.scene.hk_group_name_txt # Group rename
  220.        
  221.         # Group'un listedeki ismi degistiriliyor
  222.         list[index].name = grp.name
  223.        
  224.         return {"FINISHED"}
  225.    
  226.    
  227. # YENI BIR GRUP OLUSTURUR
  228. class HK_CreateNewGroup(bpy.types.Operator):
  229.     bl_label = "Create New Group"
  230.     bl_description = "Create new group."
  231.     bl_idname = "scene.hk_create_new_group_list"
  232.    
  233.     def execute(self, context):      
  234.         bpy.data.groups.new(name="Group") # Yeni bir grup olusturuluyor
  235.        
  236.         loadGroupList() # Group listesi guncelleniyor
  237.        
  238.         return {"FINISHED"}
  239.    
  240.    
  241. # SECILI OBJEYI LISTEDE SECILI GRUBA EKLER
  242. class HK_AddObjectGroup(bpy.types.Operator):
  243.     bl_label = "Add Object Group List"
  244.     bl_description = "Add selected object to group."
  245.     bl_idname = "scene.hk_add_object_group_list"
  246.    
  247.     def execute(self, context):
  248.         list = bpy.context.scene.hk_group_list
  249.        
  250.         if len(list) == 0:
  251.             return {"FINISHED"}
  252.        
  253.         index = bpy.context.scene.hk_group_list_index
  254.        
  255.         # Secili obje group'a baglaniyorz
  256.         bpy.ops.object.group_link(group=list[index].name)
  257.         bpy.ops.group.objects_add_active(group=list[index].name)
  258.        
  259.         loadGroupObjectList() # Object listesi guncelleniyor
  260.        
  261.         return {"FINISHED"}
  262.    
  263.    
  264. # SECILI OBJEYI LISTEDE SECILI GRUBTAN AYIRIR
  265. class HK_RemoveObjectGroup(bpy.types.Operator):
  266.     bl_label = "Remove Object Group List"
  267.     bl_description = "Remove selected object from selected group."
  268.     bl_idname = "scene.hk_remove_object_group_list"
  269.    
  270.     def execute(self, context):
  271.         list = bpy.context.scene.hk_group_list
  272.        
  273.         if len(list) == 0:
  274.             return {"FINISHED"}
  275.        
  276.         index = bpy.context.scene.hk_group_list_index
  277.        
  278.         # Secili obje listede secili gruptan ayriliyor
  279.         bpy.ops.group.objects_remove(group=list[index].name)
  280.        
  281.         loadGroupObjectList() # Object listesi guncelleniyor
  282.        
  283.         return {"FINISHED"}
  284.    
  285.    
  286. # OBJE LISTESINDEN SECILI OBJEYI GRUPTAN AYIRIR
  287. class HK_UnlinkObjectListGroup(bpy.types.Operator):
  288.     bl_label = "Unlink Object Group List"
  289.     bl_description = "Unlink selected object from selected group."
  290.     bl_idname = "scene.hk_unlink_object_group_list"
  291.    
  292.     def execute(self, context):
  293.         list = bpy.context.scene.hk_group_object_list
  294.         listGrp = bpy.context.scene.hk_group_list
  295.        
  296.         if len(list) == 0 or len(listGrp) == 0:
  297.             return {"FINISHED"}
  298.        
  299.         index    = bpy.context.scene.hk_group_object_list_index
  300.         indexGrp = bpy.context.scene.hk_group_list_index
  301.        
  302.        
  303.         bpy.ops.object.select_all(action='DESELECT')  # Tum secimleri kaldirir
  304.        
  305.         # Object listesinde secili obje Group listesinde secili gruptan ayriliyor
  306.         print( bpy.data.objects[list[index].name] )
  307.         print( listGrp[indexGrp].name )
  308.        
  309.         o = bpy.data.objects[list[index].name]
  310.         o.select = True  # Obje seciliyor
  311.         bpy.context.scene.objects.active = o  # Obje aktiflestiriliyor
  312.         bpy.ops.group.objects_remove(group=listGrp[indexGrp].name)
  313.        
  314.         loadGroupObjectList()
  315.        
  316.        
  317.         return {"FINISHED"}
  318.    
  319.  
  320. # GROUP LISTESINDE SECILI GROUP'UN TUM BAGINI KOPARIR (UNLINK)
  321. class HK_UnlinkSelGrp(bpy.types.Operator):
  322.     bl_label = "Unlink Selected Group"
  323.     bl_description = "Unlink selected group."
  324.     bl_idname = "scene.hk_unlink_selected_group"
  325.    
  326.     def execute(self, context):
  327.         unlinkGroup(False)
  328.        
  329.         return {"FINISHED"}
  330.  
  331.    
  332. # GROUP LISTESINDE SECILI GROUP'U SILER (REMOVE)
  333. class HK_RemoveSelGrp(bpy.types.Operator):
  334.     bl_label = "Remove Selected Group"
  335.     bl_description = "Remove selected group."
  336.     bl_idname = "scene.hk_remove_selected_group"
  337.    
  338.     def execute(self, context):
  339.         # Show Message Box
  340.         if len(bpy.context.scene.hk_group_list) > 0:
  341.             bpy.ops.error.hk_msgbox('INVOKE_DEFAULT')
  342.        
  343.         return {"FINISHED"}
  344.    
  345.    
  346. # SECILI GROUP'A BAGLI TUM OBJELERI SECIME EKLER
  347. class HK_SelectGroup(bpy.types.Operator):
  348.     bl_label = "Select Group"
  349.     bl_description = "Select group."
  350.     bl_idname = "scene.hk_select_group_list"
  351.    
  352.     def execute(self, context):
  353.         list = bpy.context.scene.hk_group_list
  354.    
  355.         if len(list) == 0:
  356.             return {"FINISHED"}
  357.        
  358.         index = bpy.context.scene.hk_group_list_index
  359.         grp = bpy.data.groups[list[index].name]
  360.        
  361.                
  362.         if len(grp.objects) > 0:
  363.             for o in grp.objects:
  364.                 o.select = True  # Seciliyor, ama aktif obje olmuyor
  365.    
  366.         return {"FINISHED"}
  367.    
  368.    
  369. # SECILI GROUP'A BAGLI TUM OBJELERIN SECIMINI KALDIRIR
  370. class HK_DeselectGroup(bpy.types.Operator):
  371.     bl_label = "Deselect Group"
  372.     bl_description = "Deselect group."
  373.     bl_idname = "scene.hk_deselect_group_list"
  374.    
  375.     def execute(self, context):
  376.         list = bpy.context.scene.hk_group_list
  377.    
  378.         if len(list) == 0:
  379.             return {"FINISHED"}
  380.        
  381.         index = bpy.context.scene.hk_group_list_index
  382.         grp = bpy.data.groups[list[index].name]
  383.        
  384.        
  385.         if len(grp.objects) > 0:
  386.             for o in grp.objects:
  387.                 o.select = False  # Secim kaldiriliyor, aktiflige karisilmiyor
  388.    
  389.         return {"FINISHED"}
  390.    
  391.    
  392. # OBJE LISTESINDEN SECILI OBJEYI SECER
  393. class HK_SelectObjectListGroup(bpy.types.Operator):
  394.     bl_label = "Select Object Group List"
  395.     bl_description = "Select object from object list."
  396.     bl_idname = "scene.hk_select_object_group_list"
  397.    
  398.     def execute(self, context):
  399.         list = bpy.context.scene.hk_group_object_list
  400.        
  401.         if len(list) == 0:
  402.             return {"FINISHED"}
  403.        
  404.         index = bpy.context.scene.hk_group_object_list_index      
  405.        
  406.         bpy.ops.object.select_all(action='DESELECT') # Tum secimleri kaldirir
  407.        
  408.         # Object seciliyor (Object listesinde secili olan)
  409.         o = bpy.data.objects[list[index].name]
  410.         o.select = True  # Obje seciliyor
  411.         bpy.context.scene.objects.active = o  # Obje aktiflestiriliyor
  412.        
  413.         return {"FINISHED"}
  414.  
  415.  
  416. #======================================================================
  417.  
  418.  
  419. iIndexTmp = 0
  420.  
  421. class SCENE_PT_HK_GroupEditor_ItemList(bpy.types.UIList):
  422.   def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):  
  423.     layout.label(item.name)
  424.        
  425.     #iIndex = getattr(data, active_propname)
  426.     #if hasattr(data, active_propname) and iIndex >= 0:
  427.       #loadGroupObjectList()
  428.  
  429.  
  430. class HK_MsgBox(bpy.types.Operator):
  431.     bl_idname = "error.hk_msgbox"
  432.     bl_label = "Remove Group"
  433.  
  434.     def execute(self, context):
  435.         unlinkGroup(True)
  436.         return {'FINISHED'}
  437.  
  438.     def invoke(self, context, event):
  439.         wm = context.window_manager
  440.         return wm.invoke_props_dialog(self, width=200)
  441.  
  442.     def draw(self, context):
  443.         self.layout.label("Are you sure?", icon="CANCEL")
  444.        
  445.  
  446. bpy.utils.register_class(HK_MsgBox)
  447.  
  448.  
  449. # GROUP EDITOR PANEL GUI - GROUPS KISMI
  450. #
  451. # NOT: Blender ayni panelde iki listenin olmasini desteklemiyor.
  452. #      Bu yuzden listeler iki ayri panele yerlestirildi.
  453. class SCENE_PT_HK_GroupEditor_Groups(bpy.types.Panel):
  454.     bl_label = "Group Editor - Groups"
  455.     bl_space_type = "VIEW_3D"
  456.     bl_region_type = "UI"
  457.     bl_options = {'DEFAULT_CLOSED'}
  458.    
  459.                                            
  460.     # Liste icin ozellikler tanimlaniyor. "bpy.types.Scene" kisminda ne
  461.     # kullanilmissa, "row.template_list" kisminda da onunla ilgili bir deger
  462.     # kullanilmali. "bpy.context.scene" gibi.
  463.     #
  464.     # Burada "hk_group_list" group listesinden secilen elemani,
  465.     # "hk_group_list_index" ise listeden secilen elemanin sira numarasini tutar.
  466.     bpy.types.Scene.hk_group_list = bpy.props.CollectionProperty(type=GroupList)
  467.     bpy.types.Scene.hk_group_list_index = bpy.props.IntProperty()
  468.    
  469.     # Group Name TextBox
  470.     bpy.types.Scene.hk_group_name_txt = bpy.props.StringProperty(name="")
  471.    
  472.  
  473.     def draw(self, context):
  474.         scn = bpy.context.scene
  475.    
  476.         layout = self.layout
  477.        
  478.         row = layout.row()
  479.         row.template_list( "SCENE_PT_HK_GroupEditor_ItemList",
  480.                            "",
  481.                            context.scene,
  482.                            "hk_group_list",
  483.                            context.scene,
  484.                            "hk_group_list_index"
  485.         )  # Group List
  486.        
  487.         row = layout.row()
  488.         row.operator("scene.hk_rename_group_list", text="", icon="OUTLINER_DATA_FONT")
  489.         row.operator("scene.hk_select_group_list", text="", icon="SPACE2")
  490.         row.operator("scene.hk_deselect_group_list", text="", icon="SPACE3")
  491.         row.operator("scene.hk_refresh_group_list", text="Refresh", icon="FILE_REFRESH")
  492.        
  493.         row = layout.row()
  494.         row.prop(context.scene, "hk_group_name_txt")
  495.  
  496.         row = layout.row()
  497.         row.operator("scene.hk_get_group_contents_list", text="", icon="STYLUS_PRESSURE")
  498.         row.operator("scene.hk_create_new_group_list", text="", icon="NEW")
  499.         row.operator("scene.hk_add_object_group_list", text="", icon="ZOOMIN")
  500.         row.operator("scene.hk_remove_object_group_list", text="", icon="ZOOMOUT")
  501.         row.operator("scene.hk_unlink_selected_group", text="", icon="X")
  502.         row.operator("scene.hk_remove_selected_group", text="", icon="CANCEL")
  503.        
  504.        
  505. # GROUP EDITOR PANEL GUI - OBJECTS KISMI
  506. class OBJECT_PT_HK_GroupEditor_Objects(bpy.types.Panel):
  507.     bl_label = "Group Editor - Objects"
  508.     bl_space_type = "VIEW_3D"
  509.     bl_region_type = "UI"
  510.     bl_options = {'DEFAULT_CLOSED'}
  511.    
  512.                                            
  513.     # Liste icin ozellikler tanimlaniyor. "bpy.types.Scene" kisminda ne
  514.     # kullanilmissa, "row.template_list" kisminda da onunla ilgili bir deger
  515.     # kullanilmali. "bpy.context.scene" gibi.
  516.     #
  517.     # Burada "hk_group_object_list" object listesinden secilen elemani,
  518.     # "hk_group_object_list_index" ise listeden secilen elemanin sira numarasini tutar.  
  519.     bpy.types.Scene.hk_group_object_list = bpy.props.CollectionProperty(type=GroupObjectList)
  520.     bpy.types.Scene.hk_group_object_list_index = bpy.props.IntProperty()
  521.        
  522.  
  523.     def draw(self, context):  
  524.         layout = self.layout      
  525.        
  526.         row = layout.row()
  527.        
  528.         row.template_list( "SCENE_PT_HK_GroupEditor_ItemList",
  529.                            "",
  530.                            context.scene,
  531.                            "hk_group_object_list",
  532.                            context.scene,
  533.                            "hk_group_object_list_index"
  534.         )  # Group Object List
  535.        
  536.         row = layout.row()
  537.         row.operator("scene.hk_unlink_object_group_list", text="Unlink", icon="X")
  538.         row.operator("scene.hk_select_object_group_list", text="Select", icon="SPACE2")
  539.        
  540.  
  541. def register():
  542.     bpy.utils.register_module(__name__)
  543.  
  544.  
  545. def unregister():
  546.     bpy.utils.unregister_module(__name__)
  547.  
  548.  
  549. # MAIN
  550. if __name__ == "__main__":
  551.     register()
  552.  
go to heaven