addons-contrib: objects.link/unlink syntax update
authorNBurn <7nburn@gmail.com>
Wed, 30 Jan 2019 02:58:30 +0000 (21:58 -0500)
committerNBurn <7nburn@gmail.com>
Wed, 30 Jan 2019 02:58:30 +0000 (21:58 -0500)
Change objects.link and objects.unlink from scene to collection

26 files changed:
add_dimension.py
add_mesh_clusters/__init__.py
add_mesh_space_tree/__init__.py
camera_overscan.py
curve_tools/Surfaces.py
curve_tools/auto_loft.py
io_atomblend_utilities/io_atomblend_utilities.py
io_directx_bel/bel/mesh.py
io_directx_bel/bel/ob.py
io_directx_bel/import_x.py
io_import_LRO_Lola_MGS_Mola_img.py
io_import_voodoo_camera.py
io_mesh_gwyddion/import_gwyddion.py
io_mesh_xyz/import_xyz.py
io_points_pcd/pcd_utils.py
io_scene_cod/import_xmodel.py
io_scene_fpx/fpx_import.py
io_scene_map/export_map.py
io_scene_open_street_map.py
object_creaprim.py
oscurart_futurism.py
oscurart_mesh_cache_tools.py
oscurart_mesh_thread.py
render_cube_map.py
space_view3d_add_surround_cameras.py
space_view3d_enhanced_3d_cursor.py

