def execute(self, operation, file_path, **kwargs): """ Main hook entry point :operation: String Scene operation to perform :file_path: String File path to use if the operation requires it (e.g. open) :returns: Depends on operation: 'current_path' - Return the current scene file path as a String all others - None """ if operation == "current_path": # return the current scene path return tde4.getProjectPath() elif operation == "open": # do new scene as Maya doesn't like opening # the scene it currently has open! tde4.loadProject(file_path) elif operation == "save": current_file = tde4.getProjectPath() tde4.saveProject(current_file)
def setUp(self): tde4.loadProject( 'c:/_store/dev/3DEtools-env/3DEtools/tests/3de/footage02_v001.3de') # tde4.loadProject('/home/DForgacs/dev/3DEtools/tests/3de/footage02_v001.3de') try: self.tde_file = tde4.getProjectPath() except: print '--> No 3De project is opne...' raise Exception self.tde_path = os.path.dirname(self.tde_file) self.tde_filename = os.path.basename(self.tde_file) self.project = self.tde_filename.split('.')[0] self.mel_filename = self.tde_filename.replace('3de', 'mel') self.mel_file = os.path.join(self.tde_path, 'exports', self.mel_filename) self.camera_id = tde4.getCurrentCamera() self.footage = tde4.getCameraPath(self.camera_id) self.footage_name = os.path.basename(self.footage).split('.')[0] self.exportfolder = os.path.join(self.tde_path, 'exports') if os.path.exists(self.exportfolder): shutil.rmtree(self.exportfolder) assert os.path.exists(self.exportfolder) == False, '--> Export exists' MayaMelExport.main() with open(self.mel_file, 'r') as f: self.melscript = f.read()
def collect_current_3de_session(self, settings, parent_item): """ Analyzes the current session open in Maya and parents a subtree of items under the parent_item passed in. :param dict settings: Configured settings for this collector :param parent_item: Root item instance """ # get the current path file_path = tde4.getProjectPath() if not file_path: # the session has not been saved before (no path determined). # provide a save button. the session will need to be saved before # validation will succeed. self.logger.warning("The 3de scene has not been saved.", extra=self._get_save_as_action()) # Define the item's properties properties = {} session_item = self._add_file_item(settings, parent_item, file_path, False, None, "Current 3DE Session", "3de.session", parent_item.context, properties) self.logger.info("Collected item: %s" % session_item.name) return session_item
def buildUI(): # calculate Output file # we will get the path of the first camera - changed # to path to file .3DE wo extension ''' firstCam = tde4.getIndexCamera(0) firstCamPath = tde4.getCameraPath(firstCam).replace('\\', '/') ''' if tde4.getProjectPath() == None: print "Can't get the Project Path" outputFile = "Can't get the Project Path" else: # the same as the file 3DE wo the extension (asume in the 4 last chars) outputFile = tde4.getProjectPath().replace('/', '\\')[:-4] # open requester... req = tde4.createCustomRequester() tde4.addFileWidget(req, "file_browser", "Browse...", "*", outputFile) # tde4.addTextFieldWidget(req, "filePath", "Optuput file", outputFile) labels = nukeVersions.keys() labels.sort() labels.reverse() print labels #tde4.addOptionMenuWidget(req, "nukeVersion", "Nuke Version", *labels) #tde4.addToggleWidget(req, "openNuke", "Open nuke after Export", 0) # To Export tde4.addSeparatorWidget(req, "sep2") # export all cameras tde4.addToggleWidget(req, "exportAllCameras", "Export all Cameras", 1) tde4.setWidgetCallbackFunction(req, "exportAllCameras", "callBackExportAll") tde4.addSeparatorWidget(req, "sepAllCameras") # cameras to select for cameraIndex in range(tde4.getNoCameras()): cameraTmp = tde4.getIndexCamera(cameraIndex) if not tools.validCamera(cameraTmp): buildUINotSupported(req, cameraIndex, cameraTmp) else: buildUICamera(req, cameraIndex, cameraTmp) return req
def _timer(): QtCore.QCoreApplication.processEvents() # check for open file change global g_current_file cur_file = tde4.getProjectPath() if g_current_file != cur_file: if cur_file: engine = tank.platform.current_engine() context = engine.context new_context = engine.tank.context_from_path(cur_file, context) if new_context != context: tank.platform.change_context(new_context) g_current_file = cur_file
def get_mel_filename(): projectpath = os.path.abspath(tde4.getProjectPath()) folder = os.path.dirname(projectpath) projectname = os.path.basename(projectpath) mel_name = projectname.replace('3de', 'mel') path = os.path.join(folder, 'exports', mel_name) path = path.replace('\\', '/') if not os.path.exists(os.path.join(folder, 'exports')): os.mkdir(os.path.join(folder, 'exports')) # print('path: {0}'.format(path)) return {'path': path, 'filename': projectname}
def _heartbeat(self): from sgtk.platform.qt import QtCore, QtGui # Keep Qt alive QtCore.QCoreApplication.processEvents() # check for open file change cur_file = tde4.getProjectPath() if self._current_file != cur_file: if cur_file: new_context = self.sgtk.context_from_path( cur_file, self.context) if new_context != self.context: sgtk.platform.change_context(new_context) self._current_file = cur_file
def execute(self, operation, file_path, **kwargs): """ Main hook entry point :operation: String Scene operation to perform :file_path: String File path to use if the operation requires it (e.g. open) :returns: Depends on operation: 'current_path' - Return the current scene file path as a String all others - None """ if operation == "current_path": return tde4.getProjectPath() elif operation == "open": tde4.loadProject(file_path) elif operation == "save": project_path = tde4.getProjectPath() tde4.saveProject(project_path)
def _build_gui(file_path): """ Build the widgets at the top of the window. :param file_path: The initial file path to parse. :type file_path: basestring or None :returns: 3DEqualizer UI request id. """ # Get the clipboard value and test if it's a valid .mmcamera file, # if so use it as the default. If not, use the current 3DE file # path as a directory to search. cwd_path = os.getcwd() proj_path = tde4.getProjectPath() if SUPPORT_CLIPBOARD is True: file_path = tde4.getClipboardString() file_data = None if file_path: file_data = _parse_data(file_path) has_vaild_data = _file_data_has_valid_data(file_data) if has_vaild_data is not True: file_path = proj_path or cwd_path window_requester = tde4.createCustomRequester() file_pattern = '*' + EXT tde4.addFileWidget( window_requester, FILE_BROWSER_WIDGET, FILE_BROWSER_LABEL, file_pattern, file_path, ) tde4.setWidgetCallbackFunction( window_requester, FILE_BROWSER_WIDGET, '_build_widgets' ) pgroup_id, cam_id, lens_id = _query_selection_state() has_vaild_data = _file_data_has_valid_data(file_data) if has_vaild_data is not True or not pgroup_id or not cam_id or not lens_id: _build_widgets(window_requester, FILE_BROWSER_WIDGET, 0) else: _build_widgets_with_data(window_requester, pgroup_id, cam_id, lens_id, file_data) return window_requester
def _timer(): """ Poller to listen to the change of the scene file to determine the new context. """ QtCore.QCoreApplication.processEvents() # check for open file change global g_current_file cur_file = tde4.getProjectPath() if g_current_file != cur_file: if cur_file: engine = sgtk.platform.current_engine() context = engine.context new_context = engine.sgtk.context_from_path(cur_file, context) if new_context != context: sgtk.platform.change_context(new_context) g_current_file = cur_file
def test__mel_filepath_is_3de_path_plus_export(self): project = tde4.getProjectPath() paths = MayaMelExport.get_mel_filename() print project print paths
n = 0 i0 = -1 while (i < len(path)): if path[i] == '#': n += 1 if n == 1: i0 = i i += 1 if i0 != -1: fstring = "%%s%%0%dd%%s" % (n) path2 = fstring % (path[0:i0], startframe, path[i0 + n:len(path)]) path = path2 return path # # main script... projectPath = tde4.getProjectPath() projectName = os.path.basename(projectPath) ShotName = projectName.split('_')[1] # # search for camera point group... campg = None pgl = tde4.getPGroupList() for pg in pgl: if tde4.getPGroupType(pg) == "CAMERA": campg = pg if campg == None: tde4.postQuestionRequester("Export Maya...", "Error, there is no camera point group.", "Ok") # # open requester...
def execute(self, operation, file_path, context, parent_action, file_version, read_only, **kwargs): """ Main hook entry point :param operation: String Scene operation to perform :param file_path: String File path to use if the operation requires it (e.g. open) :param context: Context The context the file operation is being performed in. :param parent_action: This is the action that this scene operation is being executed for. This can be one of: - open_file - new_file - save_file_as - version_up :param file_version: The version/revision of the file to be opened. If this is 'None' then the latest version should be opened. :param read_only: Specifies if the file should be opened read-only or not :returns: Depends on operation: 'current_path' - Return the current scene file path as a String 'reset' - True if scene was reset to an empty state, otherwise False all others - None """ if operation == "current_path": # return the current project path return tde4.getProjectPath() elif operation == "open": self._set_preferences(context) tde4.loadProject(file_path) elif operation == "save": project_path = tde4.getProjectPath() tde4.saveProject(project_path) elif operation == "save_as": tde4.saveProject(file_path) elif operation == "reset": """ Reset the scene to an empty state """ while not tde4.isProjectUpToDate(): self.logger.debug(file_path) # changes have been made to the scene res = QtGui.QMessageBox.question( QtGui.QApplication.activeWindow(), "Save your scene?", "Your scene has unsaved changes. Save before proceeding?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel) if res == QtGui.QMessageBox.Cancel: return False elif res == QtGui.QMessageBox.No: break else: project_path = tde4.getProjectPath() if not project_path: # there is no 3de python API to open a save file GUI, so just use sgtk self.parent.engine.commands["File Save..."][ "callback"]() return False else: tde4.saveProject(project_path) # do new file: tde4.newProject() if parent_action == "new_file": self._set_preferences(context) self.parent.engine.commands["File Save..."]["callback"]() # call the task status updates return super(SceneOperation, self).execute(operation, file_path, context, parent_action, file_version, read_only, **kwargs)
QtCore.QCoreApplication.processEvents() # check for open file change global g_current_file cur_file = tde4.getProjectPath() if g_current_file != cur_file: if cur_file: engine = tank.platform.current_engine() context = engine.context new_context = engine.tank.context_from_path(cur_file, context) if new_context != context: tank.platform.change_context(new_context) g_current_file = cur_file if __name__ == '__main__': engine = tank.platform.current_engine() if not engine: from tank_vendor.shotgun_authentication import ShotgunAuthenticator user = ShotgunAuthenticator(tank.util.CoreDefaultsManager()).get_user() tank.set_authenticated_user(user) context = tank.context.deserialize(os.environ.get("TANK_CONTEXT")) engine = tank.platform.start_engine('tk-3de4', context.tank, context) # Qt if not QtCore.QCoreApplication.instance(): QtGui.QApplication([]) global g_current_file g_current_file = tde4.getProjectPath() tde4.setTimerCallbackFunction("_timer", 50) engine.post_qt_init()
def compress(cams, ui=False): errors = [] max_steps = 0 seq_cams = {} for cam in cams: cam_name = tde4.getCameraName(cam) if tde4.getCameraType(cam) != 'SEQUENCE': errors.append( 'Camera {} is not a Sequence Camera.'.format(cam_name)) continue start, end = tde4.getCameraSequenceAttr(cam)[:2] frames = abs(end - start + 1) steps = frames + frames / 100 + 2 max_steps += steps seq_cams[cam] = { 'name': cam_name, 'start': start, 'end': end, 'frames': frames, 'steps': steps } if cams: if ui: tde4.postProgressRequesterAndContinue(TITLE, 'Please wait...', max_steps, 'Ok') else: print(TITLE) else: errors.append('Please choose a camera.') steps_done = 0 for cam in seq_cams: cam_name = seq_cams[cam]['name'] msg = 'Exporting: {} (starting)'.format(cam_name) if ui: tde4.updateProgressRequester(steps_done, msg) else: print(' 0% ' + msg) start = seq_cams[cam]['start'] end = seq_cams[cam]['end'] frames = seq_cams[cam]['frames'] steps = seq_cams[cam]['steps'] path = tde4.getCameraPath(cam) if tde4.getPreferenceValue('ICOMPRESS_BCFILE_IN_DIR') == '1': # save buffer in project directory project_dir = os.path.dirname(tde4.getProjectPath()) if project_dir: # we have a project directory, it's safe to save target_path = os.path.join(project_dir, os.path.basename(path)) else: # no project directory, alert the user target_path = '' errors.append( 'Can not save buffer to project directory. Project is not saved.' ) elif tde4.getPreferenceValue('ICOMPRESS_BCFILE_IN_DIR') == '2': # save buffer in custom directory custom_dir = tde4.getPreferenceValue('ICOMPRESS_CUSTOM_DIR') target_path = os.path.join(custom_dir, os.path.basename(path)) else: # default behavior, save buffer in image path target_path = path if not path: errors.append( ("Couldn't process camera {} because it doesn't have " 'any Footage loaded.').format(cam_name)) steps_done += steps continue gamma = tde4.getCamera8BitColorGamma(cam) softclip = tde4.getCamera8BitColorSoftclip(cam) black, white = tde4.getCamera8BitColorBlackWhite(cam) exr = tde4.getCameraImportEXRDisplayWindowFlag(cam) sxr = tde4.getCameraImportSXRRightEyeFlag(cam) if sxr == 1: sxr2 = " -import_sxr_right_eye " else: sxr2 = " " if exr == 1: exr2 = " -import_exr_display_window " else: exr2 = " " proc_err = None # makeBCFile exits cleanly even if it errored, so we have to parse # its errors manually. proc = subprocess.Popen( (os.path.join(tde4.get3DEInstallPath(), 'bin', 'makeBCFile'), '-source', path, '-start', str(start), '-end', str(end), '-out', os.path.dirname(target_path), sxr2, exr2, '-black', str(black), '-white', str(white), '-gamma', str(gamma), '-softclip', str(softclip)), stdout=subprocess.PIPE, universal_newlines=True) for line in iter(proc.stdout.readline, ''): line = line.rstrip() if line.startswith('Error'): proc_err = line continue elif line.endswith('image files processed'): frame = int(line.split('/', 1)[0]) msg = 'Exporting: {} ({}/{})'.format(cam_name, frame, frames) if ui: tde4.updateProgressRequester(steps_done + frame + 1, msg) else: print('{: 3d}% {}'.format( 100 * (steps_done + frame + 1) / max_steps, msg)) if proc_err: errors.append( "Couldn't create Buffer Compression File for Camera {}.". format(cam_name)) errors.append('Message >> {}'.format(proc_err)) steps_done += steps continue msg = 'Exporting: {} (finishing)'.format(cam_name) if ui: tde4.updateProgressRequester(steps_done + frames + 2, msg) else: print('{: 3d}% {}'.format( 100 * (steps_done + frames + 2) / max_steps, msg)) bcompress = ('x'.join(target_path.split('#' * path.count('#'))) + '.3de_bcompress') if not os.path.isfile(bcompress): errors.append( "Couldn't find Buffer Compression File for Camera {}.".format( cam_name)) steps_done += steps continue if not tde4.importBufferCompressionFile(cam): errors.append( "Couldn't import Buffer Compression File for Camera {}.". format(cam_name)) # Change permissions of the Buffer Compression File, # to be nice to everyone else who might work on the shot eventually! try: os.chmod(bcompress, 0o666) except OSError: errors.append( "Couldn't set permissions of Buffer CompressionFile for Camera {}." .format(cam_name)) steps_done += steps if ui: tde4.unpostProgressRequester() if errors: req = tde4.createCustomRequester() for i, line in enumerate(errors): name = 'line{}'.format(i) tde4.addLabelWidget(req, name, line, 'ALIGN_LABEL_LEFT') tde4.setWidgetOffsets(req, name, 0, 0, 0, 0) tde4.postCustomRequester(req, TITLE, 0, 0, 'Ok') else: print('100% Done.') if errors: raise RuntimeError('\n'.join(errors))
def __init__(self, *args, **kwargs): self._current_file = tde4.getProjectPath() self._custom_scripts_dir_path = None Engine.__init__(self, *args, **kwargs)