# Apply transformations does not work in automated process

I am facing a strange problem with Blender. I start Blender with a script as parameter which is supposed to apply all transformations to an imported fbx model. The import itself works fine.

Part of the code is following:

for o in bpy.context.scene.objects:
print(o.name)
o.select = True
bpy.context.scene.objects.active = o
bpy.ops.object.transform_apply(location = True, scale = True, rotation = True)
o.select = False


When running the code like that, Blender does not apply the transformations. Instead it prints:

Warning: Objects have no data to transform


for every single object.

The really starnge thing is, when I paste the exact same script snippet into the editor field and run it, Blender executes it like expected and applies the transformation.

I really tried to find a solution, but did not find one. Thank you in advance!

• Also related in that you can run the operator once per scene by selecting the objects first. – batFINGER May 7 '18 at 10:11
• What command line are you using? the order is important Surely this can be done without a workaround such as the one suggested in your answer. – batFINGER May 7 '18 at 16:10

Make sure that you actually need to apply transformations. If you are writing an exporter, multiplying the object.matrix_world by the vertex position gives you the transformed value without altering the original mesh.

In case you still need to do it, do what batFINGER suggested.

• Thank you for the answers. :-) I am working on a rendering pipeline and need the objects measurement for scaling and positioning purposes in the scene. The assets our client delivered have often many groups or parent/child relations, many different scalings, rotations, pivot positions in all layers and so on. I need also to reset the empties values, because their children inherit the transformations if a empty is a grouphead. – S.Hermes May 7 '18 at 13:48

The answer from CoDEmanX to this question actually helped me solve my problem.

How to programmatically load a python script in Text Editor and launch it

I did exactly what is the topic of that post. I was not able to run the code from commandline argument script so I loaded it to the blender text editor and run it from there.

The code in the main function:

filename = os.getcwd() + "\\\src\\python\\blender\\render\\apply.py"

for area in bpy.context.screen.areas:
if area.type == 'TEXT_EDITOR':
area.spaces[0].text = text # make loaded text file visible

ctx = bpy.context.copy()
ctx['edit_text'] = text # specify the text datablock to execute
ctx['area'] = area # not actually needed...
ctx['region'] = area.regions[-1] # ... just be nice

bpy.ops.text.run_script(ctx)
break


... and apply.py

import bpy

for o in bpy.context.scene.objects:
o.select = True
bpy.context.scene.objects.active = o
bpy.ops.object.transform_apply(location=True, rotation=False, scale=True)


It also looks like as if initially a blend file with a Text Editor field has to be loaded to make that run.

Thanks again for your time and I hope I was also able to help solving future problems.