def playblast_snapshot(path = None,format = None, compression = None, hud = None, offscreen = None, range=None, scale = None):
current_image_format = cmds.getAttr("defaultRenderGlobals.imageFormat")
cmds.setAttr("defaultRenderGlobals.imageFormat", 32) # *.png
if range is None:
range = playback_selection_range()
print range
if range is None:
start = cmds.playbackOptions( q=True,min=True )
end = cmds.playbackOptions( q=True,max=True )
range = [start, end]
cmds.playblast(frame =int((range[0] + range[1])/2), cf = path, fmt="image", orn=hud, os=offscreen, wh = scene_resolution(), p=scale, v=False)
cmds.setAttr("defaultRenderGlobals.imageFormat", current_image_format)
python类playbackOptions()的实例源码
def getValues(*args):
try:
obj = cmds.ls(sl=True, transforms = True)[0]
#currentFrame = cmds.currentTime(q = True)
step = cmds.intFieldGrp(widgets['stepIFG'], q = True, v1 = True)
frmVal = cmds.radioButtonGrp(widgets["frmRBG"], q=True, sl=True)
suffix = cmds.textFieldGrp(widgets["sufTFG"], q = True, tx = True)
name = "%s_%s"%(obj, suffix)
if frmVal == 1:
frameStart = int(cmds.playbackOptions(query=True, min=True))
frameEnd = int(cmds.playbackOptions(query=True, max=True))
else:
frameStart = cmds.intFieldGrp(widgets["frmRngIFG"], q = True, v1 = True)
frameEnd = cmds.intFieldGrp(widgets["frmRngIFG"], q = True, v2 = True)
makeSequence(obj, name, frameStart, frameEnd, step)
except:
cmds.warning("Select one object with a transform")
def frameRange(start=None, end=None):
'''
Returns the frame range based on the highlighted timeslider,
or otherwise the playback range.
'''
if not start and not end:
gPlayBackSlider = mm.eval('$temp=$gPlayBackSlider')
if mc.timeControl(gPlayBackSlider, query=True, rangeVisible=True):
frameRange = mc.timeControl(gPlayBackSlider, query=True, rangeArray=True)
start = frameRange[0]
end = frameRange[1]-1
else:
start = mc.playbackOptions(query=True, min=True)
end = mc.playbackOptions(query=True, max=True)
return start,end
def __init__(self, *args, **kwargs):
super(CreateAnimation, self).__init__(*args, **kwargs)
from maya import cmds
self.data.update({
"startFrame": lambda: cmds.playbackOptions(
query=True, animationStartTime=True),
"endFrame": lambda: cmds.playbackOptions(
query=True, animationEndTime=True),
})
def rewind():
cmds.currentTime(1)
cmds.playbackOptions(minTime=1)
def playblast(path = None,format = None, compression = None, hud = None, offscreen = None, range=None, scale = None):
if range is None:
range = playback_selection_range()
print range
if range is None:
start = cmds.playbackOptions( q=True,min=True )
end = cmds.playbackOptions( q=True,max=True )
range = [start, end]
cmds.playblast(startTime =range[0] ,endTime =range[1], f = path, fmt=format, orn=hud, os=offscreen, wh = scene_resolution(), p=scale, qlt=90,c=compression, v=True, s = qeury_active_sound_node())
def get_time_slider_range(highlighted=True,
withinHighlighted=True,
highlightedOnly=False):
"""Return the time range from Maya's time slider.
Arguments:
highlighted (bool): When True if will return a selected frame range
(if there's any selection of more than one frame!) otherwise it
will return min and max playback time.
withinHighlighted (bool): By default Maya returns the highlighted range
end as a plus one value. When this is True this will be fixed by
removing one from the last number.
Returns:
list: List of two floats of start and end frame numbers.
"""
if highlighted is True:
gPlaybackSlider = mel.eval("global string $gPlayBackSlider; "
"$gPlayBackSlider = $gPlayBackSlider;")
if cmds.timeControl(gPlaybackSlider, query=True, rangeVisible=True):
highlightedRange = cmds.timeControl(gPlaybackSlider,
query=True,
rangeArray=True)
if withinHighlighted:
highlightedRange[-1] -= 1
return highlightedRange
if not highlightedOnly:
return [cmds.playbackOptions(query=True, minTime=True),
cmds.playbackOptions(query=True, maxTime=True)]
def export_alembic(nodes, file, frame_range=None, uv_write=True):
"""Wrap native MEL command with limited set of arguments
Arguments:
nodes (list): Long names of nodes to cache
file (str): Absolute path to output destination
frame_range (tuple, optional): Start- and end-frame of cache,
default to current animation range.
uv_write (bool, optional): Whether or not to include UVs,
default to True
"""
options = [
("file", file),
("frameRange", "%s %s" % frame_range),
] + [("root", mesh) for mesh in nodes]
if uv_write:
options.append(("uvWrite", ""))
if frame_range is None:
frame_range = (
cmds.playbackOptions(query=True, ast=True),
cmds.playbackOptions(query=True, aet=True)
)
# Generate MEL command
mel_args = list()
for key, value in options:
mel_args.append("-{0} {1}".format(key, value))
mel_args_string = " ".join(mel_args)
mel_cmd = "AbcExport -j \"{0}\"".format(mel_args_string)
return mel.eval(mel_cmd)
def process(self, instance):
import os
from maya import cmds
from pyblish_starter import api, maya
self.log.debug("Loading plug-in..")
cmds.loadPlugin("AbcExport.mll", quiet=True)
self.log.info("Extracting animation..")
dirname = api.format_staging_dir(
root=instance.context.data["workspaceDir"],
name=instance.data["name"])
try:
os.makedirs(dirname)
except OSError:
pass
filename = "{name}.abc".format(**instance.data)
maya.export_alembic(
nodes=instance,
file=os.path.join(dirname, filename).replace("\\", "/"),
frame_range=(cmds.playbackOptions(query=True, ast=True),
cmds.playbackOptions(query=True, aet=True)),
uv_write=True
)
# Store reference for integration
if "files" not in instance.data:
instance.data["files"] = list()
instance.data["files"].append(filename)
instance.data["stagingDir"] = dirname
self.log.info("Extracted {instance} to {dirname}".format(**locals()))
def createMush(self):
mesh = self.sourceField.text()
if not mesh:
return
if cmds.objExists(mesh + '_Mush'):
print(mesh + '_Mush already exists!')
return
cmds.currentTime(cmds.playbackOptions(q=True, min=True))
dup = cmds.duplicate(mesh, inputConnections=True, n=mesh + '_Mush')
cmds.deltaMush(dup, smoothingIterations=20, smoothingStep=0.5, pinBorderVertices=True, envelope=1)
def getSliderRange(self, *args):
"""gets framerange in current scene and returns start and end frames"""
#get timeslider range start
self.startF = cmds.playbackOptions(query=True, min=True)
self.endF = cmds.playbackOptions(query=True, max=True)
def zbw_swapRotateOrder():
#find frame range from slider
startF = cmds.playbackOptions (query=True, minTime=True)
endF = cmds.playbackOptions (query=True, maxTime=True)
objs = cmds.ls (selection=True)
#dummy check for two objects!
objA = objs[0]
objB = objs[1]
#get list of keys to use
keysAtFull = cmds.keyframe (objA, query=True, time=(startF,endF), attribute=('tx','ty','tz','rx','ry','rz'))
keysSet = set(keysAtFull)
keyList=[]
for key in keysSet:
keyList.append(key)
keyList.sort()
#print keyList
for thisKey in keyList: #populate the dictionary with the key values
cmds.currentTime(thisKey) #set currentTime to the value
cmds.pointConstraint(objA, objB, name="pointConst")#pointConstriain B to A
cmds.orientConstraint(objA, objB, name="orientConst")#orientConstan B to A
getRot() #getData() for B and puts it in keyBuffer
getTrans() #gets tranlslation data for same
cmds.delete('pointConst','orientConst') # delete the constaints on B
#since I can't add the keys while I"m constraining, do it now from dictionary
for newKey in keyList:
objRot = rotBuffer[newKey]
objTrans = transBuffer[newKey]
cmds.setKeyframe( objB, t=newKey,at='tx', v=objTrans[0]) #set keys for B on all the frames in keyBuffer to values in keyBuffer
cmds.setKeyframe( objB,t=newKey,at='ty', v=objTrans[1])
cmds.setKeyframe( objB,t=newKey,at='tz', v=objTrans[2])
cmds.setKeyframe( objB,t=newKey,at='rx', v=objRot[0])
cmds.setKeyframe( objB,t=newKey,at='ry', v=objRot[1])
cmds.setKeyframe( objB,t=newKey,at='rz', v=objRot[2])
cmds.filterCurve((objB+'_rotateX'), (objB+'_rotateY'), (objB+'_rotateZ' )) #run Euler filter on curves for rotation?
def zbw_getFrameRange():
"""gets framerange in current scene and returns start and end frames"""
#get timeslider range start
startF = cmds.playbackOptions(query=True, min=True)
endF = cmds.playbackOptions(query=True, max=True)
return(startF, endF)
#step key all
def zbw_stepAll():
sel = cmds.ls(sl=True)
keyList = []
keySet = set()
allKeys = []
#get timeslider range start
startF = cmds.playbackOptions(query=True, min=True)
#get end frame
endF = cmds.playbackOptions(query=True, max=True)
#get all the keyed frames
for this in sel:
keyList = cmds.keyframe(this, query=True, time=(startF,endF))
for key in keyList:
key = int(key)
keySet.add(key)
#print keyList
keySet = set(keyList)
for frame in keySet:
allKeys.append(frame)
allKeys.sort()
allKeys.reverse()
#print allKeys
for object in sel:
for thisKey in allKeys:
cmds.currentTime(thisKey)
cmds.setKeyframe(object, t=thisKey, ott="step")
#pull down anim from master
def getSliderRange(*args):
"""gets framerange in current scene and returns start and end frames"""
# get timeslider range start
startF = cmds.playbackOptions(query=True, min=True)
endF = cmds.playbackOptions(query=True, max=True)
return (startF, endF)
def getSliderRange(*args):
"""gets framerange in current scene and returns start and end frames"""
# get timeslider range start
startF = cmds.playbackOptions(query=True, min=True)
endF = cmds.playbackOptions(query=True, max=True)
return(startF, endF)
def getRange(*args):
sl = cmds.radioButtonGrp(widgets["rangeRBG"], q=True, sl=True)
if sl==1:
startF = cmds.playbackOptions (query=True, minTime=True)
endF = cmds.playbackOptions (query=True, maxTime=True)
else:
startF = cmds.intFieldGrp(widgets["frameRangeIFG"], q=True, v1=True)
endF = cmds.intFieldGrp(widgets["frameRangeIFG"], q=True, v2=True)
return(int(startF), int(endF))
def getSliderRange(*args):
"""gets framerange in current scene and returns start and end frames"""
#get timeslider range start
startF = cmds.playbackOptions(query=True, min=True)
endF = cmds.playbackOptions(query=True, max=True)
return(startF, endF)
def getSliderRange(*args):
"""gets framerange in current scene and returns start and end frames"""
# get timeslider range start
startF = cmds.playbackOptions(query=True, min=True)
endF = cmds.playbackOptions(query=True, max=True)
return (startF, endF)
def reset_frame_range():
"""Set frame range to current asset"""
shot = api.Session["AVALON_ASSET"]
shot = io.find_one({"name": shot, "type": "asset"})
try:
edit_in = shot["data"]["edit_in"]
edit_out = shot["data"]["edit_out"]
except KeyError:
cmds.warning("No edit information found for %s" % shot["name"])
return
fps = {
"12": "12fps",
"15": "game",
"16": "16fps",
"24": "film",
"25": "pal",
"30": "ntsc",
"48": "show",
"50": "palf",
"60": "ntscf"
}.get(api.Session.get("AVALON_FPS"), "pal") # Default to "pal"
cmds.currentUnit(time=fps)
cmds.playbackOptions(minTime=edit_in)
cmds.playbackOptions(maxTime=edit_out)
cmds.playbackOptions(animationStartTime=edit_in)
cmds.playbackOptions(animationEndTime=edit_out)
cmds.playbackOptions(minTime=edit_in)
cmds.playbackOptions(maxTime=edit_out)
cmds.currentTime(edit_in)
validate_project_editorial_info.py 文件源码
项目:config
作者: mindbender-studio
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def process(self, context):
from maya import cmds
scene_in = cmds.playbackOptions(query=True, animationStartTime=True)
scene_out = cmds.playbackOptions(query=True, animationEndTime=True)
scene_fps = {
"12fps": 12,
"game": 15,
"16fps": 16,
"film": 24,
"pal": 25,
"ntsc": 30,
"show": 48,
"palf": 50,
"ntscf": 60}.get(cmds.currentUnit(query=True, time=True))
if scene_fps is None:
scene_fps = "a strange "
env = context.data.get("environment", dict())
valid_fps = env.get("avalonFps")
valid_edit_in = env.get("avalonEditIn")
valid_edit_out = env.get("avalonEditOut")
skip_on_none = [valid_fps, valid_edit_in, valid_edit_out]
if None in skip_on_none:
self.log.debug(" environment not set")
return
assert int(valid_fps) == int(scene_fps), (
"The FPS is set to %sfps and not to %sfps"
% (scene_fps, valid_fps))
assert int(scene_in) == int(valid_edit_in), (
"Animation Start is set to %s and not set to \"%s\""
% (scene_in, valid_edit_in))
assert int(scene_out) == int(valid_edit_out), (
"Animation End is set to %s and not set to \"%s\""
% (scene_out, valid_edit_out))
def export_alembic(nodes,
file,
frame_range=None,
write_uv=True,
write_visibility=True,
attribute_prefix=None):
"""Wrap native MEL command with limited set of arguments
Arguments:
nodes (list): Long names of nodes to cache
file (str): Absolute path to output destination
frame_range (tuple, optional): Start- and end-frame of cache,
default to current animation range.
uv_write (bool, optional): Whether or not to include UVs,
default to True
attribute_prefix (str, optional): Include all user-defined
attributes with this prefix.
"""
if frame_range is None:
frame_range = (
cmds.playbackOptions(query=True, ast=True),
cmds.playbackOptions(query=True, aet=True)
)
options = [
("file", file),
("frameRange", "%s %s" % frame_range),
] + [("root", mesh) for mesh in nodes]
if isinstance(attribute_prefix, basestring):
# Include all attributes prefixed with "mb"
# TODO(marcus): This would be a good candidate for
# external registration, so that the developer
# doesn't have to edit this function to modify
# the behavior of Alembic export.
options.append(("attrPrefix", str(attribute_prefix)))
if write_uv:
options.append(("uvWrite", ""))
if write_visibility:
options.append(("writeVisibility", ""))
# Generate MEL command
mel_args = list()
for key, value in options:
mel_args.append("-{0} {1}".format(key, value))
mel_args_string = " ".join(mel_args)
mel_cmd = "AbcExport -j \"{0}\"".format(mel_args_string)
# For debuggability, put the string passed to MEL in the Script editor.
print("mel.eval('%s')" % mel_cmd)
return mel.eval(mel_cmd)
def prepare_scene(path):
"""
The function sets the basic parameters of the scene: time range and render settings.
:param path: string - The directory with necessary files
"""
cmds.playbackOptions(min=0, max=260) # Set the animation range
cmds.autoKeyframe(state=False) # Make sure, that the AutoKey button is disabled
plugins_dirs = mel.getenv("MAYA_PLUG_IN_PATH") # Mental Ray plugin is necessaryfor this script to run propperly.
# Next lines check if the plugin is avaible and installs it or displays an allert window.
# The plugins are accualy files placed in "MAYA_PLUG_IN_PATH" directories, so this script gets those paths
# and checks if there is a mental ray plugin file.
for plugins_dir in plugins_dirs.split(';'):
for filename in glob.glob(plugins_dir + '/*'): # For every filename in every directory of MAYA_PLUG_IN_PATH
if 'Mayatomr.mll' in filename: # if there is a mental ray plugin file then make sure it is loaded
if not cmds.pluginInfo('Mayatomr', query=True, loaded=True):
cmds.loadPlugin('Mayatomr', quiet=True)
cmds.setAttr('defaultRenderGlobals.ren', 'mentalRay', type='string') # Set the render engine to MR
# Next lines are a workaround for some bugs. The first one is that the render settings window has to be
# opened before setting attributes of the render. If it would not be, thhen Maya would display an error
# saying that such options do not exist.
# The second bug is that after running this scrpt the window was blank and it was impossible to set
# parameters. This is a common bug and it can be repaired by closing this window with
# cmds.deleteUI('unifiedRenderGlobalsWindow') command
cmds.RenderGlobalsWindow()
cmds.refresh(f=True)
cmds.deleteUI('unifiedRenderGlobalsWindow')
cmds.setAttr('miDefaultOptions.finalGather', 1)
cmds.setAttr('miDefaultOptions.miSamplesQualityR', 1)
cmds.setAttr('miDefaultOptions.lightImportanceSamplingQuality', 2)
cmds.setAttr('miDefaultOptions.finalGather', 1)
break
else:
continue
break
else:
print("Mental Ray plugin is not avaible. It can be found on the Autodesk website: ",
"https://knowledge.autodesk.com/support/maya/downloads/caas/downloads/content/",
"mental-ray-plugin-for-maya-2016.html")
alert_box = QtGui.QMessageBox()
alert_box.setText("Mental Ray plugin is not avaible. It can be found on the Autodesk website: " +
"https://knowledge.autodesk.com/support/maya/downloads/caas/downloads/content/" +
"mental-ray-plugin-for-maya-2016.html")
alert_box.exec_()
cam = cmds.camera(name="RenderCamera", focusDistance=35, position=[-224.354, 79.508, 3.569],
rotation=[-19.999,-90,0]) # create camera to set background (imageplane)
# Set Image Plane for camera background
cmds.imagePlane(camera=cmds.ls(cam)[1], fileName=(path.replace("\\", "/") + '/bg.bmp'))
cmds.setAttr("imagePlaneShape1.depth", 400)
cmds.setAttr("imagePlaneShape1.fit", 4)