0
$\begingroup$

I've read all questions and answers about moving UV island here. The most relevant are these:

But they do not solve my problem, my code is just not working. What is wrong with my code?

for area in bpy.context.screen.areas:
    if area.type == 'IMAGE_EDITOR':
        bpy.ops.transform.translate(value=(125, 0, 0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
    else:
        area.type = 'VIEW_3D'

This is the result:

enter image description here

The other areas changed to VIEW_3D, but the IMAGE_EDITOR area did not make the translate. The translate is still happening to the object in VIEW_3D.

$\endgroup$
  • $\begingroup$ I think it as to do with the position of the mouse, try running the script with it on top of the UV Image editor $\endgroup$ – someonewithpc Jan 12 '15 at 21:55
  • 1
    $\begingroup$ I'm not programming at Blender's Text Editor - I'm programming python with gedit. When I run the script, it creates a new Blender file with my commands. Because of this, doesn't matter my mouse position - also because I can't control this. Maybe what could be done is to leave all areas and keep open just "Image Editor" area. Do you know how I could do this? $\endgroup$ – CuriousElf Jan 19 '15 at 16:08
0
$\begingroup$

I've change my code, and use one "meta-code" - inside my code, I've opened an "Text Editor" area, and include another python file. At least, this is my code:

text = bpy.data.texts.load("translate.py")

for area in bpy.context.screen.areas:
    if area.type == 'IMAGE_EDITOR':
        area.type = 'TEXT_EDITOR'
        area.spaces[0].text = text

        ctx = bpy.context.copy()
        ctx['edit_text'] = text
        ctx['area'] = area
        ctx['region'] = area.regions[-1]

        bpy.ops.text.run_script(ctx)
        break

for area in bpy.context.screen.areas:
    if area.type == 'TEXT_EDITOR':
        area.type = 'VIEW_3D'

And, my translate.py code:

import bpy

area = bpy.context.area.type
bpy.context.area.type = 'IMAGE_EDITOR'
bpy.ops.transform.translate(value=(-0.449219, 0.425781, 0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
bpy.context.area.type = area

Thanks everybody :)

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.