def createFile(self): # check if current user exists if self.getUser().exists(): # check if current asset is set if self.getAsset(): filetype = config['filetypes'][self.filetype_select_widget.currentIndex()] comment = self.comment_line_widget.text() filename = self.name_line_widget.text() new_file = MayaFile() new_file.setName(filename) new_file.setFiletype(filetype) new_file.setUser(self.getUser()) new_file.setAsset(self.getAsset()) new_file.setComment(comment) # try to create new managed file try: new_file.validate() if ensurePath(new_file.getPath()): # rename maya document to new file name cmds.file(rename = new_file.getPath()) # save maya document to new file path if cmds.file(save = True, type = 'mayaAscii'): # set workspace setWorkspace(new_file.getAppPath()) # create default workspace dirs createWorkspace(new_file.getAppPath()) self.close() except ValueError as message: print message self.setError(str(message)) else: self.setError('No Asset selected') else: self.setError('User does not exist') self.showErrors() return self
# pipeline modules # config from config import config # helpers from helpers.dir_helper import ensurePath from helpers.maya_helper import setWorkspace, getWorkspace # actions from actions import PipelineActions # models from models import Asset, User, MayaFile if __name__ == '__main__': # browse for file to open file_path_list = cmds.fileDialog2(fileFilter = '*.ma', fileMode = 1) # if a path is returned if file_path_list: file_path = file_path_list[0] # get managed file from selected file path new_file = PipelineActions.getFileFromPath(os.path.normpath(file_path)) # if selected file is managed file, open that file and set the workspace to current asset directory if new_file: if cmds.file(new_file.getPath(), open = True, force = True): # set workspace setWorkspace(new_file.getAppPath())