def saveRefsSources(replaceDB): processedPaths = set() for tr, path in replaceDB.items(): if not m.objExists(tr): continue expandedPath = expandPath(path) if expandedPath in processedPaths: continue shape = getShape(tr) childTransforms = getChildTransforms(tr) if not shape and not childTransforms: log.logAppend('Cannot save empty transform: {}. Source save skipped.'.format(tr)) continue else: oldParent = getParent(tr) tr2 = m.duplicate(tr, rr=True) if oldParent: newObject = m.parent(tr2, world=True)[0] else: newObject = tr2 worldRP = m.xform(newObject, q=True, rotatePivot=True, worldSpace=True) m.xform(newObject, relative=True, worldSpace=True, translation=[-x for x in worldRP]) m.xform(newObject, absolute=True, rotation=(0, 0, 0), scale=(1, 1, 1), shear=(0, 0, 0)) if shape: m.select(newObject, r=True) else: children = getChildTransforms(newObject) if children: newChildren = m.parent(children, world=True) m.select(newChildren, r=True) ext = os.path.splitext(path)[1] watch(path, 'saving path') makeWritable(expandPath(path)) m.file( path, exportSelected=True, force=True, typ='mayaBinary' if ext == '.mb' else 'mayaAscii', options='v=0;' ) if not shape: m.delete(newChildren) m.delete(newObject) processedPaths.add(expandedPath) return processedPaths
def initHandle(self, transform=None, shape=None): if (transform is not None) and (m.objExists(transform)): self.transform = transform self.shape = getShape(transform) elif (shape is not None) and (m.objExists(shape)): self.transform = getParent(shape) self.shape = shape else: self.transform = None self.shape = None
def createNew(self, refFilename): refLocatorTr = m.spaceLocator(p=(0, 0, 0))[0] refLocatorTr = getLongName(m.rename(refLocatorTr, self.generateShortName(refFilename) + REF_LOCATOR_SUFFIX)) refLocatorSh = getShape(refLocatorTr) m.addAttr( refLocatorSh, at='message', shortName=ATTR_REF_NODE_MESSAGE_NAMES[0], longName=ATTR_REF_NODE_MESSAGE_NAMES[1], niceName=ATTR_REF_NODE_MESSAGE_NAMES[2] ) m.addAttr( refLocatorSh, dt='string', shortName=ATTR_REF_FILENAME_NAMES[0], longName=ATTR_REF_FILENAME_NAMES[1], niceName=ATTR_REF_FILENAME_NAMES[2] ) m.setAttr('{}.{}'.format(refLocatorSh, ATTR_REF_FILENAME), refFilename, typ='string') self.loadFromRefLocatorShape(refLocatorSh)