def __init__(self, *args, **kwargs): """ Flags: - parent: p (QMainWindow, default:Wrapped Maya main window) The parent layout for this control. """ # Get the maya main window as a QMainWindow instance. parent = kwargs.pop('p', kwargs.pop('parent', sip.wrapinstance(long(mui.MQtUtil.mainWindow()), QObject))) super(QMainWindow, self).__init__(parent) # uic adds a function to our class called setupUi, calling this creates all the # widgets from the .ui file. self.setupUi(self) self.__name__ = self.__class__.__name__ g_name = 'g%sDocker' % self.__name__ melGlobals.initVar('string', g_name) docker = melGlobals[g_name] if docker and dockControl(docker, exists=True): info('Deleting docker: ' + docker) deleteUI(docker, control=True) docker = dockControl(allowedArea=['left', 'right'], area='right', floating=False, content=self.__name__, parent='MayaWindow|formLayout1', label=str(self.windowTitle()), width=self.width()) melGlobals[g_name] = docker.split('|')[-1]
def get_ui_path(cls, **kwargs): """ Flags: - ui_file: f (unicode, default:Subclass module's .pyc filename.ui) Full path to a user interface file to load. """ pat = re.compile('^(.+)\.pyc?$') ui_path = kwargs.pop('f', kwargs.pop('ui_file', pat.match( \ sys.modules[cls.__module__].__file__).group(1) + '.ui')) info('Loading ui file: ' + ui_path) return ui_path
def export_mesh(self, **kwargs): format, ext = str(self.format.text()), str(self.formatExt.text()) format = self.name_pat.sub( \ lambda m: '%(name)' + m.group(1)[1:], format) format = self.frame_pat.sub( \ lambda m: '%(frame)' + m.group(1)[1:], format) path = Path(self.path.text()) if not self.animation.isChecked() and self.oneFilePerNode.isChecked(): sel = ls(selection=True) for s in sel: select(s) name = format % dict(name=s.name().replace('|', '')) + ext self.write_mesh(path, name, **kwargs) select(sel) else: end, by = self.end.value(), self.by.value() frame, renum_frame, renum_by = (self.frame, self.renum_frame, self.renum_by) info('Exporting frames... Press Esc to cancel.') self.progress_init(1) while (by > 0 and frame <= end) or (by < 0 and frame >= end): if self.aborted: return setCurrentTime(frame) if self.oneFilePerNode.isChecked(): sel = ls(selection=True) for s in sel: select(s) name = format % dict(name=s.shortName(), frame=renum_frame) + ext if not self.write_mesh(path, name): break else: name = format % dict(frame=renum_frame) + ext if not self.write_mesh(path, name, **kwargs): break # Prepare for the next iteration. frame += by renum_frame += renum_by self.export_count += 1 self.progress_step()
def on_exportButton_clicked(self): if not ls(selection=True): return error('Nothing is currently selected.') # Load the objExport plug-in if it hasn't been already. kwargs = {} if self.formatExt.text() == '.obj': mll = 'objExport.mll' if not pluginInfo(mll, query=True, loaded=True): try: loadPlugin(mll) info('Loaded plug-in: ' + mll) except: return error('Failed loading plug-in: ' + mll) #kwargs = dict(force=True, constructionHistory=False, # channels=False, constraints=False, expressions=True, # shader=False, preserveReferences=False, type='OBJexport') options = dict(groups=self.groups, ptgroups=self.pointGroups, materials=self.materials, smoothing=self.smoothing, normals=self.normals) options = ';'.join('%s=%d' % (k, cb.isChecked()) \ for k, cb in options.items()) kwargs = dict(exportSelected=True, type='OBJexport', force=True, options=options) elif self.exportCombo.currentIndex() == 2: # mesh return error('Unsupported extension: %s.' % self.formatExt.text()) # Validate the output path. output_path = Path(self.path.text()) if not output_path.exists(): output_path = Path(self.set_path(workspace.getPath())) if not output_path.exists(): return # Validate the frame range. start, end, by = self.start.value(), self.end.value(), self.by.value() remainder = (end - start) % by if remainder: click_result = confirmDialog(title='Confirm', message=os.linesep.join(( \ 'The end frame will not be exported because', 'the "by frame" overshoots it by %.2f.' % remainder)), button=('OK', 'Cancel'), cancelButton='Cancel', defaultButton='OK', dismissString='Cancel') if click_result == 'Cancel': return # Validate the format. format = str(self.format.text()) try: format % (start + by) except TypeError: return error('Invalid format: "%s". ' % format + \ 'Click the \'...\' tool button for help.' % format) # Disable UI elements while running. [o.show() for o in self.run_showers] [o.setEnabled(False) for o in self.run_disablers] # Set the range. if self.renumFrames.isChecked(): renum_start = self.renumStart.value() self.renum_by = self.renumBy.value() else: renum_start = start self.renum_by = by self.frame, self.renum_frame = start, renum_start # Set loop vars. self.aborted = False self.export_count = 0 self.copy_and_replace_all = False # Call the appropriate export function. (self.export_skeleton, self.export_camera, self.export_mesh, self.export_skin_weights)[self.exportCombo.currentIndex()](**kwargs) self.main_progress.endProgress() # Enable UI elements back. [o.hide() for o in self.run_showers] [o.setEnabled(True) for o in self.run_disablers] # Report results. if self.aborted: msg = 'Aborted with %s exported' else: msg = 'Successfully exported %s' plural = self.export_count != 1 and 's' or '' frames = '%d frame' % self.export_count + plural result(msg % frames + ' to: %s.' % output_path)
def export_camera(self): start, end = self.start.value(), self.end.value() path = Path(self.path.text()) # Validate the selection. sel = ls(selection=True, dagObjects=True, cameras=True) if not ls(selection=True): return error('No cameras in selection.') # Associate the camera shapes with their parents. cams = dict((s, s.getParent()) for s in sel) # Pull-out only the attributes that are checked. shape_atts = [] for cb in self.cameraChannelsLayout.findChildren(QCheckBox): if cb.isChecked(): [shape_atts.extend(str(cb.property(n).toString()).split('|')) \ for n in cb.dynamicPropertyNames() if n == 'shortName'] cam_atts = (cb.objectName() for cb \ in self.translation.findChildren(QCheckBox) if cb.isChecked()) attributes = (shape_atts, cam_atts) # Enable any locked or non-keyable channels. for shape, cam in cams.items(): for i, obj in enumerate((shape, cam)): for att in attributes[i]: obj.attr(att).set('locked', False) obj.attr(att).set('keyable', True) # Initialize the progress bar. lc = len(cams) self.progress_init(lc + lc * len([ x for x in (self.createStandIn.isChecked(), self.oneFile.isChecked() and self.oneFilePerNode.isChecked) if x ])) # Bake the keys to the camera shape. frame_range = self.animation.isChecked() and (start, end) or (start, ) for shape, cam in cams.items(): if self.aborted: return info('Baking keys to %s: %d-%d...' % \ ((shape,) + frame_range)) bakeResults(shape, time=frame_range, simulation=True, attribute=shape_atts) info('%s keys %d-%d baked.' % ((shape, ) + frame_range)) self.progress_step() # Disable the cycle check warning. cycleCheck(evaluation=False) # Create a null stand-in for the camera and bake keys to it. #mel.source('channelBoxCommand.mel') if self.createStandIn.isChecked(): for cam in cams.values(): if self.aborted: return stand_in = Transform(name='standInNull') parentConstraint(cam, stand_in, name='nullParentConstraint') info('Baking keys to the stand-in null...') bakeResults(stand_in, time=frame_range, shape=True, simulation=True, attribute=cam_atts) info('Null keys baked.') # If the camera is a child, parent it to the world. if cam.firstParent2(): cam.setParent(world=True) # Break existing connections between the rotate or translate # attributes. for att in cam_atts: if connectionInfo(cam, isExactDestination=True): disconnectAttr( connectionInfo(cam, getExactDestination=True)) #mel.CBdeleteConnection(getExactDestination=True) # Constrain the camera to the null. parentConstraint(stand_in, cam, name='cameraParentConstraint') # Bake the camera translate/rotate keys. info('Baking keys to the camera...') bakeResults(cam, time=frame_range, disableImplicitControl=True, simulation=True, attribute=cam_atts) info('Transform keys baked.') self.progress_step() # Remove excess elements unless optimize has been disabled. if self.optimize.isChecked(): info('Optimizing scene...') delete([s for s in ls(dagObjects=True) if s not in cams.keys() + \ cams.values() + ls(selection=True, type='animCurve')]) # Save-out the cameras. kwargs = dict(force=True, constructionHistory=False, channels=True, constraints=False, expressions=False, shader=False, type='mayaAscii') ext = str(self.formatExt.text()) if self.oneFile.isChecked(): if self.oneFilePerNode.isChecked(): for cam in cams.values(): if self.aborted: return select(cam) exportSelected(path / cam.name() + ext, **kwargs) self.progress_step() else: select(cams.values()) exportSelected(path / 'camera' + ext, **kwargs) else: error('Not implemented yet. Coming soon...')
def export_camera(self): start, end = self.start.value(), self.end.value() path = Path(self.path.text()) # Validate the selection. sel = ls(selection=True, dagObjects=True, cameras=True) if not ls(selection=True): return error('No cameras in selection.') # Associate the camera shapes with their parents. cams = dict((s, s.getParent()) for s in sel) # Pull-out only the attributes that are checked. shape_atts = [] for cb in self.cameraChannelsLayout.findChildren(QCheckBox): if cb.isChecked(): [shape_atts.extend(str(cb.property(n).toString()).split('|')) \ for n in cb.dynamicPropertyNames() if n == 'shortName'] cam_atts = (cb.objectName() for cb \ in self.translation.findChildren(QCheckBox) if cb.isChecked()) attributes = (shape_atts, cam_atts) # Enable any locked or non-keyable channels. for shape, cam in cams.items(): for i, obj in enumerate((shape, cam)): for att in attributes[i]: obj.attr(att).set('locked', False) obj.attr(att).set('keyable', True) # Initialize the progress bar. lc = len(cams) self.progress_init(lc + lc * len([x for x in (self.createStandIn.isChecked(), self.oneFile.isChecked() and self.oneFilePerNode.isChecked) if x])) # Bake the keys to the camera shape. frame_range = self.animation.isChecked() and (start, end) or (start,) for shape, cam in cams.items(): if self.aborted: return info('Baking keys to %s: %d-%d...' % \ ((shape,) + frame_range)) bakeResults(shape, time=frame_range, simulation=True, attribute=shape_atts) info('%s keys %d-%d baked.' % ((shape,) + frame_range)) self.progress_step() # Disable the cycle check warning. cycleCheck(evaluation=False) # Create a null stand-in for the camera and bake keys to it. #mel.source('channelBoxCommand.mel') if self.createStandIn.isChecked(): for cam in cams.values(): if self.aborted: return stand_in = Transform(name='standInNull') parentConstraint(cam, stand_in, name='nullParentConstraint') info('Baking keys to the stand-in null...') bakeResults(stand_in, time=frame_range, shape=True, simulation=True, attribute=cam_atts) info('Null keys baked.') # If the camera is a child, parent it to the world. if cam.firstParent2(): cam.setParent(world=True) # Break existing connections between the rotate or translate # attributes. for att in cam_atts: if connectionInfo(cam, isExactDestination=True): disconnectAttr(connectionInfo(cam, getExactDestination=True)) #mel.CBdeleteConnection(getExactDestination=True) # Constrain the camera to the null. parentConstraint(stand_in, cam, name='cameraParentConstraint') # Bake the camera translate/rotate keys. info('Baking keys to the camera...') bakeResults(cam, time=frame_range, disableImplicitControl=True, simulation=True, attribute=cam_atts) info('Transform keys baked.') self.progress_step() # Remove excess elements unless optimize has been disabled. if self.optimize.isChecked(): info('Optimizing scene...') delete([s for s in ls(dagObjects=True) if s not in cams.keys() + \ cams.values() + ls(selection=True, type='animCurve')]) # Save-out the cameras. kwargs = dict(force=True, constructionHistory=False, channels=True, constraints=False, expressions=False, shader=False, type='mayaAscii') ext = str(self.formatExt.text()) if self.oneFile.isChecked(): if self.oneFilePerNode.isChecked(): for cam in cams.values(): if self.aborted: return select(cam) exportSelected(path / cam.name() + ext, **kwargs) self.progress_step() else: select(cams.values()) exportSelected(path / 'camera' + ext, **kwargs) else: error('Not implemented yet. Coming soon...')