def next_version(file_): """ Get the next version from the given file Args: file_: Raises: ValueError: if the filename is not correct Returns: str: file with last version """ split_file = file_.rsplit("_", 1) name_file = split_file[0] version = split_file[-1] padding = len(version) if version.isdigit(): next_version = int(version) + 1 next_version = str(next_version).zfill(padding) return concat(name_file, next_version, separator="_") else: e = concat(file_, " is incorrect.") raise ValueError(e)
def publish(filepath_): path, name = os.path.split(filepath_) publish_path = path.rsplit("/", 1)[0] publish_path = concat(publish_path, "PUBLISH", separator="/") name, ext = os.path.splitext(name) publish_name = name.rsplit("_", 1)[0] + ext publish_ = concat(publish_path, publish_name, separator="/") save_as(publish_) open_file(filepath_)
def create_group(self): if not self.type_grp: mc.group(empty=True, name=concat(self.asset, self.asset_type, "grp", separator="_")) if not self.main_grp: mc.group(empty=True, name=concat(self.asset, "grp", separator="_")) try: mc.parent(self.type_grp, self.main_grp) except RuntimeError: pass
def compute_export_path(self, comment=""): if comment in [None, ""]: filename = concat(self.name, self.task, separator="_") path = os.path.join(self.path, self.name, self.task).replace("\\", "/") else: filename = concat(self.name, self.task, comment, separator="_") path = os.path.join(self.path, self.name, self.task, comment).replace("\\", "/") make_dirs(path) filepath_ = concat(path, filename, separator="/") print(filepath_) return filepath_
def file_to_load(self, path): last_file = self.get_last_file(path) filepath = concat(path, last_file, separator="/") return filepath
def quick_renaming(): from Maya.tree.create_tree import ProjectTree sel = get_objects(dag=False) asset_name = ProjectTree().asset for obj in sel: mc.rename(obj, concat(asset_name, "C", obj, "geo", separator="_"))
def save(self, item="", dpt=""): # type: (Optional[Union[Asset, Shot]], str) -> None """. Args: item: name of the asset dpt: department of the file: MOD, RIG, SHD """ if self.filepath: path, _ = os.path.split(self.filepath) file_ = self.get_last_file(path) last_file, _ = os.path.splitext(file_) new_filename = self.next_version(last_file) new_filepath = concat(path, new_filename + MAYA_EXT, separator="/") ProjectTree() save_as(new_filepath) else: path = os.path.join(item.paths["PATH"], item.name, dpt).replace("\\", "/") path = glob_path_recursive(path, "VERSION") file_ = self.get_last_file(path) if item.name in file_ and dpt in file_ and MAYA_EXT in file_: last_file, _ = os.path.splitext(file_) filename = self.next_version(last_file) else: filename = concat(item.name, dpt, "001" + MAYA_EXT, separator="_") filepath_ = concat(path, filename + MAYA_EXT, separator="/") ProjectTree(filepath_) save_as(filepath_)
def check(selection): _asset = (r"^(?P<asset>[A-Z]+)") _side = (r"(?P<side>C|L|R)") _object = (r"(?P<object>[A-Za-z0-9]+)") _type = ( r"(?P<type>jnt|jntEnd|geo|ctrl|loc|clstr|crv|nbs|ikhl|grp|parentConstraint|poleVectorConstraint)$" ) obj_regex = re.compile(concat(_asset, _side, _object, _type, separator="_")) grp_regex = re.compile( r"^(?P<asset>[A-Z]+)_(?P<object>SKL|CTRL|XTRAS|GEO)_(?P<type>grp)$") list_error = list() for each in selection: match = obj_regex.match(each) grp_match = grp_regex.match(each) if not match and not grp_match and not "effector" in each: list_error.append(each) if list_error != []: raise RuntimeError("Some error in naming", list_error)
def main_grp(self): return mc.ls(concat(self.asset, "grp", separator="_"))
def type_grp(self): return mc.ls(concat(self.asset, self.asset_type, "grp", separator="_"))