[Bf-extensions-cvs] [ad4e81e5] master: addons-contrib: more view_layer syntax updates

NBurn noreply at git.blender.org
Tue Jan 29 20:09:30 CET 2019


Commit: ad4e81e5c2cc7dea7af06c4b31ae551252003299
Author: NBurn
Date:   Tue Jan 29 14:09:08 2019 -0500
Branches: master
https://developer.blender.org/rBACad4e81e5c2cc7dea7af06c4b31ae551252003299

addons-contrib: more view_layer syntax updates

===================================================================

M	add_dimension.py
M	cacharanth/util.py
M	data_overrides/util.py
M	io_import_LRO_Lola_MGS_Mola_img.py
M	io_scene_fpx/fpx_import.py
M	io_scene_map/export_map.py
M	io_scene_open_street_map.py
M	space_view3d_add_surround_cameras.py
M	space_view3d_enhanced_3d_cursor.py

===================================================================

diff --git a/add_dimension.py b/add_dimension.py
index 08b6e097..c60c3cda 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 7a9cd130..d75f4391 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 5e59d981..6fa86611 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 66e184c1..af612898 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 18c967a9..02977c00 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 0660eb32..b4631a6f 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 9d661e33..bbc73203 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 549fd113..8e99f801 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 7540fd88..c020f994 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

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list