def getFileFromPath(path):
	file_name, file_extension = os.path.splitext(path)

	ret_file = None
	new_file = None

	# if extension is .c4d, get Cinema4DFile
	if file_extension == '.c4d':
		new_file = Cinema4DFile()

	# if extension is .ma, get MayaFile
	if file_extension == '.ma':
		new_file = MayaFile()

	# if new file is set
	if new_file:
		# get new file from path
		new_file.fromFilepath(path)

		# validate new file and set return file to new file
		try:
			new_file.validate()

			ret_file = new_file
		except ValueError as message:
			print message

	return ret_file
Beispiel #2
0
	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