1
$\begingroup$

Why do functions like bpy.ops.object.add() return {'FINISHED'} and not the object?

Wouldn't it be better to return the object if successful and None otherwise so that obj = bpy.ops.object.add() can be used (instead of bpy.ops.object.add(); obj = bpy.context.object)?

If the {'FINISHED'} is necessary, then wouldn't returning the object and finished value as tuple be better (return (obj, finished))?

$\endgroup$
  • 3
    $\begingroup$ Not every operator creates an object and the way it's currently implemented allows code to handle the return value of all operators in the same way. Although it would be technically possible, it would also require a lot of changes to the existing code with only marginal benefits, like in your use case. $\endgroup$ – Robert Gützkow Oct 27 '19 at 19:16
  • $\begingroup$ To add, this is the operator / context paradigm. Operators adjust the context and return a status So no, IMO it wouldn't be better. That said. There are a number of API methods that do return a reference to the created object eg create a new mesh new_mesh = bpy.data.meshes.new("New Mesh") then assign it as the data part of a new object new_object = bpy.data.objects.new("New Object", new_mesh) to create a new mesh type object with an empty mesh. $\endgroup$ – batFINGER Oct 28 '19 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.