Use collection and instance terminology in Python API
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 28 Nov 2018 16:51:29 +0000 (17:51 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 28 Nov 2018 16:51:29 +0000 (17:51 +0100)
This follows naming convention agreed on in T56648.

17 files changed:
add_dimension.py
add_mesh_clusters/__init__.py
add_mesh_space_tree/__init__.py
amaranth/misc/dupli_group_id.py
cacharanth/meshcache.py
cacharanth/ui.py
data_overrides/ui.py
io_atomblend_utilities/io_atomblend_utilities.py
io_directx_bel/bel/group.py
io_directx_bel/bel/ob.py
io_mesh_xyz/import_xyz.py
io_scene_fpx/fpx_import.py
object_color_rules.py
oscurart_mesh_cache_tools.py
space_view3d_enhanced_3d_cursor.py
space_view3d_library_hide.py
space_view3d_toolshelf_menu.py

index f78d448..6468d94 100644 (file)
@@ -1748,10 +1748,10 @@ def createCurve(vertArray, self, align_matrix):
 
     bpy.ops.object.mode_set(mode = 'OBJECT')
 
-    if group_name in bpy.data.groups:
-        group = bpy.data.groups[group_name]
+    if group_name in bpy.data.collections:
+        group = bpy.data.collections[group_name]
     else:
-        group = bpy.data.groups.new(group_name)
+        group = bpy.data.collections.new(group_name)
 
     if not DimensionCurve.name in group.objects:
         group.objects.link(DimensionCurve)
index f384f03..38c1c3a 100644 (file)
@@ -356,7 +356,7 @@ def DEF_atom_draw_atoms(prop_element,
 
     ball.active_material = material
     ball.parent = new_atom_mesh
-    new_atom_mesh.dupli_type = 'VERTS'
+    new_atom_mesh.instance_type = 'VERTS'
 
     # ------------------------------------------------------------------------
     # SELECT ALL LOADED OBJECTS
index 3f26e98..629b142 100644 (file)
@@ -67,12 +67,12 @@ from .timer import Timer
 
 
 def availableGroups(self, context):
-    return [(name, name, name, n) for n, name in enumerate(bpy.data.groups.keys())]
+    return [(name, name, name, n) for n, name in enumerate(bpy.data.collections.keys())]
 
 
 def availableGroupsOrNone(self, context):
     groups = [('None', 'None', 'None', 1)]
-    return groups + [(name, name, name, n + 1) for n, name in enumerate(bpy.data.groups.keys())]
+    return groups + [(name, name, name, n + 1) for n, name in enumerate(bpy.data.collections.keys())]
 
 
 def availableObjects(self, context):
@@ -157,9 +157,9 @@ def halton3D(index):
 
 
 def insidegroup(pointrelativetocursor, group):
-    if bpy.data.groups.find(group) < 0:
+    if bpy.data.collections.find(group) < 0:
         return False
-    for ob in bpy.data.groups[group].objects:
+    for ob in bpy.data.collections[group].objects:
         if pointInsideMesh(pointrelativetocursor, ob):
             return True
     return False
@@ -169,8 +169,8 @@ def groupdistribution(crowngroup, shadowgroup=None, seed=0, size=Vector((1, 1, 1
                       pointrelativetocursor=Vector((0, 0, 0))):
     if crowngroup == shadowgroup:
         shadowgroup = None  # safeguard otherwise every marker would be rejected
-    nocrowngroup = bpy.data.groups.find(crowngroup) < 0
-    noshadowgroup = (shadowgroup is None) or (bpy.data.groups.find(shadowgroup) < 0) or (shadowgroup == 'None')
+    nocrowngroup = bpy.data.collections.find(crowngroup) < 0
+    noshadowgroup = (shadowgroup is None) or (bpy.data.collections.find(shadowgroup) < 0) or (shadowgroup == 'None')
     index = 100 + seed
     nmarkers = 0
     nyield = 0
@@ -199,8 +199,8 @@ def groupExtends(group):
     of the bounding box in world space that encapsulates all objects in a group.
     """
     bb = []
-    if bpy.data.groups.find(group) >= 0:
-        for ob in bpy.data.groups[group].objects:
+    if bpy.data.collections.find(group) >= 0:
+        for ob in bpy.data.collections[group].objects:
             rot = ob.matrix_world.to_quaternion()
             scale = ob.matrix_world.to_scale()
             translate = ob.matrix_world.translation
@@ -954,8 +954,8 @@ class SCATree(bpy.types.Operator):
 
         startingpoints = []
         if self.useTrunkGroup:
-            if bpy.data.groups.find(self.trunkGroup) >= 0:
-                for ob in bpy.data.groups[self.trunkGroup].objects:
+            if bpy.data.collections.find(self.trunkGroup) >= 0:
+                for ob in bpy.data.collections[self.trunkGroup].objects:
                     p = ob.location - context.scene.cursor_location
                     startingpoints.append(Branchpoint(p, None))
 
index 3c42eae..b131eef 100644 (file)
@@ -73,8 +73,8 @@ def ui_dupli_group_library_path(self, context):
     row = self.layout.row()
     row.alignment = "LEFT"
 
-    if ob and ob.dupli_group and ob.dupli_group.library:
-        lib = ob.dupli_group.library.filepath
+    if ob and ob.instance_collection and ob.instance_collection.library:
+        lib = ob.instance_collection.library.filepath
 
         row.operator(AMTH_SCENE_OT_blender_instance_open.bl_idname,
                      text="Library: %s" % lib,
@@ -94,7 +94,7 @@ class AMTH_OBJECT_OT_id_dupligroup(bpy.types.Operator):
 
     @classmethod
     def poll(cls, context):
-        return context.active_object.dupli_group
+        return context.active_object.instance_collection
 
     def execute(self, context):
         self.__class__.clear = False
@@ -105,8 +105,8 @@ class AMTH_OBJECT_OT_id_dupligroup(bpy.types.Operator):
         obdata = 'bpy.data.objects[" % s"]' % ob.name
         # TODO: cleanup script var using format or template strings
         script = "%s" % (
-            "\nif %(obdata)s and %(obdata)s.dupli_group and %(obdata)s.pass_index != 0: %(obname)s \n"
-            "    for dob in %(obdata)s.dupli_group.objects: %(obname)s \n"
+            "\nif %(obdata)s and %(obdata)s.instance_collection and %(obdata)s.pass_index != 0: %(obname)s \n"
+            "    for dob in %(obdata)s.instance_collection.objects: %(obname)s \n"
             "        dob.pass_index = %(obdata)s.pass_index %(obname)s \n" %
             {"obdata": obdata, "obname": script_intro})
 
@@ -122,9 +122,9 @@ class AMTH_OBJECT_OT_id_dupligroup(bpy.types.Operator):
             amth_text.write(script_intro)
             amth_text.write(script)
 
-        if ob and ob.dupli_group:
+        if ob and ob.instance_collection:
             if ob.pass_index != 0:
-                for dob in ob.dupli_group.objects:
+                for dob in ob.instance_collection.objects:
                     dob.pass_index = ob.pass_index
 
         self.report({"INFO"},
@@ -143,7 +143,7 @@ class AMTH_OBJECT_OT_id_dupligroup_clear(bpy.types.Operator):
 
     @classmethod
     def poll(cls, context):
-        return context.active_object.dupli_group
+        return context.active_object.instance_collection
 
     def execute(self, context):
         context.active_object.pass_index = 0
@@ -165,7 +165,7 @@ class AMTH_OBJECT_OT_id_dupligroup_clear(bpy.types.Operator):
 
 def ui_object_id_duplis(self, context):
 
-    if context.active_object.dupli_group:
+    if context.active_object.instance_collection:
         split = self.layout.split()
         row = split.row(align=True)
         row.enabled = context.active_object.pass_index != 0
index ef6417b..b259da4 100644 (file)
@@ -83,7 +83,7 @@ class MeshcacheOperator():
     def poll(cls, context):
         if context.scene.meshcache_apply_to == 'GROUP':
             # XXX doesn't seem correct
-            return bpy.data.groups
+            return bpy.data.collections
         else:
             return context.active_object is not None
 
@@ -92,7 +92,7 @@ class MeshcacheOperator():
         scene = context.scene
 
         if scene.meshcache_apply_to == 'GROUP':
-            objects = bpy.data.groups[scene.meshcache_group].objects
+            objects = bpy.data.collections[scene.meshcache_group].objects
         else:
             objects = context.selected_objects
 
index eb2c900..00a680a 100644 (file)
@@ -43,17 +43,17 @@ class CACHARANTH_GroupSelect(Operator):
     bl_description = "Switch to another material in this mesh"
 
     def avail_groups(self,context):
-        items = [(str(i),x.name,x.name, "GROUP", i) for i,x in enumerate(bpy.data.groups)]
+        items = [(str(i),x.name,x.name, "GROUP", i) for i,x in enumerate(bpy.data.collections)]
         return items
 
     group_select = bpy.props.EnumProperty(items = avail_groups, name = "Available Groups")
 
     @classmethod
     def poll(cls, context):
-        return bpy.data.groups
+        return bpy.data.collections
 
     def execute(self,context):
-        bpy.context.scene.meshcache_group = bpy.data.groups[int(self.group_select)].name
+        bpy.context.scene.meshcache_group = bpy.data.collections[int(self.group_select)].name
         return {'FINISHED'}
 
 
@@ -135,9 +135,9 @@ class VIEW3D_PT_MeshcacheToolsPanel(Panel):
         row.prop(scene, "meshcache_apply_to", expand=True)
 
         if scene.meshcache_apply_to == 'GROUP':
-            if bpy.data.groups:
+            if bpy.data.collections:
                 row = layout.row(align=True)
-                row.enabled = len(bpy.data.groups) != 0
+                row.enabled = len(bpy.data.collections) != 0
                 row.label(text="Select Group:")
                 row.operator_menu_enum("cacharanth.group_select",
                                                "group_select",
index e518cfe..e4998dc 100644 (file)
@@ -29,8 +29,8 @@ from data_overrides.override import *
 '''
 def id_data_children(id_data):
     if isinstance(id_data, bpy.types.Object):
-        if id_data.dupli_type == 'GROUP' and id_data.dupli_group:
-            yield id_data.dupli_group
+        if id_data.instance_type == 'COLLECTION' and id_data.instance_collection:
+            yield id_data.instance_collection
     elif isinstance(id_data, bpy.types.Group):
         for ob in id_data.objects:
             yield ob
index ef77962..9562a7c 100644 (file)
@@ -419,7 +419,7 @@ def separate_atoms(scn):
     atom = bpy.context.edit_object
 
     # Do nothing if it is not a dupliverts structure.
-    if not atom.dupli_type == "VERTS":
+    if not atom.instance_type == "VERTS":
        return {'FINISHED'}
 
     bm = bmesh.from_edit_mesh(atom.data)
index 05f3846..2e39b84 100644 (file)
@@ -9,17 +9,17 @@ naming_method = 3   create new, replace existing
 '''
 
 def new(name,naming_method):
-    if name in bpy.data.groups and naming_method :
-        grp = bpy.data.groups[name]
+    if name in bpy.data.collections and naming_method :
+        grp = bpy.data.collections[name]
         # if naming_method == 1 return existing
         if naming_method == 2 :
-            grp = bpy.data.groups.new(name)
+            grp = bpy.data.collections.new(name)
             grp.name = name
         elif naming_method == 3 :
-            bpy.data.groups.remove(grp)
-            grp = bpy.data.groups.new(name)
+            bpy.data.collections.remove(grp)
+            grp = bpy.data.collections.new(name)
     else :
-        grp = bpy.data.groups.new(name)
+        grp = bpy.data.collections.new(name)
     return grp
 
 ##  TODO
@@ -56,8 +56,8 @@ def remove(ob,with_data=True) :
 
             # odd (pre 2.60) :
             # ob=bpy.data.objects[ob.name]
-            # if the ob (board) argument comes from bpy.data.groups['aGroup'].objects,
-            #  bpy.data.groups['board'].objects['board'].users_scene
+            # if the ob (board) argument comes from bpy.data.collections['aGroup'].objects,
+            #  bpy.data.collections['board'].objects['board'].users_scene
             ob.name = '_dead'
             for sc in ob.users_scene :
                 sc.objects.unlink(ob)
index 52e6352..b9fec3b 100644 (file)
@@ -56,8 +56,8 @@ def remove(ob,with_data=True) :
 
             # odd (pre 2.60) :
             # ob=bpy.data.objects[ob.name]
-            # if the ob (board) argument comes from bpy.data.groups['aGroup'].objects,
-            #  bpy.data.groups['board'].objects['board'].users_scene
+            # if the ob (board) argument comes from bpy.data.collections['aGroup'].objects,
+            #  bpy.data.collections['board'].objects['board'].users_scene
             ob.name = '_dead'
             for sc in ob.users_scene :
                 sc.objects.unlink(ob)
index eedd5c3..798d923 100644 (file)
@@ -647,7 +647,7 @@ def import_xyz(Ball_type,
             ball.name = "Ball (NURBS)_"+atom.name
         ball.active_material = atom.material
         ball.parent = new_atom_mesh
-        new_atom_mesh.dupli_type = 'VERTS'
+        new_atom_mesh.instance_type = 'VERTS'
         # The object is back translated to 'object_center_vec'.
         new_atom_mesh.location = object_center_vec
         STRUCTURE.append(new_atom_mesh)
index 42cea23..6b7170f 100644 (file)
@@ -2657,8 +2657,8 @@ class FptImporter():
 
             blender_empty_object_new.parent = blender_empty_object
 
-            #blender_empty_object_new.dupli_type = 'GROUP'
-            #blender_empty_object_new.dupli_group = blender_group
+            #blender_empty_object_new.instance_type = 'COLLECTION'
+            #blender_empty_object_new.instance_collection = blender_group
             blender_empty_object_new.layers = layers
             blender_empty_object_new.select = True
             """
index fea8c1c..4b2f59f 100644 (file)
@@ -62,7 +62,7 @@ class rule_test:
     def GROUP(obj, rule, cache):
         if not cache:
             match_name = rule.match_name
-            objects = {o for g in bpy.data.groups if test_name(rule, match_name, g.name) for o in g.objects}
+            objects = {o for g in bpy.data.collections if test_name(rule, match_name, g.name) for o in g.objects}
             cache["objects"] = objects
         else:
             objects = cache["objects"]
index a28fe65..598b601 100644 (file)
@@ -59,7 +59,7 @@ class CreaPropiedades(Operator):
     bl_label = "Create Auto Load PC Proxy List"
 
     def execute(self, context):
-        for gr in bpy.data.groups:
+        for gr in bpy.data.collections:
             if gr.library is not None:
                 i = bpy.context.scene.pc_auto_load_proxy.add()
                 i.name = gr.name
@@ -92,7 +92,7 @@ class OscurartMeshCacheSceneAutoLoad(PropertyGroup):
 def CargaAutoLoadPC(dummy):
     for gr in bpy.context.scene.pc_auto_load_proxy:
         if gr.use_auto_load:
-            for ob in bpy.data.groups[gr.name].objects:
+            for ob in bpy.data.collections[gr.name].objects:
                 for MOD in ob.modifiers:
                     if MOD.type == "MESH_CACHE":
                         MOD.cache_format = "PC2"
@@ -151,7 +151,7 @@ class OscEPc2ExporterPanel(View3DMCPanel, Panel):
         row.prop(scene, "pc_pc2_start", text="Frame Start")
         row.prop(scene, "pc_pc2_end", text="Frame End")
         row.prop(scene, "pc_pc2_exclude", text="Exclude Token:")
-        row.prop_search(scene, "pc_pc2_group", bpy.data, "groups", text="")
+        row.prop_search(scene, "pc_pc2_group", bpy.data, "collections", text="")
         row.operator("export_shape.pc2_selection", text="Export!", icon="POSE_DATA")
         row.prop(scene, "pc_pc2_world_space", text="World Space")
         row = layout.box().column(align=1)
@@ -164,9 +164,9 @@ class OscEPc2ExporterPanel(View3DMCPanel, Panel):
         row.operator("scene.pc_auto_load_proxy_remove", text="Remove List", icon="X")
 
         for i in scene.pc_auto_load_proxy:
-            if bpy.data.groups[i.name].library is not None:
+            if bpy.data.collections[i.name].library is not None:
                 row = layout.row()
-                row.prop(bpy.data.groups[i.name], "name", text="")
+                row.prop(bpy.data.collections[i.name], "name", text="")
                 row.prop(i, "use_auto_load", text="")
 
 
@@ -199,7 +199,7 @@ def OscFuncExportPc2(self):
     folderpath = bpy.context.scene.pc_pc2_folder
     framerange = end - start
 
-    for ob in bpy.data.groups[bpy.context.scene.pc_pc2_group].objects[:]:
+    for ob in bpy.data.collections[bpy.context.scene.pc_pc2_group].objects[:]:
         if any(token not in ob.name for token in bpy.context.scene.pc_pc2_exclude.split(",")):
             bpy.context.window_manager.progress_begin(0, 100)  # progressbar
             if ob.type == "MESH":
@@ -270,7 +270,7 @@ class OscRemoveSubsurf(Operator):
                 'DECIMATE', 'MASK', 'MIRROR', 'REMESH', 'SCREW',
                 'SKIN', 'SOLIDIFY', 'SUBSURF', 'TRIANGULATE'
                 ]
-        for OBJ in bpy.data.groups[bpy.context.scene.pc_pc2_group].objects[:]:
+        for OBJ in bpy.data.collections[bpy.context.scene.pc_pc2_group].objects[:]:
             for MOD in OBJ.modifiers[:]:
                 if MOD.type in GENERATE:
                     if eval("bpy.context.scene.mesh_cache_tools_settings.%s" % (MOD.type.lower())):
@@ -306,14 +306,14 @@ def OscLinkedGroupToLocal():
     try:
         ACTOBJ = bpy.context.active_object
 
-        if not ACTOBJ.id_data.dupli_group:
+        if not ACTOBJ.id_data.instance_collection:
             return False
 
-        GROBJS = [ob for ob in ACTOBJ.id_data.dupli_group.objects[:] if ob.type == "MESH"]
+        GROBJS = [ob for ob in ACTOBJ.id_data.instance_collection.objects[:] if ob.type == "MESH"]
 
-        for ob in ACTOBJ.id_data.dupli_group.objects[:]:
+        for ob in ACTOBJ.id_data.instance_collection.objects[:]:
             bpy.context.scene.objects.link(ob)
-        NEWGROUP = bpy.data.groups.new("%s_CLEAN" % (ACTOBJ.name))
+        NEWGROUP = bpy.data.collections.new("%s_CLEAN" % (ACTOBJ.name))
         bpy.context.scene.objects.unlink(ACTOBJ)
         NEWOBJ = []
         for ob in GROBJS:
index 5d0c0ac..7afa1ad 100644 (file)
@@ -3186,14 +3186,14 @@ class MeshCache:
             # (though it'd be better to change the logic in the raycasting)
             tmp_obj.show_in_front = src_obj.show_in_front
 
-            tmp_obj.dupli_faces_scale = src_obj.dupli_faces_scale
-            tmp_obj.dupli_frames_end = src_obj.dupli_frames_end
-            tmp_obj.dupli_frames_off = src_obj.dupli_frames_off
-            tmp_obj.dupli_frames_on = src_obj.dupli_frames_on
-            tmp_obj.dupli_frames_start = src_obj.dupli_frames_start
-            tmp_obj.dupli_group = src_obj.dupli_group
+            tmp_obj.instance_faces_scale = src_obj.instance_faces_scale
+            tmp_obj.instance_frames_end = src_obj.instance_frames_end
+            tmp_obj.instance_frames_off = src_obj.instance_frames_off
+            tmp_obj.instance_frames_on = src_obj.instance_frames_on
+            tmp_obj.instance_frames_start = src_obj.instance_frames_start
+            tmp_obj.instance_collection = src_obj.instance_collection
             #tmp_obj.dupli_list = src_obj.dupli_list
-            tmp_obj.dupli_type = src_obj.dupli_type
+            tmp_obj.instance_type = src_obj.instance_type
 
         # Make Blender recognize object as having geometry
         # (is there a simpler way to do this?)
index dbccd98..e88b1c1 100644 (file)
@@ -75,7 +75,7 @@ def pick_object(context, event, pick_objects, ray_max=10000.0):
             if obj.type == 'MESH':
                 yield (None, obj, obj.matrix_world.copy())
 
-            if obj.dupli_type != 'NONE':
+            if obj.instance_type != 'NONE':
                 print("DupliInst: %r" % obj)
                 obj.dupli_list_create(scene)
                 # matrix = obj.matrix_world.copy()
index ba536cc..5361324 100644 (file)
@@ -1161,12 +1161,12 @@ class VIEW3D_MT_GroupMenu2(Menu):
 
     def draw(self, context):
         layout = self.layout
-        layout.operator("group.create")
-        layout.operator("group.objects_add_active")
+        layout.operator("collection.create")
+        layout.operator("collection.objects_add_active")
         UseSeparator(self, context)
-        layout.operator("group.objects_remove")
-        layout.operator("group.objects_remove_all")
-        layout.operator("group.objects_remove_active")
+        layout.operator("collection.objects_remove")
+        layout.operator("collection.objects_remove_all")
+        layout.operator("collection.objects_remove_active")
 
 
 # ********** Object Camera Options **********