Python: What if no active_object? I have a problem to define my script if no active object is exisiting in the current scene. My approach is if no active object is existing then another definition should be happen. Python console says &quot;no active object, no attributes at all&quot;.
Please, can somebody help me?
import bpy

act_obj = bpy.context.active_object

for sel_obj in bpy.context.selected_objects:
   if act_obj.name in sel_obj.name:
       ob1_act = bpy.context.scene.cursor
   else:
       ob1_act = act_obj
    
bpy.ops.object.empty_add(type='PLAIN_AXES', location=ob1_act.location)
Ok, got it! (sorry, couldn't post a comment since i haven't got an account)
This works what I searched for.
try:
   posemp = bpy.context.active_object.location
except:
   posemp = bpy.context.scene.cursor.location

bpy.ops.object.empty_add(type='PLAIN_AXES', location=posemp)