forked from bartvdbraak/blender
Fix incorrect active object setting in scripts.
This commit is contained in:
parent
9284c051d6
commit
31c49493d1
@ -166,7 +166,7 @@ def object_data_add(context, obdata, operator=None, name=None):
|
|||||||
|
|
||||||
obj_act.select_set(action='SELECT')
|
obj_act.select_set(action='SELECT')
|
||||||
scene.update() # apply location
|
scene.update() # apply location
|
||||||
# scene.objects.active = obj_new
|
# layer.objects.active = obj_new
|
||||||
|
|
||||||
# Match up UV layers, this is needed so adding an object with UV's
|
# Match up UV layers, this is needed so adding an object with UV's
|
||||||
# doesn't create new layers when there happens to be a naming mis-match.
|
# doesn't create new layers when there happens to be a naming mis-match.
|
||||||
|
@ -238,7 +238,7 @@ class CLIP_OT_track_to_empty(Operator):
|
|||||||
ob = bpy.data.objects.new(name=track.name, object_data=None)
|
ob = bpy.data.objects.new(name=track.name, object_data=None)
|
||||||
ob.select_set(action='SELECT')
|
ob.select_set(action='SELECT')
|
||||||
context.scene.objects.link(ob)
|
context.scene.objects.link(ob)
|
||||||
context.scene.objects.active = ob
|
context.view_layer.objects.active = ob
|
||||||
|
|
||||||
for con in ob.constraints:
|
for con in ob.constraints:
|
||||||
if con.type == 'FOLLOW_TRACK':
|
if con.type == 'FOLLOW_TRACK':
|
||||||
@ -314,7 +314,7 @@ class CLIP_OT_bundles_to_mesh(Operator):
|
|||||||
ob.matrix_world = matrix
|
ob.matrix_world = matrix
|
||||||
context.scene.objects.link(ob)
|
context.scene.objects.link(ob)
|
||||||
ob.select = True
|
ob.select = True
|
||||||
context.scene.objects.active = ob
|
context.view_layer.objects.active = ob
|
||||||
else:
|
else:
|
||||||
self.report({'WARNING'}, "No usable tracks selected")
|
self.report({'WARNING'}, "No usable tracks selected")
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class CopyRigidbodySettings(Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
obj_act = context.object
|
obj_act = context.object
|
||||||
scene = context.scene
|
view_layer = context.view_layer
|
||||||
|
|
||||||
# deselect all but mesh objects
|
# deselect all but mesh objects
|
||||||
for o in context.selected_objects:
|
for o in context.selected_objects:
|
||||||
@ -68,9 +68,9 @@ class CopyRigidbodySettings(Operator):
|
|||||||
o.select_set(action='DESELECT')
|
o.select_set(action='DESELECT')
|
||||||
elif o.rigid_body is None:
|
elif o.rigid_body is None:
|
||||||
# Add rigidbody to object!
|
# Add rigidbody to object!
|
||||||
scene.objects.active = o
|
view_layer.objects.active = o
|
||||||
bpy.ops.rigidbody.object_add()
|
bpy.ops.rigidbody.object_add()
|
||||||
scene.objects.active = obj_act
|
view_layer.objects.active = obj_act
|
||||||
|
|
||||||
objects = context.selected_objects
|
objects = context.selected_objects
|
||||||
if objects:
|
if objects:
|
||||||
@ -265,7 +265,7 @@ class ConnectRigidBodies(Operator):
|
|||||||
ob = bpy.data.objects.new("Constraint", object_data=None)
|
ob = bpy.data.objects.new("Constraint", object_data=None)
|
||||||
ob.location = loc
|
ob.location = loc
|
||||||
context.scene.objects.link(ob)
|
context.scene.objects.link(ob)
|
||||||
context.scene.objects.active = ob
|
context.view_layer.objects.active = ob
|
||||||
ob.select_set(action='SELECT')
|
ob.select_set(action='SELECT')
|
||||||
|
|
||||||
bpy.ops.rigidbody.constraint_add()
|
bpy.ops.rigidbody.constraint_add()
|
||||||
@ -278,7 +278,7 @@ class ConnectRigidBodies(Operator):
|
|||||||
con.object2 = object2
|
con.object2 = object2
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
scene = context.scene
|
view_layer = context.view_layer
|
||||||
objects = context.selected_objects
|
objects = context.selected_objects
|
||||||
obj_act = context.active_object
|
obj_act = context.active_object
|
||||||
change = False
|
change = False
|
||||||
@ -312,7 +312,7 @@ class ConnectRigidBodies(Operator):
|
|||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
obj.select_set(action='SELECT')
|
obj.select_set(action='SELECT')
|
||||||
scene.objects.active = obj_act
|
view_layer.objects.active = obj_act
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
else:
|
else:
|
||||||
self.report({'WARNING'}, "No other objects selected")
|
self.report({'WARNING'}, "No other objects selected")
|
||||||
|
@ -579,7 +579,7 @@ def unwrap(operator, context, **kwargs):
|
|||||||
# define list of meshes
|
# define list of meshes
|
||||||
meshes = []
|
meshes = []
|
||||||
if PREF_ACT_ONLY:
|
if PREF_ACT_ONLY:
|
||||||
obj = context.scene.objects.active
|
obj = context.view_layer.objects.active
|
||||||
if obj and obj.type == 'MESH':
|
if obj and obj.type == 'MESH':
|
||||||
meshes = [obj.data]
|
meshes = [obj.data]
|
||||||
else:
|
else:
|
||||||
|
@ -9,9 +9,9 @@ basedir = os.path.dirname(bpy.data.filepath)
|
|||||||
if not basedir:
|
if not basedir:
|
||||||
raise Exception("Blend file is not saved")
|
raise Exception("Blend file is not saved")
|
||||||
|
|
||||||
scene = bpy.context.scene
|
view_layer = bpy.context.view_layer
|
||||||
|
|
||||||
obj_active = scene.objects.active
|
obj_active = view_layer.objects.active
|
||||||
selection = bpy.context.selected_objects
|
selection = bpy.context.selected_objects
|
||||||
|
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
@ -21,7 +21,7 @@ for obj in selection:
|
|||||||
obj.select_set(action='SELECT')
|
obj.select_set(action='SELECT')
|
||||||
|
|
||||||
# some exporters only use the active object
|
# some exporters only use the active object
|
||||||
scene.objects.active = obj
|
view_layer.objects.active = obj
|
||||||
|
|
||||||
name = bpy.path.clean_name(obj.name)
|
name = bpy.path.clean_name(obj.name)
|
||||||
fn = os.path.join(basedir, name)
|
fn = os.path.join(basedir, name)
|
||||||
@ -36,7 +36,7 @@ for obj in selection:
|
|||||||
print("written:", fn)
|
print("written:", fn)
|
||||||
|
|
||||||
|
|
||||||
scene.objects.active = obj_active
|
view_layer.objects.active = obj_active
|
||||||
|
|
||||||
for obj in selection:
|
for obj in selection:
|
||||||
obj.select_set(action='SELECT')
|
obj.select_set(action='SELECT')
|
||||||
|
@ -68,7 +68,7 @@ def main(context, event):
|
|||||||
# we could do lots of stuff but for the example just select.
|
# we could do lots of stuff but for the example just select.
|
||||||
if best_obj is not None:
|
if best_obj is not None:
|
||||||
best_obj.select_set(action='SELECT')
|
best_obj.select_set(action='SELECT')
|
||||||
context.scene.objects.active = best_obj
|
context.view_layer.objects.active = best_obj
|
||||||
|
|
||||||
|
|
||||||
class ViewOperatorRayCast(bpy.types.Operator):
|
class ViewOperatorRayCast(bpy.types.Operator):
|
||||||
|
Loading…
Reference in New Issue
Block a user