2

I'm new in python. I try to make a button in Maya that increments the value of the crease edges. Each time I click on it I want to make +1 to the crease value.

I tried this :

def crease(ignore):
    value=+1
    newvalue = value
    for i in value(int(newvalue)+1):
        maya.cmds.polyCrease(i)

But it doesn't work. If somebody could help I really appreciate any help you can provide

Green Cell
  • 4,677
  • 2
  • 18
  • 49
iobs
  • 47
  • 5

2 Answers2

2

It's a problem of nesting values, when your value is under a def, it is not not stored in the global scope.

counter = 0

def crease(ignore):
    value = counter+1
    maya.cmds.polyCrease(v=i)
    return value

counter = crease(0)

if you want to keep track of the counter, you can create a global : Can not increment global variable from function in python

a dict : python modify a dictionary inside a method

or even a class.

DrWeeny
  • 2,487
  • 1
  • 14
  • 17
1

As it happens, cmds.polyCrease includes a flag that does what you want:

cmds.polyCrease(rv=1)

will bump the crease value on the currently selected components by 1; a negative value will bump it down. A global counter works from a programming standpoint but it will probably have surprising results if you hop between different objects in the scene.

theodox
  • 12,028
  • 3
  • 23
  • 36