Check transforms script for maya

Hi everyone !!

I’m writing a simple script to check if my objects are frozen in maya.
The good thing is that it works, but I have a few questions to optimize it:

import pymel.core as pm

def checkFreeze():

nonFreezedList = []
transformNodes = = "transform")
for x in transformNodes:
    matrix =
    if str(matrix) != "[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]":
print nonFreezedList
print len(nonFreezedList)

This works properly, but I have a few questions :

  1. to check my matrix, I convert it to a string because I failed otherwise:
matrix =
    if str(matrix) != "[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]":

Is there a cleaner way to do that?

  1. My second question is that I read in another script that it’s a bad idea to check all my transform nodes and that I should list all the parent nodes of my objects instead. I don’t really understand why (I want to freeze groups too and this doesn’t affect cameras).

Is there a simple way to get a nice name instead of something like:

[nt.Transform(u'group1'), nt.Transform(u'group2'), nt.Transform(u'pCube2'), nt.Transform(u'pCylinder1')]
  1. Lastly I use the get() function, but I tried the getTransformations() function from the transform class, and I get slightly different values when not frozen (otherwise it works)

Thanks !!!

Is this what you’re after?

import pymel.core as pm
mat_identity = pm.dt.Matrix()
transforms = set('transform'))
cameras = set([cam.getParent() for cam in'camera')])
transforms = list(transforms - cameras)
frozen_nodes = list()
for trans in transforms:
    mat = trans.getMatrix()
    if mat == mat_identity:

Thank you !!! I just spend one hour to update my script to this :

import pymel.core as pm
nonFreezedList = []
shapes = ,noIntermediate=True, long=True,  allPaths=True)
shapeTransforms = pm.listRelatives( shapes, parent=True, fullPath=True )
groups = [g for g in'transform', long=True,  allPaths=True) or [] if not pm.listRelatives(g, s=True)]
transformNodes = shapeTransforms + groups

for x in transformNodes:
    if str(x.getTransformation()) != "[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]":

but you’re solution is a lot more elegant and simple.
I’m still learning python, may I ask why do you do

transforms = set('transform'))

instead of

transforms ='transform'))

Thanks again for the help !

The Set() is just used later to remove any intersections between transforms and cameras and return a list.

Hi @Diablito_Kun,

As in two lines but potentially cryptic

import maya.cmds as cmds
import maya.api.OpenMaya as apiOM

objects = filter(lambda x: x[1] and x[2], map(lambda n: (n, cmds.listRelatives(n, parent=True), cmds.listRelatives(n, shapes=True)),"geometry"))

non_frozen = filter(lambda n: apiOM.MMatrix(cmds.xform(n, q=True, m=True)) != apiOM.MMatrix(), list(sum(objects, ())))

…cleaner, more succinct - easy to understand without doing string comparisons - using api 2.0’s advantages:

objects = []

for geo in"geometry"):

   parent = cmds.listRelatives(
      geo, parent=True)
   shapes = cmds.listRelatives(
       geo, shapes=True)

   if parent and shapes:
     objects.extend([geo, parent])

# Make objects unique.
objects = list(set(objects))

non_frozen = []

for obj in objects:

    xfo = cmds.xform(obj, q=True, matrix=True)
    mat = apiOM.MMatrix(xfo)
    if mat != apiOM.MMatrix():

Thank you both of you !! This is very helpful to help me understand a lot cleaner way of doing things.
For now I’ll go for listing transform and removing cameras. This is good because it should also take locators.
I’ll see if I run into issues after testing in production, if it does I may switch to list the specific transform nodes that I need.

Thank you so much !!