def export_skin(file_path=None, shapes=None): """Exports the skinClusters of the given shapes to disk. :param file_path: Path to export the data. :param shapes: Optional list of dag nodes to export skins from. All descendent nodes will be searched for skinClusters also. """ if shapes is None: shapes = cmds.ls(sl=True) or [] # If no shapes were selected, export all skins skins = get_skin_clusters(shapes) if shapes else cmds.ls(type="skinCluster") if not skins: raise RuntimeError("No skins to export.") if file_path is None: start_dir = shortcuts.get_setting(KEY_STORE, cmds.workspace(q=True, rd=True)) if len(skins) == 1: file_path = cmds.fileDialog2( dialogStyle=2, fileMode=0, fileFilter="Skin Files (*{0})".format(EXTENSION), startingDirectory=start_dir, ) if file_path and not file_path[0].endswith(EXTENSION): file_path[0] += EXTENSION else: file_path = cmds.fileDialog2( dialogStyle=2, fileMode=3, startingDirectory=start_dir ) if not file_path: return file_path = file_path[0] directory = file_path if len(skins) > 1 else os.path.dirname(file_path) # Save the directory in the cache shortcuts.set_setting(KEY_STORE, directory) if not os.path.exists(directory): os.makedirs(directory) for skin in skins: skin = SkinCluster(skin) data = skin.gather_data() logger.info( "Exporting skinCluster %s on %s (%d influences, %d vertices)", skin.node, skin.shape, len(data["weights"].keys()), len(data["blendWeights"]), ) if len(skins) > 1: # With multiple skinClusters, the user just chooses an export directory. Set the # name to the transform name. file_path = os.path.join( directory, "{}{}".format(skin.shape.replace("|", "!"), EXTENSION) ) with open(file_path, "w") as fh: json.dump(data, fh)
def _save(self): """Saves the string list to the persistent cache.""" shortcuts.set_setting(self._name, json.dumps(self.stringList()))