def namespace_deleter(cls): """the legendary namespace deleter from Mehmet Erer finds and deletes unused namespaces """ all_namespaces = pm.listNamespaces() ref_namespaces = [ref.namespace for ref in pm.listReferences()] missing_namespaces = [] from anima.ui.progress_dialog import ProgressDialogManager if len(all_namespaces) > 0: pdm = ProgressDialogManager() pdm.close() caller = pdm.register(len(all_namespaces), 'Locating Unused Namespaces...') for nsa in all_namespaces: i = 0 for nsr in ref_namespaces: i += 1 if nsr == nsa: break if i == len(ref_namespaces): missing_namespaces.append(nsa) caller.step() if len(missing_namespaces) > 0: caller = pdm.register(len(missing_namespaces), 'Deleting Unused Namespaces...') for ns in missing_namespaces: ns_info = pm.namespaceInfo(ns, lon=1, fn=1, r=1) if len(ns_info) > 0: nsc = ns_info[len(ns_info) - 1] nsc_array = nsc.split(':') if len(nsc_array) > 0: for del_nsc in nsc_array: pm.namespace(rm=del_nsc, mnr=1) else: pm.namespace(rm=ns, mnr=1) print('Deleted -> :' + ns) caller.step() else: pm.warning( 'There are no first-level unused namespaces in this scene.' ) if len(ref_namespaces) == 0 and len(all_namespaces) > 0: for ns in all_namespaces: pm.namespace(rm=ns, mnr=1) print('Deleted -> : %s' % ns) pm.warning( 'There are no references in this scene. All empty namespaces ' 'are deleted.' )
def save_previs_to_shots(self, take_name): """exports previs to animation shots """ self.pre_publish_previs() shot_tasks = self.scene_shot_tasks shot_nodes = self.shot_list shots_to_export = [] for shot_node in shot_nodes: for shot_task in shot_tasks: for task in shot_task.tasks: if task.type == self.anim_type: shot_number = shot_task.name.split('_')[-1] if shot_node.getShotName() == shot_number: shots_to_export.append( [shot_node, task, shot_number]) from anima.env import mayaEnv from stalker import Version from anima.ui.progress_dialog import ProgressDialogManager pdm = ProgressDialogManager() pdm.close() m_env = mayaEnv.Maya() versions = [] description = 'Auto Created By Shot Exporter' # create versions to save and show in pop-up window for shot_info in shots_to_export: version = Version(task=shot_info[1], description=description, take_name=take_name, created_by=self.logged_in_user) versions.append(version) if len(versions) != len(shots_to_export): from stalker.db.session import DBSession DBSession.rollback() raise RuntimeError( 'Something is critically wrong. Contact Mehmet ERER.') # pop-up a window to show everything will be saved properly before actually doing it message = 'Shots will be Saved as Below:\r\n' message += '\r' index = 0 for shot_info in shots_to_export: v = versions[index] message += 'shot[ %s ] -> %s\n' % (shot_info[2], v) index += 1 dialog = pm.confirmDialog( title='Important Warning', message=message, button=['OK, Start Saving Shots', 'STOP, wrong paths!']) if dialog == 'OK, Start Saving Shots': pass else: from stalker.db.session import DBSession DBSession.rollback() raise RuntimeError('Process Interrupted by User.') previs_version = self.current_version errored_shots = [] ind = 0 caller = pdm.register( len(shots_to_export), 'Batch Saving Previs Shot Nodes to Animation Shot Tasks...') from anima.env.mayaEnv import toolbox from stalker.db.session import DBSession for shot_info in shots_to_export: shot_task = versions[ind].task.parent try: # open previs version m_env.open(previs_version, force=True, reference_depth=3, skip_update_check=True) # clear scene except_this_shot = pm.PyNode(shot_info[0].name()) self.clear_scene(except_this_shot) # set frame range before save anima.env.mayaEnv.animation.Animation.set_range_from_shot() # update shot.cut_in and shot.cut_out info cut_in = pm.playbackOptions(q=1, min=1) cut_out = pm.playbackOptions(q=1, max=1) shot_task.cut_in = int(cut_in) shot_task.cut_out = int(cut_out) # save it m_env.save_as(versions[ind]) except: errored_shots.append(shot_info[2]) else: # store information to database DBSession.add(shot_task) DBSession.add(versions[ind]) DBSession.commit() ind += 1 caller.step() if errored_shots: message = 'Shots could not be saved:\r\n' message += '\r' for shot in errored_shots: message += '[ %s ]\n' % shot pm.confirmDialog(title='Error', message=message, button='OK') DBSession.rollback() raise RuntimeError( 'Some Shots could not be saved. Contact Mehmet ERER.') # leave it as empty new file pm.newFile(force=True) message = 'Previs to Shots\r\n' message += '\r' message += 'Completed Succesfully.\r\n' pm.confirmDialog(title='Info', message=message, button='OK')
def save_previs_to_shots(self, take_name): """exports previs to animation shots """ self.pre_publish_previs() shot_tasks = self.scene_shot_tasks shot_nodes = self.shot_list shots_to_export = [] for shot_node in shot_nodes: for shot_task in shot_tasks: for task in shot_task.tasks: if task.type == self.anim_type: shot_number = shot_task.name.split('_')[-1] if shot_node.getShotName() == shot_number: shots_to_export.append([shot_node, task, shot_number]) from anima.env import mayaEnv from stalker import Version from anima.ui.progress_dialog import ProgressDialogManager pdm = ProgressDialogManager() pdm.close() m_env = mayaEnv.Maya() versions = [] description = 'Auto Created By Shot Exporter' # create versions to save and show in pop-up window for shot_info in shots_to_export: version = Version( task=shot_info[1], description=description, take_name=take_name, created_by=self.logged_in_user ) versions.append(version) if len(versions) != len(shots_to_export): from stalker.db.session import DBSession DBSession.rollback() raise RuntimeError('Something is critically wrong. Contact Mehmet ERER.') # pop-up a window to show everything will be saved properly before actually doing it message = 'Shots will be Saved as Below:\r\n' message += '\r' index = 0 for shot_info in shots_to_export: v = versions[index] message += 'shot[ %s ] -> %s\n' % (shot_info[2], v) index += 1 dialog = pm.confirmDialog(title='Important Warning', message=message, button=['OK, Start Saving Shots', 'STOP, wrong paths!']) if dialog == 'OK, Start Saving Shots': pass else: from stalker.db.session import DBSession DBSession.rollback() raise RuntimeError('Process Interrupted by User.') previs_version = self.current_version errored_shots = [] ind = 0 caller = pdm.register(len(shots_to_export), 'Batch Saving Previs Shot Nodes to Animation Shot Tasks...') from anima.env.mayaEnv import toolbox reload(toolbox) from stalker.db.session import DBSession for shot_info in shots_to_export: shot_task = versions[ind].task.parent try: # open previs version m_env.open(previs_version, force=True, reference_depth=3, skip_update_check=True) # clear scene except_this_shot = pm.PyNode(shot_info[0].name()) self.clear_scene(except_this_shot) # set frame range before save toolbox.Animation.set_range_from_shot() # update shot.cut_in and shot.cut_out info cut_in = pm.playbackOptions(q=1, min=1) cut_out = pm.playbackOptions(q=1, max=1) shot_task.cut_in = int(cut_in) shot_task.cut_out = int(cut_out) # save it m_env.save_as(versions[ind]) except: errored_shots.append(shot_info[2]) else: # store information to database DBSession.add(shot_task) DBSession.add(versions[ind]) DBSession.commit() ind += 1 caller.step() if errored_shots: message = 'Shots could not be saved:\r\n' message += '\r' for shot in errored_shots: message += '[ %s ]\n' % shot pm.confirmDialog(title='Error', message=message, button='OK') DBSession.rollback() raise RuntimeError('Some Shots could not be saved. Contact Mehmet ERER.') # leave it as empty new file pm.newFile(force=True) message = 'Previs to Shots\r\n' message += '\r' message += 'Completed Succesfully.\r\n' pm.confirmDialog(title='Info', message=message, button='OK')