0

I am having a problem when creating a Maya MEL expression with a python script. I need to be able to format the expression based on the values entered into certain GUI components but when I try format the expression that contains an "if statement" there is some conflicting. Take a look:

revol_int = self.revol_int.value()

revolExpression = pm.expression(o=rigRevol, s='if (frame%8 == 0) {rz = (frame//{0}) * ((360/{1}.000)/2.000);}'.format(interv_int, revol_int))

The expression works when entered manually but when done by formatting through the script I get an KeyError due to the "{}" that house the if statements block of code. So I tried the other method of formatting:

revol_int = self.revol_int.value()

revolExpression = pm.expression(o=rigRevol, n='olr_revolutions_expression', s='if (frame%8 == 0) {rz = (frame//%s) * ((360/%s.000)/2.000);}' % (interv_int, revol_int))

But in this case I get a # ValueError: unsupported format character ' ' (0x20) at index 11. I am quite uncertain where to go from here. Any suggestions would be greatly appreciated.

PyHP3D
  • 88
  • 10

1 Answers1

1

You need to include another % to use as an escape character for the first percentage. Otherwise Python gets confused on how to evaluate the string.

'if ( (frame%%8) == 0) {rz = (frame/%s) * ((360/%s.000)/2.000);}' % (interv_int, revol_int)
Green Cell
  • 4,677
  • 2
  • 18
  • 49