addons-contrib: more view_layer syntax updates
authorNBurn <7nburn@gmail.com>
Tue, 29 Jan 2019 19:09:08 +0000 (14:09 -0500)
committerNBurn <7nburn@gmail.com>
Tue, 29 Jan 2019 19:09:08 +0000 (14:09 -0500)
add_dimension.py
cacharanth/util.py
data_overrides/util.py
io_import_LRO_Lola_MGS_Mola_img.py
io_scene_fpx/fpx_import.py
io_scene_map/export_map.py
io_scene_open_street_map.py
space_view3d_add_surround_cameras.py
space_view3d_enhanced_3d_cursor.py

index 08b6e09..c60c3cd 100644 (file)
@@ -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)
index 7a9cd13..d75f439 100644 (file)
@@ -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)
index 5e59d98..6fa8661 100644 (file)
@@ -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)
index 66e184c..af61289 100644 (file)
@@ -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 ***')
index 18c967a..02977c0 100644 (file)
@@ -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):
index 0660eb3..b4631a6 100644 (file)
@@ -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")
index 9d661e3..bbc7320 100644 (file)
@@ -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
index 549fd11..8e99f80 100644 (file)
@@ -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'}
index 7540fd8..c020f99 100644 (file)
@@ -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'