ERROR trying to creatu UI with python


#1

hi everyone,
i was trying to create a little script that aligns objects, with a window prompt. So i have written this code

ALIGNER TOOL = mc.window(title=“object aligner tool”, s=False, wh=(300,400) )
mc.columnLayout(adj=True)
mc.text(l=“select source, then the target!”)
mc.button(l=“Align!”, w=300, h=400, c=“Objaligner()”)
mc.showWindow(ALIGNER TOOL)

def Objaligner():
pntcst=mc.pointConstraint()
mc.delete(pntcst)
I can’t figure out what’s the problem… it gives me a simple Syntax error, without further indications.
what’s the problem?


#2

For this type of question, you should turn on stack trace in the script editor history menu, run you code and then post the full error message.

Anyway, from what I can see, I’d say you need to drop the quotes and brackets in the button command. You want to pass it the function. The way you have it you are passing in the result of running the function when the button is created.

mc.button(l=“Align!”, w=300, h=400, c=Objaligner)

David


#3

thanks for the answer david, i already tried but it doesn’t work(Objaligner is a function, not a variable and needs the brackets) and it’s strange, because i’m positive that i have witten in the same way as the guy in the tutorial i’m following did…


#4

Never mind i found the culprit, the name of the variable ALIGNER TOOL is incorrect because variables don’t accept spaces between words… you have to put an underscore xD… thanks for telling me to turn on stack trace XD