Suppose if we need to create a group (PyNode) when it doesn't exists else we need to get variable for that node if it already exists. How to get this in one line? Let us test this in Maya with Python.
Instead of writing in 4 lines, let us do it in one line ! Here goes the code :

#Import Libraries:
from maya.cmds import *
from pymel.all import *
from pymel.core import *

#In regular way (4 Lines):
if objExists('Spine_Grp'):
    spineGrp =PyNode('Spine_Grp')
    spineGrp =PyNode(group(em=1, n='Spine_Grp'))

#One Line Statement:
spineGrp = PyNode('Spine_Grp') if objExists('Spine_Grp') else PyNode(group(em=1, n='Spine_Grp'))

That's it :)
Wish you a happy and easy coding ..

1 Comment