def doReplacement(replaceDB): notExistingSources = set() createdRefs = [] for tr, path in replaceDB.items(): if path in notExistingSources: continue if not os.path.exists(os.path.expandvars(path)): notExistingSources.add(path) log.logAppend('Path does not exists: {}. Replacement skipped.'.format(path)) continue refHandle = RefHandle() refHandle.createNew(path) createdRefs.append(refHandle) worldRP = m.xform(tr, q=True, rotatePivot=True, worldSpace=True) m.xform(refHandle.refLocator.transform, translation=worldRP, absolute=True, worldSpace=True) transformParent = getParent(tr) if transformParent: newRefLocTransform = getLongName(m.parent(refHandle.refLocator.transform, transformParent)[0]) refHandle.setRefLocator(TransformHandle(transform=newRefLocTransform)) rotation = m.xform(tr, q=True, rotation=True, objectSpace=True) scale = m.xform(tr, q=True, scale=True, objectSpace=True, relative=True) shear = m.xform(tr, q=True, shear=True, objectSpace=True, relative=True) m.xform(refHandle.refLocator.transform, rotation=rotation, scale=scale, shear=shear) if m.objExists(tr): m.delete(tr) return createdRefs
def createAnnotation(self): if not self.isValid(): return annotationShapes = self.refLocator.getChildren(allDescendants=True, typ='annotationShape') for s in annotationShapes: m.delete(getParent(s)) annotationSh = m.annotate(self.refLocator.transform, p=(0, -0.5, 0)) annotationTr = getParent(annotationSh) annotationTr = m.parent(annotationTr, self.refLocator.transform, relative=True)[0] lockTransformations(annotationTr) self.annotation = TransformHandle(transform=getLongName(annotationTr)) m.setAttr(self.annotation.shape + '.displayArrow', False) m.setAttr(self.annotation.transform + '.overrideEnabled', True) m.setAttr(self.annotation.transform + '.overrideDisplayType', 2)
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 prepareModelData(self, matchedData): # input [(fullPathName, searchField), ....] # return [(exists, shortName, filename, mayaPath, nodeInfo), ...] modelData = [] for fullPathName, shortName in matchedData: filename = self.getRefFilename(fullPathName) exists = 'Yes' if os.path.exists(os.path.expandvars(filename)) else 'No' mayaPath = getParent(fullPathName) ni = NodeInfo() ni.selectionString = [mayaPath] ni.fullPathName = mayaPath ni.shortName = shortName modelData.append((exists, shortName, filename, mayaPath, ni)) # print modelData return modelData
def prepareModelData(self, matchedData): # input [(fullPathName, searchField), ....] # return [(exists, shortName, filename, mayaPath, nodeInfo), ...] modelData = [] for fullPathName, shortName in matchedData: filename = self.getRefFilename(fullPathName) exists = 'Yes' if os.path.exists( os.path.expandvars(filename)) else 'No' mayaPath = getParent(fullPathName) ni = NodeInfo() ni.selectionString = [mayaPath] ni.fullPathName = mayaPath ni.shortName = shortName modelData.append((exists, shortName, filename, mayaPath, ni)) # print modelData return modelData