Red9_General¶
Red9 General is a module for general functions called and used throughout the codebase. This includes most of the context managers and decorators.
Note
Nothing inside this module should require any other part of Red9
Key functions
getCurrentFPS () |
returns the current frames per second as a number, rather than a useless string |
getModifier () |
return the modifier key pressed |
forceToString (text) |
simple function to ensure that data can be passed correctly into |
itersubclasses (cls) |
http://code.activestate.com/recipes/576949-find-all-subclasses-of-a-given-class/ |
inspectFunctionSource (value) |
This is a neat little wrapper over the mel “whatIs” and Pythons inspect module that finds the given functions source filePath, either Mel or Python and opens the original file in the default program. |
getScriptEditorSelection () |
this is a hack to bypass an issue with getting the data back from the |
thumbNailScreen (filepath, width, height[, mode]) |
|
thumbnailFromPlayBlast (filepath, width, height) |
Generate a ThumbNail of the screen |
thumbnailApiFromView (filename, width, height) |
grab the thumbnail direct from the buffer? |
os_OpenFileDirectory (path) |
open the given folder in the default OS browser |
os_OpenFile (filePath, *args) |
open the given file in the default program for this OS |
Context Managers / decorators
AnimationContext ([evalmanager, time, undo]) |
CONTEXT MANAGER : Simple Context Manager for restoring Animation settings |
undoContext ([initialUndo, undoFuncCache, ...]) |
CONTEXT MANAGER : Simple Context Manager for chunking the undoState |
ProgressBarContext ([maxValue, ...]) |
CONTEXT MANAGER : Context manager to make it easier to wrap progressBars |
HIKContext (NodeList) |
CONTEXT MANAGER : Simple Context Manager for restoring HIK Animation settings and managing HIK callbacks |
SceneRestoreContext () |
CONTEXT MANAGER : Simple Context Manager for restoring Scene Global settings |
Timer (func) |
DECORATOR : Simple timer function |
runProfile (func) |
DECORATOR : run the profiler - only ever used when debugging /optimizing |
-
getCurrentFPS
()¶ returns the current frames per second as a number, rather than a useless string
-
forceToString
(text)¶ simple function to ensure that data can be passed correctly into textFields for the UI (ensuring lists are converted)
-
formatPath
(path)¶ take a path and format it to forward slashes with catches for the exceptions
-
itersubclasses
(cls)¶ http://code.activestate.com/recipes/576949-find-all-subclasses-of-a-given-class/ Iterator to yield full inheritance from a given class, including subclasses. This is used in the MetaClass to build the RED9_META_REGISTERY inheritance dict
-
inspectFunctionSource
(value)¶ This is a neat little wrapper over the mel “whatIs” and Pythons inspect module that finds the given functions source filePath, either Mel or Python and opens the original file in the default program. Great for developers Supports all Mel functions, and Python Class / functions
-
getScriptEditorSelection
()¶ this is a hack to bypass an issue with getting the data back from the ScriptEditorHistory scroll. We need to copy the selected text to the clipboard then pull it back afterwards.
-
Timer
(func)¶ DECORATOR : Simple timer function
-
runProfile
(func)¶ DECORATOR : run the profiler - only ever used when debugging /optimizing function call speeds.visualize the data using ‘runsnakerun’ to view the profiles and debug
-
evalManager_DG
(func)¶ DECORATOR : simple decorator to call the evalManager_switch plugin and run the enclosed function in DG eval mode NOT parallel.
Note
Parallel EM mode is slow at evaluating time, DG is up to 3 times faster! The plugin call is registered back in the undoStack, cmds.evalmanager call is not
-
evalManagerState
(mode='off')¶ wrapper function for the evalManager so that it’s switching is recorded in the undo stack via the Red9.evalManager_switch plugin
-
class
AnimationContext
(evalmanager=True, time=True, undo=True)¶ Bases:
object
CONTEXT MANAGER : Simple Context Manager for restoring Animation settings
Parameters: - evalmanager – do we manage the evalManager in this context for Maya 2016 onwards
- time – do we manage the time and restore the original currentTime?
- undo – do we manage the undoStack, collecting everything in one chunk
-
class
undoContext
(initialUndo=False, undoFuncCache=[], undoDepth=1)¶ Bases:
object
CONTEXT MANAGER : Simple Context Manager for chunking the undoState
If initialUndo is True then the context manager will manage what to do on entry with the undoStack. The idea is that if True the code will look at the last functions in the undoQueue and if any of those mantch those in the undoFuncCache, it’ll undo them to the depth given. WHY?????? This is specifically designed for things like floatFliders where you’ve set a function to act on the ‘dc’ flag, (drag command) by passing that func through this each drag will only go into the stack once, enabling you to drag as much as you want and return to the initial state, pre ALL drags, in one chunk.
Parameters: - initialUndo – on first process whether undo on entry to the context manager
- undoFuncCache – only if initialUndo = True : functions to catch in the undo stack
- undoDepth – only if initialUndo = True : depth of the undo stack to go to
Note
When adding funcs to this you CAN’T call the ‘dc’ command on any slider with a lambda func, it has to call a specific func to catch in the undoStack. See Red9_AnimationUtils.FilterCurves code for a live example of this setup.
-
undoCall
()¶
-
class
ProgressBarContext
(maxValue=100, interruptable=True, step=1, ismain=True, title='')¶ Bases:
object
CONTEXT MANAGER : Context manager to make it easier to wrap progressBars
Parameters: - maxValue – max value used in the progress
- interruptable – if the progress is interruptable / escapable
- step – step used in the progress bar
- ismain – if we use the main progressBar OR a progressWindow to view the progress
- title – only valid if ismain=False, used as the progressUI window title
>>> #Example of using this in code >>> >>> progressBar=r9General.ProgressBarContext(maxValue=1000, step=1) >>> >>> #now do your code but increment and check the progress state >>> with progressBar: <<<<<<< HEAD >>> for i in range(1,1000,1): >>> if progressBar.isCancelled(): >>> print 'process cancelled' >>> break ======= >>> for i in range(1:1000): >>> if progressBar.isCanceled(): >>> print 'process cancelled' >>> return >>>>>>> d7ab8a039c4da0838a07bf4a9ec3ad957667b21e >>> progressBar.updateProgress()
-
isCanceled
()¶
-
setText
(text)¶
-
setMaxValue
(value)¶
-
setStep
(value)¶
-
setProgress
(value)¶
-
getProgress
()¶
-
updateProgress
()¶ more simplistic way to just update the progress. Previously we generate a counter and used that with the setProgress() call, this is a far better way to do it
-
reset
()¶
-
class
HIKContext
(NodeList)¶ Bases:
object
CONTEXT MANAGER : Simple Context Manager for restoring HIK Animation settings and managing HIK callbacks
-
class
SceneRestoreContext
¶ Bases:
object
CONTEXT MANAGER : Simple Context Manager for restoring Scene Global settings
Basically we store the state of all the modelPanels and timeLine setups. Think of it like this, you export a scene, file -new, then re-import it but you’ve now lost all the scenes UI and setups. This is capable of returning the UI to the previous state. Maybe this could be a tool in it’s own write?
- Things stored:
- All UI viewport states, display and settings
- currentTime, timeRanges, timeUnits, sceneUnits, upAxis
- Main cameras and transforms for the 4 main modelPanels
- active sound and sound displays
>>> from Red9.core.Red9_General import SceneRestoreContext as sceneStore >>> with sceneStore: >>> #do something to modify the scene setup >>> cmds.currentTime(100) >>> >>> #out of the context manager the scene will be restored as it was >>> #before the code entered the context. (with sceneStore:)
-
storeSettings
()¶ main work function, store all UI settings
-
restoreSettings
()¶ restore all UI settings
-
thumbNailScreen
(filepath, width, height, mode='api')¶
-
thumbnailFromPlayBlast
(filepath, width, height)¶ Generate a ThumbNail of the screen Note: ‘cf’ flag is broken in 2012 :param filepath: path to Thumbnail :param width: width of capture :param height: height of capture
-
thumbnailApiFromView
(filename, width, height, compression='bmp', modelPanel='modelPanel4')¶ grab the thumbnail direct from the buffer? TODO: not yet figured out how you crop the data here?
-
getModifier
()¶ return the modifier key pressed
-
class
Clipboard
¶ Get or Set data to the Windows clipboard...Used in the inspect code to grab the ScriptEditor’s selected history CURRENTLY NOT BEING CALLED - switched to pyperclip.py module
-
static
getText
()¶ Get clipboard text if available
-
static
setText
(value)¶ Set clipbard text
-
static
-
os_OpenFileDirectory
(path)¶ open the given folder in the default OS browser
-
os_OpenFile
(filePath, *args)¶ open the given file in the default program for this OS
-
os_formatPath
(path)¶ take the given path and format it for Maya path
-
os_listFiles
(folder, filters=[], byDate=False, fullPath=False)¶ simple os wrap to list a dir with filters for file type and sort byDate
Parameters: - folder – folder to dir list
- filters – list of file extensions to filter for
- byData – sort the list by modified date, newest first!
- fullPath – return either the fully matched path or just the files that match
-
os_openCrashFile
(openDir=False)¶ Open the default temp dir where Maya stores it’s crash files and logs
-
os_fileCompare
(file1, file2, openDiff=False)¶ Pass in 2 files for diffComparision. If files are identical, ie there are no differences then the code returns 0
Parameters: - file1 – first file to compare with second file
- file2 – second file to compare against the first
- openDiff – if a difference was found then boot Diffmerge UI, highlighting the diff
Note
This is a stub function that requires Diffmerge.exe, you can download from https://sourcegear.com/diffmerge/. Once downloaded drop it here Red9/pakcages/diffMerge.exe
-
writeJson
(filepath=None, content=None)¶ write json file to disk
Parameters: - filepath – file pat to drive where to write the file
- content – file content
Returns: None
-
readJson
(filepath=None)¶ file pat to drive where to read the file
Parameters: filepath – Returns: