def setSilentMode(self, switch): """ \remarks implements AbstractScene.setSilentMode method to make the application silent during intense calls. \param switch <bool> \return <bool> success """ if switch: if not self._buffer.get('silentMode', None): self._buffer['silentMode'] = {} self._buffer['silentMode']['cmdlog'] = xsi.GetValue( "preferences.scripting.cmdlog") self._buffer['silentMode']['msglogverbose'] = xsi.GetValue( "preferences.scripting.msglogverbose") self._buffer['silentMode']['msglogrealtime'] = xsi.GetValue( "preferences.scripting.msglogrealtime") self._buffer['silentMode']['autoinspect'] = xsi.GetValue( "preferences.Interaction.autoinspect") xsi.SetValue("preferences.scripting.cmdlog", False, "") xsi.SetValue("preferences.scripting.msglogverbose", False, "") xsi.SetValue("preferences.scripting.msglogrealtime", False, "") xsi.SetValue("preferences.Interaction.autoinspect", False, "") else: if self._buffer.get('silentMode', None): xsi.SetValue("preferences.scripting.cmdlog", self._buffer['silentMode']['cmdlog'], "") xsi.SetValue("preferences.scripting.msglogverbose", self._buffer['silentMode']['msglogverbose'], "") xsi.SetValue("preferences.scripting.msglogrealtime", self._buffer['silentMode']['msglogrealtime'], "") xsi.SetValue("preferences.Interaction.autoinspect", self._buffer['silentMode']['autoinspect'], "") del self._buffer['silentMode'] return True
def renderSize(self): """ \remarks return the render output size for the scene \return <QSize> """ from PyQt4.QtCore import QSize return QSize(xsi.GetValue("Passes.RenderOptions.ImageWidth"), xsi.GetValue("Passes.RenderOptions.ImageHeight"))
def slateIsActive(self): import cross3d application = cross3d.application version = application.version() if version > 9: camera = self._nativeCamera() return xsi.GetValue(camera.FullName + '.camvis.camerainfo') return False
def resolutionPath(self, resolution=''): if self.isReferenced(): if not resolution: resolution = self.resolution() resolutions = self.resolutions() if resolution in resolutions: return xsi.GetValue("%s.resolutions.res%i.file" % (self.name(), resolutions.index(resolution))) return ''
def viewOptions(self): viewOptions = {'Camera Visibility': {}, 'Camera Display': {}} for parameter in self._nativePointer.Properties('Camera Visibility').Parameters: viewOptions['Camera Visibility'][ parameter.ScriptName ] = parameter.Value for parameter in self._nativePointer.Properties('Camera Display').Parameters: viewOptions['Camera Display'][ parameter.ScriptName ] = parameter.Value viewOptions[ 'viewcubeshow' ] = xsi.GetValue('preferences.ViewCube.show') return viewOptions
def setViewOptions(self, viewOptions): for prop in viewOptions: if prop in [ 'Camera Visibility', 'Camera Display' ]: for param in viewOptions[prop]: if not param in ['hidlincol', 'wrfrmdpthcuecol']: try: self._nativePointer.Properties(prop).Parameters(param).Value = viewOptions[prop][param] except: print 'TRACEBACK: skipping param: {} {}...'.format(prop, param) print traceback.format_exc() xsi.SetValue('preferences.ViewCube.show', viewOptions.get('viewcubeshow'), xsi.GetValue('preferences.ViewCube.show')) return True
def platePath(self): """ TODO: This is currently only handling FileSequence paths defined by the cross3d.FileSequence class. It does not support static images or movies. """ # If not plate is assigned the clip name will be and empty string. clipName = xsi.GetValue("%s.rotoscope.imagename" % self.name()) if clipName: clip = xsi.Dictionary.GetObject(clipName, False) path = clip.Source.FileName.Value match = re.match(cross3d.application.imageSequenceRegex(), path) if match: t = match.groupdict() fileSequence = FileSequence('%s%s-%s.%s' % (t['path'], t['start'], t['end'], t['extension'])) fileSequence.setPadding(int(t['padding'])) return fileSequence.path() # Fallback. return ''
def headlightIsActive(self): return xsi.GetValue(self.name() + '.camdisp.headlight')
def showsFrame(self): return xsi.GetValue(self.name() + '.camvis.currenttime')
def _nativeFocalLength(self): return xsi.GetValue(self.name() + '.camera.projplanedist')
def __enter__(self): self._undo = xsi.GetValue("preferences.General.undo") xsi.SetValue("preferences.General.undo", 0, "")
def setHeadlightIsActive(self): camera = self._nativeCamera() return xsi.GetValue(camera.FullName + '.camdisp.headlight')
def generatePlayblast(self, fileName, frameRange=None, resolution=None, slate=None, effects=True, geometryOnly=True, pathFormat=r'{basePath}\{fileName}.{frame}.{ext}'): """ Creates an unpadded JPG file sequence from the viewport for a given range. """ # Treating inputs. if isinstance(frameRange, int): frameRange = FrameRange([frameRange, frameRange]) # Checking frame range. initialFrameRange = self._scene.animationRange() if not frameRange: frameRange = initialFrameRange # Collecting data. nativeCamera = self._nativeCamera() def genImagePath(frame=None): basePath, fn = os.path.split(fileName) pf = pathFormat # Deal with xsi's special number padding format if frame == None: filen = '(fn)' ext = '(ext)' # Remove any number specific formatting so we can insert a simple # for each padding digit pf = re.sub(r'{frame:[^}]*', r'{frame', pf) padding = re.findall(r'{frame:(\d+)', pathFormat) if padding: frameNo = '#' * int(padding[0]) else: frameNo = '#' else: fileSplit = fn.split('.') filen = '.'.join(fileSplit[:-1]) ext = fileSplit[-1] frameNo = frame out = pf.format(basePath=basePath, fileName=filen, frame=frameNo, ext=ext) index = pathFormat.find('{ext}') if frame == None and index > 0 and pathFormat[index - 1] == '.': # strip out the file extension dot fileSplit = out.split('.') out = '.'.join(fileSplit[:-1]) + fileSplit[-1] return out firstFrameFileName = genImagePath(frameRange[0]) lastFrameFileName = genImagePath(frameRange[1]) try: firstFrameStartTime = os.path.getmtime(firstFrameFileName) lastFrameStartTime = os.path.getmtime(lastFrameFileName) except os.error: firstFrameStartTime = 0 lastFrameStartTime = 0 # Storing object states. self._scene.storeState() self.storeViewOptions() # Setting slate. if slate: self.setSlateText(slate) self.setSlateIsActive(True) xsi.SetValue(nativeCamera.FullName + '.camvis.currenttime', False) elif slate == None: xsi.SetValue(nativeCamera.FullName + '.camvis.currenttime', False) else: xsi.SetValue(nativeCamera.FullName + '.camvis.currenttime', True) # Setting regular visibility options. nativeCamera.Properties('Camera Visibility').Parameters( 'gridvis').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'gridaxisvis').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'constructionlevel').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objannotationobjects').Value = False xsi.SetValue('preferences.ViewCube.show', False) if geometryOnly: # Setting geometry only visibility options. nativeCamera.Properties('Camera Visibility').Parameters( 'objpolymesh').Value = True nativeCamera.Properties('Camera Visibility').Parameters( 'objparticles').Value = True nativeCamera.Properties('Camera Visibility').Parameters( 'objinstances').Value = True nativeCamera.Properties('Camera Visibility').Parameters( 'objlights').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objcameras').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objimpgeometry').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objcurves').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objhair').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objnulls').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrltransfogroups').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrlchnjnts').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrlchnroots').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrlchneff').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrllattices').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrltextsupp').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrlchnjnts').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrlwaves').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objctrlother').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'objenvironment').Value = False nativeCamera.Properties('Camera Visibility').Parameters( 'custominfo').Value = False # Checking resolution. if not resolution: resolution = QSize( xsi.GetValue("Passes.RenderOptions.ImageWidth"), xsi.GetValue("Passes.RenderOptions.ImageHeight")) # Setting the scene range. Apparently if you don't it causes an animation layer issue. if not initialFrameRange.contains(frameRange): self._scene.setAnimationRange(frameRange) # Set camera's picture ratio. camera = self.camera() if camera: pictureRatio = camera.pictureRatio() camera.setPictureRatio( float(resolution.width()) / resolution.height()) fps = self._scene.animationFPS() viewportCapture = xsi.Dictionary.GetObject( 'ViewportCapture').NestedObjects viewportCapture('File Name').Value = fileName viewportCapture('Padding').Value = os.path.basename(genImagePath()) viewportCapture('Width').Value = resolution.width() viewportCapture('Height').Value = resolution.height() viewportCapture('Scale Factor').Value = 1 viewportCapture('User Pixel Ratio').Value = True viewportCapture('Pixel Ratio').Value = 1 viewportCapture('Frame Rate').Value = fps viewportCapture('Write Alpha').Value = False viewportCapture('Record Audio Track').Value = False viewportCapture('Start Frame').Value = frameRange[0] viewportCapture('End Frame').Value = frameRange[1] viewportCapture('Launch Flipbook').Value = False viewportCapture('Use Native Movie Player').Value = False viewportCapture('Movie').Value = False viewportCapture('OpenGL Anti-Aliasing').Value = 16 if effects else 1 viewportCapture('Remember Last Sequence').Value = False letterToNumber = {"A": 1, "B": 2, "C": 3, "D": 4} xsi.CaptureViewport(letterToNumber[self.name], False) # Restoring states. self._scene.restoreViewOptions() self.restoreViewOptions() if camera: camera.setPictureRatio(pictureRatio) # If the famous capture Softimage bug happened we raise a specific error. try: firstFrameEndTime = os.path.getmtime(firstFrameFileName) if not firstFrameStartTime < firstFrameEndTime: raise Exceptions.OutputFailed( 'The playblast failed due to a native Softimage bug. Do not panic, the fix is easy. Open the regular capture window, change the format to anything. Close the window and try again.' ) except os.error: raise Exceptions.OutputFailed( 'The playblast failed due to a native Softimage bug. Do not panic, the fix is easy. Open the regular capture window, change the format to anything. Close the window and try again.' ) # If the capture was not completed we just return False. try: lastFrameEndTime = os.path.getmtime(lastFrameFileName) if not lastFrameStartTime < lastFrameEndTime: return False except os.error: return False return True