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 dump(filename, obj, showError=True): try: makeWritable(filename) with open(filename, 'w') as f: f.write(yaml.dump(obj, default_flow_style=False)) except IOError: if showError: message_box.exception('Cannot save YAML file:\n{}'.format(filename)) raise except StandardError: if showError: message_box.exception('Unexpected error saving YAML file:\n{}'.format(filename)) raise
def dump(filename, obj, showError=True): try: makeWritable(filename) with open(filename, "w") as f: json.dump(obj, f, sort_keys=True, indent=4, separators=(",", ": ")) except IOError: if showError: message_box.exception("Cannot save JSON file:\n{}".format(filename)) raise except StandardError: if showError: message_box.exception("Unexpected error saving JSON file:\n{}".format(filename)) raise
def dump(filename, obj, showError=True): try: makeWritable(filename) with open(filename, 'w') as f: json.dump(obj, f, sort_keys=True, indent=4, separators=(',', ': ')) except IOError: if showError: message_box.exception( 'Cannot save JSON file:\n{}'.format(filename)) raise except StandardError: if showError: message_box.exception( 'Unexpected error saving JSON file:\n{}'.format(filename)) raise
def dump(filename, obj, showError=True): try: makeWritable(filename) with open(filename, 'w') as f: f.write(yaml.dump(obj, default_flow_style=False)) except IOError: if showError: message_box.exception( 'Cannot save YAML file:\n{}'.format(filename)) raise except StandardError: if showError: message_box.exception( 'Unexpected error saving YAML file:\n{}'.format(filename)) raise
def execute(self): filesToProcess = self.getFilesToProcess() if self.copyFolderStruct: copyInfo = self.getCopyInfoFolderStructure(filesToProcess) else: copyInfo = self.getCopyInfoSimple(filesToProcess) checkedDirs = set() createdDirs = set() for s, t in copyInfo: targetDir = os.path.dirname(t) if targetDir not in checkedDirs: checkedDirs.add(targetDir) if not os.path.exists(targetDir): try: os.makedirs(targetDir) createdDirs.add(targetDir) except os.error as e: self.log('') self.log('Cannot create dir: {0}'.format(targetDir)) self.log(str(e)) else: createdDirs.add(targetDir) if targetDir in createdDirs: try: makeWritable(t) shutil.copy(s, t) self.processedInfo[s.lower()] = t except IOError as e: self.log('') self.log('Cannot copy file: {0} -> {1}'.format(s, t)) self.log(str(e)) if self.delSrc: for f in self.processedInfo: if os.path.exists(f): try: makeWritable(f) os.remove(f) except OSError as e: self.log('') self.log('Cannot delete file: {0}'.format(f)) self.log(str(e))