Update object transformation in script

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Fri Mar 02, 2012 1:04 pm

Update object transformation in script

Post by leo1756 »

Hello all,

I'm trying to make a Python script that make some calculations according to the objects position (actually it's angle of rotation) at the scene. In this script I have a loop that increments the objects angle by some step value and for each iteration it performs the calculations and prints the result.

The problem is that when I run the script only the initial angle are considered, it seems the angle increments are not computated.

For example:

Code: Select all

current_obj = bpy.data.objects['Cube']
for ang in range(80,100):
    ang_r = (ang*math.pi)/180
    current_obj.rotation_euler = mathutils.Euler((0,ang_r,0),'XYZ')

    mtx = current_obj.matrix_world
The code above seems to not update the "current_obj.rotation_euler" until it finishes, it does not update it while executing the loop. Is there any restriction on updating objects properties inside a loop on scripts?

I suspect I'm doing something silly here, but I'll need someone's help, because I'm very new to Blender yet.
I'm using Blender 2.61.

Thanks for the attention.

Posts: 0
Joined: Mon Feb 22, 2010 10:20 am

Post by mb »

Since blender 2.51 the possibility of moving/rotating objects (at reasonable speed) in the editor environment has got lost.
I started a thread on the matter:
http://www.blender.org/forum/viewtopic. ... highlight=

However your problem could be easily solved in the game engine environment, with very simple python code.
Let me know whether you are interested on this latter solution.

Posts: 0
Joined: Fri Mar 02, 2012 1:04 pm

Post by leo1756 »

Hello mb,

thanks for answering me. My first goal with this script was to rotate some objects, make some calculations and output the results on a file. I've found that if I use the folowing code inside the loop:

Code: Select all

then it solves the calculation problem (the objects position is updated). However it does not update the screen while the script executes (which would be my next step).
As I said, I'm new to Blender and I didn'd study the game engine yet, but I will check it out. I won't bother you with questions about it for now, but any further hints are welcome :).

Thank you

Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

if you change e.g. a Bone's roll angle, UI won't update.

If you move cursor on the roll property slider, value will update as soon as you hover it.

And re-placing the 3d cursor (left click in 3d view) or toggling any checkbox will update the bone in 3d view.

However, i haven't found a way to force such an update via script. It's obviously not intended to work, but would be helpful in rare cases.

tried scene, screen and window manager update_tag()
I'm sitting, waiting, wishing, building Blender in superstition...

Post Reply