index c60c3cd..bdcd665 100644 (file)
@@ -52,7 +52,7 @@ def addText(string = '', loc = ((0, 0, 0)), textsize = 1, align = 'CENTER', offs
         fnt = bpy.data.fonts.load(font)
     tcu.font = fnt
     text.location = loc
         fnt = bpy.data.fonts.load(font)
     tcu.font = fnt
     text.location = loc
-    bpy.context.scene.objects.link(text)
+    bpy.context.collection.objects.link(text)
 
     return text
 
 
     return text
 
@@ -1514,7 +1514,6 @@ def createCurve(vertArray, self, align_matrix):
     name = self.Dimension_Type         # Type as name
 
     # create curve
     name = self.Dimension_Type         # Type as name
 
     # create curve
-    scene = bpy.context.scene
     newCurve = bpy.data.curves.new(name, type = 'CURVE') # curvedatablock
     newSpline = newCurve.splines.new('BEZIER') # spline
 
     newCurve = bpy.data.curves.new(name, type = 'CURVE') # curvedatablock
     newSpline = newCurve.splines.new('BEZIER') # spline
 
@@ -1528,7 +1527,7 @@ def createCurve(vertArray, self, align_matrix):
 
     # create object with newCurve
     DimensionCurve = bpy.data.objects.new(name, newCurve) # object
 
     # create object with newCurve
     DimensionCurve = bpy.data.objects.new(name, newCurve) # object
-    scene.objects.link(DimensionCurve) # place in active scene
+    bpy.context.collection.objects.link(DimensionCurve) # place in active scene
     DimensionCurve.Dimension = True
     DimensionCurve.matrix_world = align_matrix # apply matrix
     self.Dimension_Name = DimensionCurve.name
     DimensionCurve.Dimension = True
     DimensionCurve.matrix_world = align_matrix # apply matrix
     self.Dimension_Name = DimensionCurve.name
index ef2a29a..f034ce4 100644 (file)
@@ -344,7 +344,7 @@ def DEF_atom_draw_atoms(prop_element,
     atom_mesh.from_pydata(atom_vertices, [], [])
     atom_mesh.update()
     new_atom_mesh = bpy.data.objects.new(name, atom_mesh)
     atom_mesh.from_pydata(atom_vertices, [], [])
     atom_mesh.update()
     new_atom_mesh = bpy.data.objects.new(name, atom_mesh)
-    bpy.context.scene.objects.link(new_atom_mesh)
+    bpy.context.collection.objects.link(new_atom_mesh)
 
     bpy.ops.surface.primitive_nurbs_surface_sphere_add(
                             view_align=False, enter_editmode=False,
 
     bpy.ops.surface.primitive_nurbs_surface_sphere_add(
                             view_align=False, enter_editmode=False,
index 6938100..9fc9632 100644 (file)
@@ -320,7 +320,7 @@ def createObjects(tree, parent=None, objectname=None, probability=0.5, size=0.5,
                 obj.rotation_euler = rot[:]
                 obj.scale = [scale, scale, scale]
                 obj.parent = parent
                 obj.rotation_euler = rot[:]
                 obj.scale = [scale, scale, scale]
                 obj.parent = parent
-                bpy.context.scene.objects.link(obj)
+                bpy.context.collection.objects.link(obj)
                 # this is not the best choice of distribution because we might
                 # get negative values especially if sigma is large
                 t += gauss(1.0 / probability, 0.1)
                 # this is not the best choice of distribution because we might
                 # get negative values especially if sigma is large
                 t += gauss(1.0 / probability, 0.1)
@@ -565,7 +565,7 @@ def createGeometry(tree, power=0.5, scale=0.01, addleaves=False, pleaf=0.5,
 
     # create the tree object an make it the only selected and active object in the scene
     obj_new = bpy.data.objects.new(mesh.name, mesh)
 
     # create the tree object an make it the only selected and active object in the scene
     obj_new = bpy.data.objects.new(mesh.name, mesh)
-    base = bpy.context.scene.objects.link(obj_new)
+    base = bpy.context.collection.objects.link(obj_new)
     for ob in bpy.context.scene.objects:
         ob.select_set(False)
     base.select_set(True)
     for ob in bpy.context.scene.objects:
         ob.select_set(False)
     base.select_set(True)
@@ -611,7 +611,7 @@ def createGeometry(tree, power=0.5, scale=0.01, addleaves=False, pleaf=0.5,
                     bleaf, connectoffset
                 )
         obj_leaves = bpy.data.objects.new(mesh.name, mesh)
                     bleaf, connectoffset
                 )
         obj_leaves = bpy.data.objects.new(mesh.name, mesh)
-        base = bpy.context.scene.objects.link(obj_leaves)
+        base = bpy.context.collection.objects.link(obj_leaves)
         obj_leaves.parent = obj_new
         bpy.context.view_layer.objects.active = obj_leaves
         bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
         obj_leaves.parent = obj_new
         bpy.context.view_layer.objects.active = obj_leaves
         bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
@@ -975,7 +975,7 @@ class SCATree(bpy.types.Operator):
         if self.showMarkers:
             mesh = createMarkers(sca, self.markerScale)
             obj_markers = bpy.data.objects.new(mesh.name, mesh)
         if self.showMarkers:
             mesh = createMarkers(sca, self.markerScale)
             obj_markers = bpy.data.objects.new(mesh.name, mesh)
-            base = bpy.context.scene.objects.link(obj_markers)
+            base = bpy.context.collection.objects.link(obj_markers)
         timings.add('showmarkers')
 
         sca.iterate2(newendpointsper1000=self.newEndPointsPer1000, maxtime=self.maxTime)
         timings.add('showmarkers')
 
         sca.iterate2(newendpointsper1000=self.newEndPointsPer1000, maxtime=self.maxTime)
index ab4df77..3be7e7b 100644 (file)
@@ -60,7 +60,7 @@ class CODuplicateCamera(Operator):
                 cam_obj = active_cam.copy()
                 cam_obj.data = active_cam.data.copy()
                 cam_obj.name = "Camera_Overscan"
                 cam_obj = active_cam.copy()
                 cam_obj.data = active_cam.data.copy()
                 cam_obj.name = "Camera_Overscan"
-                context.scene.objects.link(cam_obj)
+                context.collection.objects.link(cam_obj)
         except:
             self.report({'WARNING'}, "Setting up a new Overscan Camera has failed")
             return {'CANCELLED'}
         except:
             self.report({'WARNING'}, "Setting up a new Overscan Camera has failed")
             return {'CANCELLED'}
index cfbf59c..f2a1399 100644 (file)
@@ -119,7 +119,7 @@ class LoftedSurface:
 
         meshObject = bpy.data.objects.new(self.name, mesh)
 
 
         meshObject = bpy.data.objects.new(self.name, mesh)
 
-        bpy.context.scene.objects.link(meshObject)
+        bpy.context.collection.objects.link(meshObject)
 
 
 
 
 
 
@@ -267,7 +267,7 @@ class SweptSurface:
 
         meshObject = bpy.data.objects.new(self.name, mesh)
 
 
         meshObject = bpy.data.objects.new(self.name, mesh)
 
-        bpy.context.scene.objects.link(meshObject)
+        bpy.context.collection.objects.link(meshObject)
 
 
 
 
 
 
@@ -456,4 +456,4 @@ class BirailedSurface:
 
         meshObject = bpy.data.objects.new(self.name, mesh)
 
 
         meshObject = bpy.data.objects.new(self.name, mesh)
 
-        bpy.context.scene.objects.link(meshObject)
+        bpy.context.collection.objects.link(meshObject)
index 70ecc4c..a8bab35 100644 (file)
@@ -19,7 +19,6 @@ class OperatorAutoLoftCurves(Operator):
 
     def execute(self, context):
         #print("### TODO: OperatorLoftCurves.execute()")
 
     def execute(self, context):
         #print("### TODO: OperatorLoftCurves.execute()")
-        scene = context.scene
         mesh = bpy.data.meshes.new("LoftMesh")
 
         curve0 = context.selected_objects[0]
         mesh = bpy.data.meshes.new("LoftMesh")
 
         curve0 = context.selected_objects[0]
@@ -31,7 +30,7 @@ class OperatorAutoLoftCurves(Operator):
 
         loftobj = bpy.data.objects.new(self.name, mesh)
 
 
         loftobj = bpy.data.objects.new(self.name, mesh)
 
-        scene.objects.link(loftobj)
+        context.collection.objects.link(loftobj)
         loftobj["autoloft"] = True
         if loftobj.get('_RNA_UI') is None:
             loftobj['_RNA_UI'] = {}
         loftobj["autoloft"] = True
         if loftobj.get('_RNA_UI') is None:
             loftobj['_RNA_UI'] = {}
index 0d9fd12..3b50f26 100644 (file)
@@ -656,7 +656,7 @@ def draw_obj_special(atom_shape, atom):
         new_mesh.from_pydata([Vector((0.0,0.0,0.0))], [], [])
         new_mesh.update()
         new_atom = bpy.data.objects.new(atom.name + "_sep", new_mesh)
         new_mesh.from_pydata([Vector((0.0,0.0,0.0))], [], [])
         new_mesh.update()
         new_atom = bpy.data.objects.new(atom.name + "_sep", new_mesh)
-        bpy.context.scene.objects.link(new_atom)
+        bpy.context.collection.objects.link(new_atom)
         new_atom.location = atom.location
         material_new = bpy.data.materials.new(atom.active_material.name + "_sep")
         material_new.name = atom.name + "_halo"
         new_atom.location = atom.location
         material_new = bpy.data.materials.new(atom.active_material.name + "_sep")
         material_new.name = atom.name + "_halo"
@@ -698,7 +698,7 @@ def draw_obj_special(atom_shape, atom):
         lamp = bpy.data.objects.new("F2+_lamp", lamp_data)
         lamp.location = Vector((0.0, 0.0, 0.0))
         lamp.layers = current_layers
         lamp = bpy.data.objects.new("F2+_lamp", lamp_data)
         lamp.location = Vector((0.0, 0.0, 0.0))
         lamp.layers = current_layers
-        bpy.context.scene.objects.link(lamp)
+        bpy.context.collection.objects.link(lamp)
         lamp.parent = cube
         # The new 'atom' is the F2+ defect
         new_atom = cube
         lamp.parent = cube
         # The new 'atom' is the F2+ defect
         new_atom = cube
@@ -755,7 +755,7 @@ def draw_obj_special(atom_shape, atom):
         lamp = bpy.data.objects.new("F+_lamp", lamp_data)
         lamp.location = Vector((0.0, 0.0, 0.0))
         lamp.layers = current_layers
         lamp = bpy.data.objects.new("F+_lamp", lamp_data)
         lamp.location = Vector((0.0, 0.0, 0.0))
         lamp.layers = current_layers
-        bpy.context.scene.objects.link(lamp)
+        bpy.context.collection.objects.link(lamp)
         lamp.parent = cube
         # The new 'atom' is the F+ defect complex + lamp
         new_atom = cube
         lamp.parent = cube
         # The new 'atom' is the F+ defect complex + lamp
         new_atom = cube
@@ -823,7 +823,7 @@ def draw_obj_special(atom_shape, atom):
         lamp1 = bpy.data.objects.new("F0_lamp", lamp1_data)
         lamp1.location = Vector((scale[0]*1.5, 0.0, 0.0))
         lamp1.layers = current_layers
         lamp1 = bpy.data.objects.new("F0_lamp", lamp1_data)
         lamp1.location = Vector((scale[0]*1.5, 0.0, 0.0))
         lamp1.layers = current_layers
-        bpy.context.scene.objects.link(lamp1)
+        bpy.context.collection.objects.link(lamp1)
         lamp1.parent = cube
         lamp2_data = bpy.data.lamps.new(name="F0_lamp2", type="POINT")
         lamp2_data.distance = atom.scale[0] * 2.0
         lamp1.parent = cube
         lamp2_data = bpy.data.lamps.new(name="F0_lamp2", type="POINT")
         lamp2_data.distance = atom.scale[0] * 2.0
@@ -833,7 +833,7 @@ def draw_obj_special(atom_shape, atom):
         lamp2 = bpy.data.objects.new("F0_lamp", lamp2_data)
         lamp2.location = Vector((-scale[0]*1.5, 0.0, 0.0))
         lamp2.layers = current_layers
         lamp2 = bpy.data.objects.new("F0_lamp", lamp2_data)
         lamp2.location = Vector((-scale[0]*1.5, 0.0, 0.0))
         lamp2.layers = current_layers
-        bpy.context.scene.objects.link(lamp2)
+        bpy.context.collection.objects.link(lamp2)
         lamp2.parent = cube
         # The new 'atom' is the F0 defect complex + lamps
         new_atom = cube
         lamp2.parent = cube
         # The new 'atom' is the F0 defect complex + lamps
         new_atom = cube
index af29032..1363f04 100644 (file)
@@ -144,7 +144,7 @@ def write(obname,name,
 
     # scene link check
     if obj.name not in bpy.context.scene.objects.keys() :
 
     # scene link check
     if obj.name not in bpy.context.scene.objects.keys() :
-        bpy.context.scene.objects.link(obj)
+        bpy.context.collection.objects.link(obj)
 
     return obj
 
 
     return obj
 
index b9fec3b..2ac50b5 100644 (file)
@@ -12,14 +12,14 @@ def new(name,datatype,naming_method):
             ob = bpy.data.objects.new(name,datatype)
             ob.name = name
         elif naming_method == 3 :
             ob = bpy.data.objects.new(name,datatype)
             ob.name = name
         elif naming_method == 3 :
-            bpy.context.scene.objects.unlink(ob)
+            bpy.context.collection.objects.unlink(ob)
             ob.user_clear()
             bpy.data.objects.remove(ob)
             ob = bpy.data.objects.new(name,datatype)
     else :
         ob = bpy.data.objects.new(name,datatype)
     if ob.name not in bpy.context.scene.objects.keys() :
             ob.user_clear()
             bpy.data.objects.remove(ob)
             ob = bpy.data.objects.new(name,datatype)
     else :
         ob = bpy.data.objects.new(name,datatype)
     if ob.name not in bpy.context.scene.objects.keys() :
-        bpy.context.scene.objects.link(ob)
+        bpy.context.collection.objects.link(ob)
     return ob
 
 ## returns an object or a list of objects
     return ob
 
 ## returns an object or a list of objects
index 7c7bb64..250e36e 100644 (file)
@@ -591,7 +591,7 @@ BINARY FORMAT
             armname = armdata
             armdata = bpy.data.armatures.new(name=armname)
             arm = bpy.data.objects.new(armname,armdata)
             armname = armdata
             armdata = bpy.data.armatures.new(name=armname)
             arm = bpy.data.objects.new(armname,armdata)
-            bpy.context.scene.objects.link(arm)
+            bpy.context.collection.objects.link(arm)
             arm.select_set(True)
             bpy.context.view_layer.objects.active = arm
             bpy.ops.object.mode_set(mode='EDIT')
             arm.select_set(True)
             bpy.context.view_layer.objects.active = arm
             bpy.ops.object.mode_set(mode='EDIT')
index af61289..9df161d 100644 (file)
@@ -440,10 +440,8 @@ class Import(bpy.types.Operator):
         mesh.update()
         ob_new = bpy.data.objects.new(TARGET_NAME, mesh)
         ob_new.data = mesh
         mesh.update()
         ob_new = bpy.data.objects.new(TARGET_NAME, mesh)
         ob_new.data = mesh
-        scene = bpy.context.scene
-        view_layer = bpy.context.view_layer
-        scene.objects.link(ob_new)
-        view_layer.objects.active = ob_new
+        bpy.context.collection.objects.link(ob_new)
+        bpy.context.view_layer.objects.active = ob_new
         ob_new.select_set(True)
         print ('*** End draw   ***')
         print('*** Start Smooth ***')
         ob_new.select_set(True)
         print ('*** End draw   ***')
         print('*** Start Smooth ***')
index 8968b6a..2bc2000 100644 (file)
@@ -58,6 +58,7 @@ def voodoo_import(infile,ld_cam,ld_points):
 
     file = open(infile,'rU')
     scene = bpy.context.scene
 
     file = open(infile,'rU')
     scene = bpy.context.scene
+    collection = bpy.context.collection
     initfr = scene.frame_current
     b24= True
     voodoo_import.frwas= False
     initfr = scene.frame_current
     b24= True
     voodoo_import.frwas= False
@@ -66,7 +67,7 @@ def voodoo_import(infile,ld_cam,ld_points):
     dummy.location = (0.0, 0.0, 0.0)
     dummy.rotation_euler = ( -3.141593/2, 0.0, 0.0)
     dummy.scale = (0.2, 0.2, 0.2)
     dummy.location = (0.0, 0.0, 0.0)
     dummy.rotation_euler = ( -3.141593/2, 0.0, 0.0)
     dummy.scale = (0.2, 0.2, 0.2)
-    scene.objects.link(dummy)
+    collection.objects.link(dummy)
 
     if ld_cam:
         data = bpy.data.cameras.new('voodoo_render_cam')
 
     if ld_cam:
         data = bpy.data.cameras.new('voodoo_render_cam')
@@ -82,7 +83,7 @@ def voodoo_import(infile,ld_cam,ld_points):
         data.clip_start = 0.1
         data.clip_end = 1000.0
         data.display_size = 0.5
         data.clip_start = 0.1
         data.clip_end = 1000.0
         data.display_size = 0.5
-        scene.objects.link(vcam)
+        collection.objects.link(vcam)
         vcam.parent = dummy
 
     if ld_points:
         vcam.parent = dummy
 
     if ld_points:
@@ -94,7 +95,7 @@ def voodoo_import(infile,ld_cam,ld_points):
         # mesh.scale = (5.0, 5.0, 5.0)
         mesh.rotation_euler = (0.0, 0.0, 0.0)
         mesh.scale = (1.0, 1.0, 1.0)
         # mesh.scale = (5.0, 5.0, 5.0)
         mesh.rotation_euler = (0.0, 0.0, 0.0)
         mesh.scale = (1.0, 1.0, 1.0)
-        scene.objects.link(mesh)
+        collection.objects.link(mesh)
         mesh.parent = dummy
 
     verts = []
         mesh.parent = dummy
 
     verts = []
index 9f16ca8..5fd6091 100644 (file)
@@ -205,7 +205,7 @@ def create_mesh(data_list,
         surface_mesh.from_pydata(data_mesh, [], data_faces)
         surface_mesh.update()
         surface = bpy.data.objects.new(image_name, surface_mesh)
         surface_mesh.from_pydata(data_mesh, [], data_faces)
         surface_mesh.update()
         surface = bpy.data.objects.new(image_name, surface_mesh)
-        bpy.context.scene.objects.link(surface)
+        bpy.context.collection.objects.link(surface)
         bpy.ops.object.select_all(action='DESELECT')
         surface.select = True
 
         bpy.ops.object.select_all(action='DESELECT')
         surface.select = True
 
@@ -252,7 +252,7 @@ def create_mesh(data_list,
         camera = bpy.data.objects.new("A_camera", camera_data)
         camera.location = camera_xyz_vec
         camera.layers = current_layers
         camera = bpy.data.objects.new("A_camera", camera_data)
         camera.location = camera_xyz_vec
         camera.layers = current_layers
-        bpy.context.scene.objects.link(camera)
+        bpy.context.collection.objects.link(camera)
 
         # Here the camera is rotated such it looks towards the center of
         # the object. The [0.0, 0.0, 1.0] vector along the z axis
 
         # Here the camera is rotated such it looks towards the center of
         # the object. The [0.0, 0.0, 1.0] vector along the z axis
@@ -303,7 +303,7 @@ def create_mesh(data_list,
         lamp = bpy.data.objects.new("A_lamp", lamp_data)
         lamp.location = lamp_xyz_vec
         lamp.layers = current_layers
         lamp = bpy.data.objects.new("A_lamp", lamp_data)
         lamp.location = lamp_xyz_vec
         lamp.layers = current_layers
-        bpy.context.scene.objects.link(lamp)
+        bpy.context.collection.objects.link(lamp)
 
         bpy.context.scene.world.light_settings.use_ambient_occlusion = True
         bpy.context.scene.world.light_settings.ao_factor = 0.1
 
         bpy.context.scene.world.light_settings.use_ambient_occlusion = True
         bpy.context.scene.world.light_settings.ao_factor = 0.1
index d6804f8..04ab642 100644 (file)
@@ -528,7 +528,7 @@ def import_xyz(Ball_type,
         camera = bpy.data.objects.new("A_camera", camera_data)
         camera.location = camera_xyz_vec
         camera.layers = current_layers
         camera = bpy.data.objects.new("A_camera", camera_data)
         camera.location = camera_xyz_vec
         camera.layers = current_layers
-        bpy.context.scene.objects.link(camera)
+        bpy.context.collection.objects.link(camera)
 
         # Here the camera is rotated such it looks towards the center of
         # the object. The [0.0, 0.0, 1.0] vector along the z axis
 
         # Here the camera is rotated such it looks towards the center of
         # the object. The [0.0, 0.0, 1.0] vector along the z axis
@@ -579,7 +579,7 @@ def import_xyz(Ball_type,
         lamp = bpy.data.objects.new("A_lamp", lamp_data)
         lamp.location = lamp_xyz_vec
         lamp.layers = current_layers
         lamp = bpy.data.objects.new("A_lamp", lamp_data)
         lamp.location = lamp_xyz_vec
         lamp.layers = current_layers
-        bpy.context.scene.objects.link(lamp)
+        bpy.context.collection.objects.link(lamp)
 
         bpy.context.scene.world.light_settings.use_ambient_occlusion = True
         bpy.context.scene.world.light_settings.ao_factor = 0.2
 
         bpy.context.scene.world.light_settings.use_ambient_occlusion = True
         bpy.context.scene.world.light_settings.ao_factor = 0.2
@@ -607,7 +607,7 @@ def import_xyz(Ball_type,
         atom_mesh.from_pydata(atom_vertices, [], [])
         atom_mesh.update()
         new_atom_mesh = bpy.data.objects.new(atom.name, atom_mesh)
         atom_mesh.from_pydata(atom_vertices, [], [])
         atom_mesh.update()
         new_atom_mesh = bpy.data.objects.new(atom.name, atom_mesh)
-        bpy.context.scene.objects.link(new_atom_mesh)
+        bpy.context.collection.objects.link(new_atom_mesh)
 
         # Now, build a representative sphere (atom)
         current_layers=bpy.context.scene.layers
 
         # Now, build a representative sphere (atom)
         current_layers=bpy.context.scene.layers
index e2c1744..6b4315c 100644 (file)
@@ -38,10 +38,8 @@ def create_and_link_mesh(name, points):
     mesh.validate()
     mesh.update()
 
     mesh.validate()
     mesh.update()
 
-    scene = bpy.context.scene
-
     obj = bpy.data.objects.new(name, mesh)
     obj = bpy.data.objects.new(name, mesh)
-    scene.objects.link(obj)
+    bpy.context.collection.objects.link(obj)
     obj.select_set(True)
 
 
     obj.select_set(True)
 
 
index 43f359e..5997686 100644 (file)
@@ -268,7 +268,7 @@ def load(self, context, filepath=""):
             me.from_pydata(vert_table, [], face_table)
             me.update()
             ob = bpy.data.objects.new("Py-Mesh", me)
             me.from_pydata(vert_table, [], face_table)
             me.update()
             ob = bpy.data.objects.new("Py-Mesh", me)
-            bpy.context.scene.objects.link(ob)
+            bpy.context.collection.objects.link(ob)
 
             state = 31
 
 
             state = 31
 
index 8b51454..e7212e3 100644 (file)
@@ -661,6 +661,7 @@ class FptImporter():
         self.__context = blender_context
         self.__data = blender_context.blend_data
         self.__scene = blender_context.scene
         self.__context = blender_context
         self.__data = blender_context.blend_data
         self.__scene = blender_context.scene
+        self.__collection = blender_context.collection
         self.__view_layer = blender_context.view_layer
 
         try:
         self.__view_layer = blender_context.view_layer
 
         try:
@@ -830,7 +831,7 @@ class FptImporter():
                             blender_empty_object.rotation_euler = blender_rotation
                             blender_empty_object.empty_display_type = 'ARROWS'
                             blender_empty_object.empty_display_size = 10.0
                             blender_empty_object.rotation_euler = blender_rotation
                             blender_empty_object.empty_display_type = 'ARROWS'
                             blender_empty_object.empty_display_size = 10.0
-                            self.__scene.objects.link(blender_empty_object)
+                            self.__collection.objects.link(blender_empty_object)
                             blender_empty_object.layers = layers
 
                             blender_empty_object.fpt.name = fpx_item_name
                             blender_empty_object.layers = layers
 
                             blender_empty_object.fpt.name = fpx_item_name
@@ -977,7 +978,7 @@ class FptImporter():
         name = "Camera.table"
         camera = self.__data.cameras.new(name)
         obj = self.__data.objects.new(name, camera)
         name = "Camera.table"
         camera = self.__data.cameras.new(name)
         obj = self.__data.objects.new(name, camera)
-        self.__scene.objects.link(obj)
+        self.__collection.objects.link(obj)
         width = fpx_table_data.get_value("width", default=0.0)
         obj.location = (width / 2.0, -1600.0, 550.0)
         obj.rotation_euler = (radians(63.0), 0.0, 0.0)
         width = fpx_table_data.get_value("width", default=0.0)
         obj.location = (width / 2.0, -1600.0, 550.0)
         obj.rotation_euler = (radians(63.0), 0.0, 0.0)
@@ -1036,14 +1037,14 @@ class FptImporter():
             self.__scene.render.engine = tmp_engine
 
         obj = self.__data.objects.new(FORMAT_LAMP_OBJECT.format(name), lamp)
             self.__scene.render.engine = tmp_engine
 
         obj = self.__data.objects.new(FORMAT_LAMP_OBJECT.format(name), lamp)
-        self.__scene.objects.link(obj)
+        self.__collection.objects.link(obj)
         obj.location = (width2, -length * (2.0/3.0), 600.0)
         obj.layers = FptImporter.LAYERS_AO
 
         # cycles
         mesh = self.__data.meshes.new(FORMAT_MESH.format("{}.arealamp".format(name)))
         obj = self.__data.objects.new(FORMAT_MESH_OBJECT.format(name), mesh)
         obj.location = (width2, -length * (2.0/3.0), 600.0)
         obj.layers = FptImporter.LAYERS_AO
 
         # cycles
         mesh = self.__data.meshes.new(FORMAT_MESH.format("{}.arealamp".format(name)))
         obj = self.__data.objects.new(FORMAT_MESH_OBJECT.format(name), mesh)
-        self.__scene.objects.link(obj)
+        self.__collection.objects.link(obj)
         obj.location = (width2, -length * (2.0/3.0), 610.0)
         obj.layers = FptImporter.LAYERS_AO
         bm = bmesh.new()
         obj.location = (width2, -length * (2.0/3.0), 610.0)
         obj.layers = FptImporter.LAYERS_AO
         bm = bmesh.new()
@@ -1080,7 +1081,7 @@ class FptImporter():
             self.__scene.render.engine = tmp_engine
 
         obj = self.__data.objects.new(FORMAT_LAMP_OBJECT.format(name), lamp)
             self.__scene.render.engine = tmp_engine
 
         obj = self.__data.objects.new(FORMAT_LAMP_OBJECT.format(name), lamp)
-        self.__scene.objects.link(obj)
+        self.__collection.objects.link(obj)
 
         obj.location = location
         obj.layers = layers
 
         obj.location = location
         obj.layers = layers
@@ -1489,7 +1490,7 @@ class FptImporter():
 
         mesh = self.__data.meshes.new(FORMAT_MESH.format(name))
         obj = self.__data.objects.new(FORMAT_MESH_OBJECT.format(name), mesh)
 
         mesh = self.__data.meshes.new(FORMAT_MESH.format(name))
         obj = self.__data.objects.new(FORMAT_MESH_OBJECT.format(name), mesh)
-        self.__scene.objects.link(obj)
+        self.__collection.objects.link(obj)
         obj.layers = FptImporter.LAYERS_AO
 
         #inner playfield
         obj.layers = FptImporter.LAYERS_AO
 
         #inner playfield
@@ -1525,7 +1526,7 @@ class FptImporter():
         mesh_box = self.__data.meshes.new(FORMAT_MESH.format("{}.playfield".format(name)))
         obj_box = self.__data.objects.new(FORMAT_MESH_OBJECT.format("{}.playfield".format(name)), mesh_box)
         obj_box.parent = obj
         mesh_box = self.__data.meshes.new(FORMAT_MESH.format("{}.playfield".format(name)))
         obj_box = self.__data.objects.new(FORMAT_MESH_OBJECT.format("{}.playfield".format(name)), mesh_box)
         obj_box.parent = obj
-        self.__scene.objects.link(obj_box)
+        self.__collection.objects.link(obj_box)
         obj_box.layers = FptImporter.LAYERS_AO
 
         bm = bmesh.new()
         obj_box.layers = FptImporter.LAYERS_AO
 
         bm = bmesh.new()
@@ -1584,7 +1585,7 @@ class FptImporter():
         mesh_translite = self.__data.meshes.new(FORMAT_MESH.format("{}.translite".format(name)))
         obj_translite = self.__data.objects.new(FORMAT_MESH_OBJECT.format("{}.translite".format(name)), mesh_translite)
         obj_translite.parent = obj
         mesh_translite = self.__data.meshes.new(FORMAT_MESH.format("{}.translite".format(name)))
         obj_translite = self.__data.objects.new(FORMAT_MESH_OBJECT.format("{}.translite".format(name)), mesh_translite)
         obj_translite.parent = obj
-        self.__scene.objects.link(obj_translite)
+        self.__collection.objects.link(obj_translite)
         obj_translite.layers = FptImporter.LAYERS_AO
 
         #inner translite
         obj_translite.layers = FptImporter.LAYERS_AO
 
         #inner translite
@@ -1693,7 +1694,7 @@ class FptImporter():
         if rubber_bevel is None:
             cu0 = self.__data.curves.new(bevel_name, 'CURVE')
             rubber_bevel = self.__data.objects.new(bevel_name, cu0)
         if rubber_bevel is None:
             cu0 = self.__data.curves.new(bevel_name, 'CURVE')
             rubber_bevel = self.__data.objects.new(bevel_name, cu0)
-            self.__scene.objects.link(rubber_bevel)
+            self.__collection.objects.link(rubber_bevel)
             cu0.dimensions = '2D'
             cu0.resolution_u = self.resolution_rubber_bevel
 
             cu0.dimensions = '2D'
             cu0.resolution_u = self.resolution_rubber_bevel
 
@@ -1949,7 +1950,7 @@ class FptImporter():
 
         mesh = self.__data.meshes.new(FORMAT_MESH.format(name))
         obj = self.__data.objects.new(FORMAT_MESH_OBJECT.format(name), mesh)
 
         mesh = self.__data.meshes.new(FORMAT_MESH.format(name))
         obj = self.__data.objects.new(FORMAT_MESH_OBJECT.format(name), mesh)
-        self.__scene.objects.link(obj)
+        self.__collection.objects.link(obj)
 
         z = surface + self.debug_light_extrude
         bm = bmesh.new()
 
         z = surface + self.debug_light_extrude
         bm = bmesh.new()
@@ -2022,7 +2023,7 @@ class FptImporter():
             blender_empty_object.rotation_euler = Euler((0, 0, Vector((v.x, v.y)).angle_signed(Vector((1.0, 0.0)))), 'XZY')
             blender_empty_object.empty_display_type = 'ARROWS'
             blender_empty_object.empty_display_size = 10.0
             blender_empty_object.rotation_euler = Euler((0, 0, Vector((v.x, v.y)).angle_signed(Vector((1.0, 0.0)))), 'XZY')
             blender_empty_object.empty_display_type = 'ARROWS'
             blender_empty_object.empty_display_size = 10.0
-            self.__scene.objects.link(blender_empty_object)
+            self.__collection.objects.link(blender_empty_object)
             blender_empty_object.fpt.name = FORMAT_EMPTY_OBJECT.format(FORMAT_MODEL_START.format(name))
             if fpx_id:
                 blender_empty_object.fpt.id = FptElementType.VALUE_INT_TO_NAME.get(fpx_id)
             blender_empty_object.fpt.name = FORMAT_EMPTY_OBJECT.format(FORMAT_MODEL_START.format(name))
             if fpx_id:
                 blender_empty_object.fpt.id = FptElementType.VALUE_INT_TO_NAME.get(fpx_id)
@@ -2039,7 +2040,7 @@ class FptImporter():
             blender_empty_object.rotation_euler = Euler((0, 0, Vector((v.x, v.y)).angle_signed(Vector((1.0, 0.0)))), 'XZY')
             blender_empty_object.empty_display_type = 'ARROWS'
             blender_empty_object.empty_display_size = 10.0
             blender_empty_object.rotation_euler = Euler((0, 0, Vector((v.x, v.y)).angle_signed(Vector((1.0, 0.0)))), 'XZY')
             blender_empty_object.empty_display_type = 'ARROWS'
             blender_empty_object.empty_display_size = 10.0
-            self.__scene.objects.link(blender_empty_object)
+            self.__collection.objects.link(blender_empty_object)
             blender_empty_object.fpt.name = FORMAT_EMPTY_OBJECT.format(FORMAT_MODEL_END.format(name))
             if fpx_id:
                 blender_empty_object.fpt.id = FptElementType.VALUE_INT_TO_NAME.get(fpx_id)
             blender_empty_object.fpt.name = FORMAT_EMPTY_OBJECT.format(FORMAT_MODEL_END.format(name))
             if fpx_id:
                 blender_empty_object.fpt.id = FptElementType.VALUE_INT_TO_NAME.get(fpx_id)
@@ -2137,7 +2138,7 @@ class FptImporter():
             blender_empty_object.rotation_euler = Euler((0, 0, Vector((v.x, v.y)).angle_signed(Vector((1.0, 0.0)))), 'XZY')
             blender_empty_object.empty_display_type = 'ARROWS'
             blender_empty_object.empty_display_size = 10.0
             blender_empty_object.rotation_euler = Euler((0, 0, Vector((v.x, v.y)).angle_signed(Vector((1.0, 0.0)))), 'XZY')
             blender_empty_object.empty_display_type = 'ARROWS'
             blender_empty_object.empty_display_size = 10.0
-            self.__scene.objects.link(blender_empty_object)
+            self.__collection.objects.link(blender_empty_object)
             blender_empty_object.fpt.name = FORMAT_MODEL_RING.format(name, index)
             if fpx_id:
                 blender_empty_object.fpt.id = FptElementType.VALUE_INT_TO_NAME.get(fpx_id)
             blender_empty_object.fpt.name = FORMAT_MODEL_RING.format(name, index)
             if fpx_id:
                 blender_empty_object.fpt.id = FptElementType.VALUE_INT_TO_NAME.get(fpx_id)
@@ -2219,7 +2220,7 @@ class FptImporter():
         if wire_bevel is None:
             cu = self.__data.curves.new(bevel_name, 'CURVE')
             wire_bevel = self.__data.objects.new(bevel_name, cu)
         if wire_bevel is None:
             cu = self.__data.curves.new(bevel_name, 'CURVE')
             wire_bevel = self.__data.objects.new(bevel_name, cu)
-            self.__scene.objects.link(wire_bevel)
+            self.__collection.objects.link(wire_bevel)
             cu.dimensions = '2D'
             cu.resolution_u = self.resolution_shape
 
             cu.dimensions = '2D'
             cu.resolution_u = self.resolution_shape
 
@@ -2332,7 +2333,7 @@ class FptImporter():
     def create_curve(self, name, layers, curve_resolution):
         cu = self.__data.curves.new(FORMAT_CURVE.format(name), 'CURVE')
         obj = self.__data.objects.new(FORMAT_CURVE_OBJECT.format(name), cu)
     def create_curve(self, name, layers, curve_resolution):
         cu = self.__data.curves.new(FORMAT_CURVE.format(name), 'CURVE')
         obj = self.__data.objects.new(FORMAT_CURVE_OBJECT.format(name), cu)
-        self.__scene.objects.link(obj)
+        self.__collection.objects.link(obj)
 
         cu.dimensions = '3D'
         cu.twist_mode = 'Z_UP'
 
         cu.dimensions = '3D'
         cu.twist_mode = 'Z_UP'
@@ -2505,7 +2506,7 @@ class FptImporter():
 
         cu = self.__data.curves.new("{}.bevel_curve".format(name), 'CURVE')
         obj = self.__data.objects.new("{}".format(name), cu)
 
         cu = self.__data.curves.new("{}.bevel_curve".format(name), 'CURVE')
         obj = self.__data.objects.new("{}".format(name), cu)
-        self.__scene.objects.link(obj)
+        self.__collection.objects.link(obj)
 
         cu.dimensions = '2D'
         cu.twist_mode = 'Z_UP'
 
         cu.dimensions = '2D'
         cu.twist_mode = 'Z_UP'
@@ -2558,7 +2559,7 @@ class FptImporter():
         if wire_bevel is None:
             cu = self.__data.curves.new(bevel_name, 'CURVE')
             wire_bevel = self.__data.objects.new(bevel_name, cu)
         if wire_bevel is None:
             cu = self.__data.curves.new(bevel_name, 'CURVE')
             wire_bevel = self.__data.objects.new(bevel_name, cu)
-            self.__scene.objects.link(wire_bevel)
+            self.__collection.objects.link(wire_bevel)
             cu.dimensions = '2D'
             cu.resolution_u = self.resolution_wire_bevel
 
             cu.dimensions = '2D'
             cu.resolution_u = self.resolution_wire_bevel
 
@@ -2582,7 +2583,7 @@ class FptImporter():
         if wire_bevel is None:
             cu = self.__data.curves.new(bevel_name, 'CURVE')
             wire_bevel = self.__data.objects.new(bevel_name, cu)
         if wire_bevel is None:
             cu = self.__data.curves.new(bevel_name, 'CURVE')
             wire_bevel = self.__data.objects.new(bevel_name, cu)
-            self.__scene.objects.link(wire_bevel)
+            self.__collection.objects.link(wire_bevel)
             cu.dimensions = '2D'
             cu.resolution_u = self.resolution_wire_bevel
 
             cu.dimensions = '2D'
             cu.resolution_u = self.resolution_wire_bevel
 
@@ -2633,7 +2634,7 @@ class FptImporter():
             blender_empty_object_new.rotation_euler = Euler((0, 0, radians(angle)), blender_empty_object.rotation_mode)
             blender_empty_object_new.empty_display_type = blender_empty_object.empty_display_type
             blender_empty_object_new.empty_display_size = blender_empty_object.empty_display_size
             blender_empty_object_new.rotation_euler = Euler((0, 0, radians(angle)), blender_empty_object.rotation_mode)
             blender_empty_object_new.empty_display_type = blender_empty_object.empty_display_type
             blender_empty_object_new.empty_display_size = blender_empty_object.empty_display_size
-            self.__scene.objects.link(blender_empty_object_new)
+            self.__collection.objects.link(blender_empty_object_new)
 
             old_group_dict = {}
             for old_vert in old_mesh.vertices:
 
             old_group_dict = {}
             for old_vert in old_mesh.vertices:
index b4631a6..cce1f26 100644 (file)
@@ -477,6 +477,7 @@ def export_map(context, filepath):
     print("Map Exporter 0.0")
 
     scene = context.scene
     print("Map Exporter 0.0")
 
     scene = context.scene
+    collection = context.collection
     objects = context.selected_objects
 
     obs_mesh = []
     objects = context.selected_objects
 
     obs_mesh = []
@@ -657,7 +658,7 @@ def export_map(context, filepath):
                 print("\t\tignoring %s" % ob.name)
 
     for ob in obs_mesh:
                 print("\t\tignoring %s" % ob.name)
 
     for ob in obs_mesh:
-        scene.objects.unlink(ob)
+        collection.objects.unlink(ob)
         bpy.data.objects.remove(ob)
 
     print("Exported Map in %.4fsec" % (time.time() - t))
         bpy.data.objects.remove(ob)
 
     print("Exported Map in %.4fsec" % (time.time() - t))
index bbc7320..8268344 100644 (file)
@@ -238,10 +238,8 @@ def read(context, filepath, scale=100.0, tag=False, utm=False):
         me.transform(global_matrix)
 
     # create the object in the scene
         me.transform(global_matrix)
 
     # create the object in the scene
-    scene = context.scene
-    view_layer = context.view_layer
-    scene.objects.link(obj)
-    view_layer.objects.active = obj
+    context.collection.objects.link(obj)
+    context.view_layer.objects.active = obj
     obj.select_set(True)
 
     # entry points for other addons
     obj.select_set(True)
 
     # entry points for other addons
index 74b1d2f..dee641e 100644 (file)
@@ -269,8 +269,9 @@ def do_creaprim(self, mesh, objname, addondir):
     strlist.append("\n")
     strlist.append("        mesh = bpy.data.meshes.new(name=\"" + objname + "\")\n")
     strlist.append("        obj = bpy.data.objects.new(name=\"" + objname + "\", object_data=mesh)\n")
     strlist.append("\n")
     strlist.append("        mesh = bpy.data.meshes.new(name=\"" + objname + "\")\n")
     strlist.append("        obj = bpy.data.objects.new(name=\"" + objname + "\", object_data=mesh)\n")
+    strlist.append("        collection = bpy.context.collection\n")
     strlist.append("        scene = bpy.context.scene\n")
     strlist.append("        scene = bpy.context.scene\n")
-    strlist.append("        scene.objects.link(obj)\n")
+    strlist.append("        collection.objects.link(obj)\n")
     strlist.append("        obj.location = scene.cursor_location\n")
     strlist.append("        bm = bmesh.new()\n")
     strlist.append("        bm.from_mesh(mesh)\n")
     strlist.append("        obj.location = scene.cursor_location\n")
     strlist.append("        bm = bmesh.new()\n")
     strlist.append("        bm.from_mesh(mesh)\n")
index 966bb09..7f3f15a 100644 (file)
@@ -61,7 +61,7 @@ def object_osc_futurism (self, context,STEP, HOLD):
             # CREO OBJETO
             OBJECT=bpy.data.objects.new(ACTOBJ.name[:3]+str(FC), MESH)
             # CONECTO A LA ESCENA
             # CREO OBJETO
             OBJECT=bpy.data.objects.new(ACTOBJ.name[:3]+str(FC), MESH)
             # CONECTO A LA ESCENA
-            bpy.context.scene.objects.link(OBJECT)
+            bpy.context.collection.objects.link(OBJECT)
             # SETEO FRAME CURRENT
             bpy.context.scene.frame_set(FC)
             # MARCO EXPRESIONES PARA VIEW
             # SETEO FRAME CURRENT
             bpy.context.scene.frame_set(FC)
             # MARCO EXPRESIONES PARA VIEW
index 10cd227..d03242a 100644 (file)
@@ -312,9 +312,9 @@ def OscLinkedGroupToLocal():
         GROBJS = [ob for ob in ACTOBJ.id_data.instance_collection.objects[:] if ob.type == "MESH"]
 
         for ob in ACTOBJ.id_data.instance_collection.objects[:]:
         GROBJS = [ob for ob in ACTOBJ.id_data.instance_collection.objects[:] if ob.type == "MESH"]
 
         for ob in ACTOBJ.id_data.instance_collection.objects[:]:
-            bpy.context.scene.objects.link(ob)
+            bpy.context.collection.objects.link(ob)
         NEWGROUP = bpy.data.collections.new("%s_CLEAN" % (ACTOBJ.name))
         NEWGROUP = bpy.data.collections.new("%s_CLEAN" % (ACTOBJ.name))
-        bpy.context.scene.objects.unlink(ACTOBJ)
+        bpy.context.collection.objects.unlink(ACTOBJ)
         NEWOBJ = []
         for ob in GROBJS:
             NEWGROUP.objects.link(ob)
         NEWOBJ = []
         for ob in GROBJS:
             NEWGROUP.objects.link(ob)
index 638280e..fbaea9b 100644 (file)
@@ -37,7 +37,7 @@ def func_osc_screw(self, STRETCH,TURNS,DIAMETER,RESOLUTION):
     # DATA PARA EL MESH
     me = bpy.data.meshes.new("threadData")
     obj = bpy.data.objects.new("Thread", me)
     # DATA PARA EL MESH
     me = bpy.data.meshes.new("threadData")
     obj = bpy.data.objects.new("Thread", me)
-    bpy.context.scene.objects.link(obj)
+    bpy.context.collection.objects.link(obj)
 
     # VARIABLES
     vertexlist=[]
 
     # VARIABLES
     vertexlist=[]
index 2d0bc7f..a32efa7 100644 (file)
@@ -148,6 +148,7 @@ class NodeTree:
 class View:
     def __init__(self, name, euler_rotation):
         self._name = name
 class View:
     def __init__(self, name, euler_rotation):
         self._name = name
+        self._collection = None
         self._scene = None
         self._scene_camera = None
         self._node = None
         self._scene = None
         self._scene_camera = None
         self._node = None
@@ -190,7 +191,7 @@ class View:
         self._scene_camera = self._scene.camera
 
         self._camera = bpy.data.objects.new(self._name, data)
         self._scene_camera = self._scene.camera
 
         self._camera = bpy.data.objects.new(self._name, data)
-        self._scene.objects.link(self._camera)
+        self._collection.objects.link(self._camera)
 
         rotation = self._euler_rotation.copy()
         rotation.z += zed
 
         rotation = self._euler_rotation.copy()
         rotation.z += zed
@@ -202,7 +203,7 @@ class View:
         self._scene.camera = self._camera
 
     def resetCamera(self):
         self._scene.camera = self._camera
 
     def resetCamera(self):
-        self._scene.objects.unlink(self._camera)
+        self._collection.objects.unlink(self._camera)
         bpy.data.objects.remove(self._camera)
         self._camera = None
 
         bpy.data.objects.remove(self._camera)
         self._camera = None
 
@@ -281,6 +282,8 @@ def cube_map_render_init(scene, use_force=False):
 
         hashes.append(hash(scene))
         view.setScene(scene)
 
         hashes.append(hash(scene))
         view.setScene(scene)
+        # have Dalai to look at this?
+        view._collection = bpy.context.collection  # XXX TODO better fix
 
     # create a scene from scratch
     node_tree_data = NodeTree(main_scene)
 
     # create a scene from scratch
     node_tree_data = NodeTree(main_scene)
index 8e99f80..91fca56 100644 (file)
@@ -225,12 +225,13 @@ class RemoveSurroundCamerasOperator(bpy.types.Operator):
     def execute(self, context):
 
         scene = context.scene
     def execute(self, context):
 
         scene = context.scene
+        collection = context.collection
 
         # XXX. shouldnt there be some less general way to do this?
         # like check if they are the child of origin? - campbell
         for obj in scene.objects[:]:
             if obj.type == 'CAMERA':
 
         # XXX. shouldnt there be some less general way to do this?
         # like check if they are the child of origin? - campbell
         for obj in scene.objects[:]:
             if obj.type == 'CAMERA':
-                scene.objects.unlink(obj)
+                collection.objects.unlink(obj)
 
         context.window_manager.previous_num_surround_screens = -1
         return {'FINISHED'}
 
         context.window_manager.previous_num_surround_screens = -1
         return {'FINISHED'}
index c020f99..0896cc9 100644 (file)
@@ -591,7 +591,7 @@ class EnhancedSetCursor(bpy.types.Operator):
             transform_func(particle)
 
         if make_snapshot:
             transform_func(particle)
 
         if make_snapshot:
-            self.make_normal_snapshot(context.scene, tangential_snapshot)
+            self.make_normal_snapshot(context.collection, tangential_snapshot)
 
         return {'RUNNING_MODAL'}
 
 
         return {'RUNNING_MODAL'}
 
@@ -1416,7 +1416,7 @@ class EnhancedSetCursor(bpy.types.Operator):
 
         return p0, x * scl, y * scl, z * scl, _x * scl, _z * scl
 
 
         return p0, x * scl, y * scl, z * scl, _x * scl, _z * scl
 
-    def make_normal_snapshot(self, scene, tangential=False):
+    def make_normal_snapshot(self, collection, tangential=False):
         settings = find_settings()
         tfm_opts = settings.transform_options
 
         settings = find_settings()
         tfm_opts = settings.transform_options
 
@@ -1437,7 +1437,7 @@ class EnhancedSetCursor(bpy.types.Operator):
             snapshot.empty_display_type = 'SINGLE_ARROW'
             #snapshot.empty_display_type = 'ARROWS'
             #snapshot.layers = [True] * 20 # ?
             snapshot.empty_display_type = 'SINGLE_ARROW'
             #snapshot.empty_display_type = 'ARROWS'
             #snapshot.layers = [True] * 20 # ?
-            scene.objects.link(snapshot)
+            collection.objects.link(snapshot)
 #============================================================================#
 
 
 #============================================================================#
 
 
@@ -2273,7 +2273,7 @@ class SnapUtility:
         if context.area.type == 'VIEW_3D':
             v3d = context.space_data
             shade = v3d.viewport_shade
         if context.area.type == 'VIEW_3D':
             v3d = context.space_data
             shade = v3d.viewport_shade
-            self.implementation = Snap3DUtility(context.scene, shade)
+            self.implementation = Snap3DUtility(context, shade)
             self.implementation.update_targets(
                 context.visible_objects, [])
 
             self.implementation.update_targets(
                 context.visible_objects, [])
 
@@ -2489,11 +2489,11 @@ class Snap3DUtility(SnapUtilityBase):
         for j in (-1, 1)
         for k in (-1, 1)]
 
         for j in (-1, 1)
         for k in (-1, 1)]
 
-    def __init__(self, scene, shade):
+    def __init__(self, context, shade):
         SnapUtilityBase.__init__(self)
 
         convert_types = {'MESH', 'CURVE', 'SURFACE', 'FONT', 'META'}
         SnapUtilityBase.__init__(self)
 
         convert_types = {'MESH', 'CURVE', 'SURFACE', 'FONT', 'META'}
-        self.cache = MeshCache(scene, convert_types)
+        self.cache = MeshCache(context, convert_types)
 
         # ? seems that dict is enough
         self.bbox_cache = {}#collections.OrderedDict()
 
         # ? seems that dict is enough
         self.bbox_cache = {}#collections.OrderedDict()
@@ -2547,9 +2547,9 @@ class Snap3DUtility(SnapUtilityBase):
         # because otherwise outliner will blink each
         # time cursor is clicked
         if hide:
         # because otherwise outliner will blink each
         # time cursor is clicked
         if hide:
-            self.cache.scene.objects.unlink(self.bbox_obj)
+            self.cache.collection.objects.unlink(self.bbox_obj)
         else:
         else:
-            self.cache.scene.objects.link(self.bbox_obj)
+            self.cache.collection.objects.link(self.bbox_obj)
 
     def get_bbox_obj(self, obj, sys_matrix, sys_matrix_inv, is_local):
         if is_local:
 
     def get_bbox_obj(self, obj, sys_matrix, sys_matrix_inv, is_local):
         if is_local:
@@ -3016,8 +3016,9 @@ class MeshCache:
                          'META', 'ARMATURE', 'LATTICE'}
     convert_types = conversible_types
 
                          'META', 'ARMATURE', 'LATTICE'}
     convert_types = conversible_types
 
-    def __init__(self, scene, convert_types=None):
-        self.scene = scene
+    def __init__(self, context, convert_types=None):
+        self.collection = context.collection
+        self.scene = context.scene
         if convert_types:
             self.convert_types = convert_types
         self.cached = {}
         if convert_types:
             self.convert_types = convert_types
         self.cached = {}
@@ -3200,10 +3201,10 @@ class MeshCache:
 
         # Make Blender recognize object as having geometry
         # (is there a simpler way to do this?)
 
         # Make Blender recognize object as having geometry
         # (is there a simpler way to do this?)
-        self.scene.objects.link(tmp_obj)
+        self.collection.objects.link(tmp_obj)
         self.scene.update()
         # We don't need this object in scene
         self.scene.update()
         # We don't need this object in scene
-        self.scene.objects.unlink(tmp_obj)
+        self.collection.objects.unlink(tmp_obj)
 
         return tmp_obj
 
 
         return tmp_obj
 
@@ -3822,7 +3823,7 @@ class AddEmptyAtCursor3DBookmark(bpy.types.Operator):
         name = "{}.{}".format(library.name, bookmark.name)
         obj = bpy.data.objects.new(name, None)
         obj.matrix_world = to_matrix4x4(matrix, bookmark_pos)
         name = "{}.{}".format(library.name, bookmark.name)
         obj = bpy.data.objects.new(name, None)
         obj.matrix_world = to_matrix4x4(matrix, bookmark_pos)
-        context.scene.objects.link(obj)
+        context.collection.objects.link(obj)
 
         """
         for sel_obj in list(context.selected_objects):
 
         """
         for sel_obj in list(context.selected_objects):