diff --git a/add_dimension.py b/add_dimension.py index 08b6e0975d4ae6e8e05592d9f62d1248b1e69b52..c60c3cda7d30a8ba8691102d70e16e4dd1cd38db 100644 --- a/add_dimension.py +++ b/add_dimension.py @@ -1462,10 +1462,10 @@ def align_matrix(context, location): # sets bezierhandles to auto def setBezierHandles(obj, mode = 'VECTOR'): - scene = bpy.context.scene + view_layer = bpy.context.view_layer if obj.type != 'CURVE': return - scene.objects.active = obj + view_layer.objects.active = obj bpy.ops.object.mode_set(mode = 'EDIT', toggle = True) bpy.ops.curve.select_all(action = 'SELECT') bpy.ops.curve.handle_type_set(type = mode) diff --git a/cacharanth/util.py b/cacharanth/util.py index 7a9cd1308190acedcbf98cbaa6b775e8823e7bd7..d75f4391db32a61ed6dea020807d0a4d6e8f4541 100644 --- a/cacharanth/util.py +++ b/cacharanth/util.py @@ -36,12 +36,12 @@ def round_sigfigs(num, sig_figs): class OperatorCallContext(): def __enter__(self): - scene = bpy.context.scene prefs = bpy.context.preferences + view_layer = bpy.context.view_layer # store active/selected state to restore it after operator execution - self.curact = scene.objects.active - self.cursel = { ob : ob.select for ob in scene.objects } + self.curact = view_layer.objects.active + self.cursel = { ob : ob.select_get() for ob in scene.objects } # undo can store files a lot when running operators internally, # disable since we only need one undo step after main operators anyway @@ -53,9 +53,10 @@ class OperatorCallContext(): def __exit__(self, exc_type, exc_value, traceback): scene = bpy.context.scene prefs = bpy.context.preferences + view_layer = bpy.context.view_layer # restore active/selected state - scene.objects.active = self.curact + view_layer.objects.active = self.curact for ob in scene.objects: ob.select = self.cursel.get(ob, False) @@ -63,7 +64,8 @@ class OperatorCallContext(): def select_single_object(ob): scene = bpy.context.scene + view_layer = bpy.context.view_layer - scene.objects.active = ob + view_layer.objects.active = ob for tob in scene.objects: tob.select = (tob == ob) diff --git a/data_overrides/util.py b/data_overrides/util.py index 5e59d98160c4e6c653d27589c527e0915676d5e6..6fa86611047b3e1b8df521c1115e41bbbc642936 100644 --- a/data_overrides/util.py +++ b/data_overrides/util.py @@ -80,9 +80,10 @@ class OperatorCallContext(): def __enter__(self): scene = bpy.context.scene prefs = bpy.context.preferences + view_layer = bpy.context.view_layer # store active/selected state to restore it after operator execution - self.curact = scene.objects.active + self.curact = view_layer.objects.active self.cursel = { ob : ob.select for ob in scene.objects } # undo can store files a lot when running operators internally, @@ -95,9 +96,10 @@ class OperatorCallContext(): def __exit__(self, exc_type, exc_value, traceback): scene = bpy.context.scene prefs = bpy.context.preferences + view_layer = bpy.context.view_layer # restore active/selected state - scene.objects.active = self.curact + view_layer.objects.active = self.curact for ob in scene.objects: ob.select = self.cursel.get(ob, False) @@ -105,7 +107,8 @@ class OperatorCallContext(): def select_single_object(ob): scene = bpy.context.scene + view_layer = bpy.context.view_layer - scene.objects.active = ob + view_layer.objects.active = ob for tob in scene.objects: tob.select = (tob == ob) diff --git a/io_import_LRO_Lola_MGS_Mola_img.py b/io_import_LRO_Lola_MGS_Mola_img.py index 66e184c1608f1943a205e67ad8c89efe652cf3fe..af612898f6b74e0cfe8d0c6cbfcd57000dc062a0 100644 --- a/io_import_LRO_Lola_MGS_Mola_img.py +++ b/io_import_LRO_Lola_MGS_Mola_img.py @@ -441,8 +441,9 @@ class Import(bpy.types.Operator): 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) - scene.objects.active = ob_new + view_layer.objects.active = ob_new ob_new.select_set(True) print ('*** End draw ***') print('*** Start Smooth ***') diff --git a/io_scene_fpx/fpx_import.py b/io_scene_fpx/fpx_import.py index 18c967a993bf642bd468423108bf718e8180dc49..02977c001c04da2946ff56c287752fbba7f3944e 100644 --- a/io_scene_fpx/fpx_import.py +++ b/io_scene_fpx/fpx_import.py @@ -661,6 +661,7 @@ class FptImporter(): self.__context = blender_context self.__data = blender_context.blend_data self.__scene = blender_context.scene + self.__view_layer = blender_context.view_layer try: try: @@ -963,6 +964,7 @@ class FptImporter(): self.__context = None self.__data = None self.__scene = None + self.__view_layer = None t3 = time() if self.verbose in FpxUI.VERBOSE_NORMAL: @@ -1415,7 +1417,7 @@ class FptImporter(): offset_y = tex_size_length - 2.0 * (tex_loc_y - box_y) blender_object.select_set(True) - self.__scene.objects.active = blender_object + self.__view_layer.objects.active = blender_object self.__scene.update() if ops.object.convert.poll(): ops.object.convert() @@ -1776,7 +1778,7 @@ class FptImporter(): self.create_wire_pole(cu.splines, co2, h_right2, h_left2, surface, width) # merge wire curve with pole caps - self.__scene.objects.active = obj + self.__view_layer.objects.active = obj self.merge_caps(cu.splines, width) cu.splines[0].type = 'NURBS' # looks better for wires @@ -3009,6 +3011,7 @@ def adjust_position(blender_context, blender_scene, fpx_model, fpx_model_type=No blender_object = blender_context.active_object blender_parent = blender_object.parent + blender_view_layer = blender_context.blender_view_layer # Fpm_Model_Type.OBJECT_OBJECT = 0 ## Fpm_Model_Type.OBJECT_PEG = 1 @@ -3153,8 +3156,8 @@ def adjust_position(blender_context, blender_scene, fpx_model, fpx_model_type=No pass if blender_location: - blender_scene.objects.active = blender_parent - blender_scene.objects.active.location = blender_location + blender_view_layer.objects.active = blender_parent + blender_view_layer.objects.active.location = blender_location blender_scene.update() def remove_material(blender_context): diff --git a/io_scene_map/export_map.py b/io_scene_map/export_map.py index 0660eb32ddf3909895fad73484255ec0c12f19b7..b4631a6f247b62b87bb206f028267a2f60d7783d 100644 --- a/io_scene_map/export_map.py +++ b/io_scene_map/export_map.py @@ -386,6 +386,7 @@ def write_node_map(fw, ob): def split_objects(context, objects): scene = context.scene + view_layer = context.view_layer final_objects = [] bpy.ops.object.select_all(action='DESELECT') @@ -403,7 +404,7 @@ def split_objects(context, objects): ob.select_set(True) if ob.type == "MESH": - scene.objects.active = ob + view_layer.objects.active = ob bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.mesh.select_mode(type='EDGE') @@ -420,7 +421,7 @@ def split_objects(context, objects): for split_ob in split_objects: assert(split_ob.type == "MESH") - scene.objects.active = split_ob + view_layer.objects.active = split_ob bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_mode(type='EDGE') bpy.ops.mesh.select_all(action="SELECT") diff --git a/io_scene_open_street_map.py b/io_scene_open_street_map.py index 9d661e3339b9987c48f8c7820c80cb277f36f8af..bbc732037ce4deb682e681d408233f18c1d677ba 100644 --- a/io_scene_open_street_map.py +++ b/io_scene_open_street_map.py @@ -239,8 +239,9 @@ def read(context, filepath, scale=100.0, tag=False, utm=False): # create the object in the scene scene = context.scene + view_layer = context.view_layer scene.objects.link(obj) - scene.objects.active = obj + view_layer.objects.active = obj obj.select_set(True) # entry points for other addons diff --git a/space_view3d_add_surround_cameras.py b/space_view3d_add_surround_cameras.py index 549fd113d4815e66704b4eecb9ad7b1ae9a2e622..8e99f8019255705990a332bbe931c39afe8da331 100644 --- a/space_view3d_add_surround_cameras.py +++ b/space_view3d_add_surround_cameras.py @@ -103,6 +103,7 @@ class AddSurroundCamerasOperator(bpy.types.Operator): def execute(self, context): scene = context.scene + view_layer = context.view_layer numScreens = context.window_manager.num_surround_screens # add an empty for the camera origin if not already present @@ -139,7 +140,7 @@ class AddSurroundCamerasOperator(bpy.types.Operator): # sel/activate origin bpy.ops.object.select_all(action='DESELECT') obj_origin.select_set(True) - scene.objects.active = obj_origin + view_layer.objects.active = obj_origin context.window_manager.previous_num_surround_screens = numScreens return {'FINISHED'} diff --git a/space_view3d_enhanced_3d_cursor.py b/space_view3d_enhanced_3d_cursor.py index 7540fd880454298e279fa0e9e97ff33ef088458d..c020f994939b43d4527bdb2bb14afa3fb79cdb3c 100644 --- a/space_view3d_enhanced_3d_cursor.py +++ b/space_view3d_enhanced_3d_cursor.py @@ -1546,6 +1546,8 @@ def gather_particles(**kwargs): area_type = kwargs.get("area_type", context.area.type) scene = kwargs.get("scene", context.scene) + + view_layer = kwargs.get("view_layer", context.view_layer) space_data = kwargs.get("space_data", context.space_data) region_data = kwargs.get("region_data", context.region_data) @@ -1798,7 +1800,7 @@ def gather_particles(**kwargs): pivots['CENTER'] = bbox_center.copy() csu = CoordinateSystemUtility(scene, space_data, region_data, \ - pivots, normal_system) + pivots, normal_system, view_layer) return particles, csu @@ -1852,7 +1854,7 @@ class CoordinateSystemUtility: } def __init__(self, scene, space_data, region_data, \ - pivots, normal_system): + pivots, normal_system, view_layer): self.space_data = space_data self.region_data = region_data @@ -1860,7 +1862,7 @@ class CoordinateSystemUtility: self.pivot_map_inv = self.pivot_v3d_map self.tou = TransformOrientationUtility( - scene, space_data, region_data) + scene, space_data, region_data, view_layer) self.tou.normal_system = normal_system self.pivots = pivots @@ -1943,10 +1945,11 @@ class TransformOrientationUtility: "Scaled", "Surface", } - def __init__(self, scene, v3d, rv3d): + def __init__(self, scene, v3d, rv3d, vwly): self.scene = scene self.v3d = v3d self.rv3d = rv3d + self.view_layer = vwly self.custom_systems = [item for item in scene.orientations \ if item.name not in self.special_systems] @@ -2002,7 +2005,7 @@ class TransformOrientationUtility: self.v3d.transform_orientation = name def get_matrix(self, name=None): - active_obj = self.scene.objects.active + active_obj = self.view_layer.objects.active if not name: name = self.transform_orientation @@ -2038,7 +2041,7 @@ class TransformOrientationUtility: # Is there a less cumbersome way to create transform orientation? def create_transform_orientation(scene, name=None, matrix=None): - active_obj = scene.objects.active + active_obj = view_layer.objects.active prev_mode = None if active_obj: @@ -3891,7 +3894,7 @@ class BookmarkLibraryProp(bpy.types.PropertyGroup): else: csu.source_pos = Vector() - active_obj = csu.tou.scene.objects.active + active_obj = csu.tou.view_layer.objects.active if self.system == 'GLOBAL': sys_name = 'GLOBAL'