Basic Python assistance


I’m currently making a tool in my lunch that gets a value of a selected object then moves it by 5 (Simple but trying to get fundamentals down…

This is my code section I need help with

def By5() :
mc.move( 0, translate_x_value + 5, 0 )

selected =

for item in selected:
translate_x_value = cmds.getAttr("%s.translateX" % item)
# do something with the value. egs:
print translate_x_value

The issue I’m having that once its been ran once (With GUI and a button to run the command, it’ll move by 5 once and no more…

I don’t know much about python but do I need to run a loop to request the position of cube constantly?

Thanks and apologies for the noob question


I did just realize I don’t seem to need the code below

def By5() :
mc.move( 0, translate_x_value + 5, 0 )

I’ve tried using getattr but still having issues.


By default, the move command moves the object in worldspace. So by moving it ‘5’, you’re moving it to the coordinate 5 on X (which is default axis on move command if you don’t specify).

You can add the ‘relative/r’ flag to move in a direction relative to it’s current position. You should also assign a variable to your selection unless you’re using in the move command
So you can either do:

def By5():
    mc.move(sel, 5, relative=True)


def By5():
    mc.move(, 5, relative=True)

Hope that helps you understand!


Thankyou for this! Its exactly what I needed!