Category: python

Custom Marking Menu

Most of the time, I use shortcuts / shelf buttons in Maya to speed things up. Today I went through the tutorial CGCircuit – Rigging Productivity Boost by Carlo Sansonetti. The videos are straightforward. One thing I don’t like is that the setup involves too many manual clicks and depends on Maya’s UI.

I found a post in BindPose which suggests a cleaner way: popupMenu. I think the idea is brilliant and credit goes to Vasil Shotarov. Now I have fewer buttons in my shelf and one more simple way to make life easier in Maya !!!


Python @property

While learning thru advanced tutorials, it’s time to consolidate some basic concepts in Python. The explanation about property at https://www.programiz.com/python-programming/property is very clear. I’m writing an example below to remind myself of the private variable _cm being a convention only. Name like temp_cm works too.

Also cm is no longer a normal instance variable when property decorator is used. The design of adding @property allows backward compatible to keep codes unchanged!

class Unit:
    def __init__(self, cm=0):
        self.cm = cm

    def toInch(self):
        return self.cm * 0.3937

    # @property
    # def cm(self):
    #     return self.temp_cm
    #
    # @cm.setter
    # def cm(self, v):
    #     self.temp_cm = v

unit = Unit(cm=100)
print(unit.__dict__)

# {'cm': 100}        Without getter setter. The old way.
# {'temp_cm': 100}   With getter setter. The code still runs. It's backward compatible !

Time to Un-learn

Regaining my time, there are long-awaited things I’m going to learn.

Having built several applications with python, I still don’t think I know python well. At the moment I would recommend the course Python for Maya: Beginner to Advanced Rigging Automation by Nick Hughes to beginners. I’ve just skimmed through about 40% of the course. The demo was done in Maya and explanation is thorough. The early parts are mostly basic but I start to find sth useful for better coding. In the past I would write

def f(nameList):
    for name in nameList:
        mc.polyCube(n=name)

f(['a','b'])

Now I could skip the for loop with map function

def f(name):
    mc.polyCube(n=name)
    
list(map(f,['a','b']))

Another one I’d like to share is The Gnomon Workshop – Automating Animation & Game-Ready Rigs by Nick Miller. It’s more advanced and I did fasten my seat belt to learn from him. He is undoubtedly an expert and made things “easy”. The videos are done so next is to study his codes and thought in OOP way.