0

I'm trying to save an object as a reference so I can repeated apply the transform when I need to, but I can't seem to save it in a variable, like I would normally try to:

import bpy
from math import radians

bpy.ops.mesh.primitive_solid_add() solid = bpy.context.active_object solid.rotation_euler[2] = radians(90)

solid.transform_apply(location=False, rotation=True, scale=False) #this is the error line

The error I get is the classic AttributeError: 'Object' object has no attribute 'transform_apply'

Has anyone come across a way to save the object so I can use it without repeatedly highlighting?

Gorgious
  • 30,723
  • 2
  • 44
  • 101

1 Answers1

0

What you need is an operator override. Assuming you're using a Blender version > 3.2.

import bpy
from math import radians

bpy.ops.mesh.primitive_solid_add() solid = bpy.context.active_object solid.rotation_euler[2] = radians(90)

with bpy.context.temp_override(selected_editable_objects=[solid]): bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)

See this thread for a semi-comprehensive list of operator overrides.

Gorgious
  • 30,723
  • 2
  • 44
  • 101