本文整理匯總了Python中maya.cmds.file方法的典型用法代碼示例。如果您正苦於以下問題:Python cmds.file方法的具體用法?Python cmds.file怎麽用?Python cmds.file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.cmds
的用法示例。
在下文中一共展示了cmds.file方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lock
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def lock():
"""Lock scene
Add an invisible node to your Maya scene with the name of the
current file, indicating that this file is "locked" and cannot
be modified any further.
"""
if not cmds.objExists("lock"):
with lib.maintained_selection():
cmds.createNode("objectSet", name="lock")
cmds.addAttr("lock", ln="basename", dataType="string")
# Permanently hide from outliner
cmds.setAttr("lock.verticesOnlySet", True)
fname = cmds.file(query=True, sceneName=True)
basename = os.path.basename(fname)
cmds.setAttr("lock.basename", basename, type="string")
示例2: maintained_selection
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def maintained_selection():
"""Maintain selection during context
Example:
>>> scene = cmds.file(new=True, force=True)
>>> node = cmds.createNode("transform", name="Test")
>>> cmds.select("persp")
>>> with maintained_selection():
... cmds.select("Test", replace=True)
>>> "Test" in cmds.ls(selection=True)
False
"""
previous_selection = cmds.ls(selection=True)
try:
yield
finally:
if previous_selection:
cmds.select(previous_selection,
replace=True,
noExpand=True)
else:
cmds.select(clear=True)
示例3: setUp
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def setUp(self):
# create new scene & load plugin
cmds.file(new=True, f=True)
plugin = 'spore'
self.load_plugin('spore')
# setup a simple scene
plane = cmds.polyPlane()
cone = cmds.polyCone()
cmds.select(plane[0], cone[0])
spore = cmds.spore()
# get new instance data object and connect it to the current node
self.node = node_utils.get_mobject_from_name(spore[0])
self.instance_data = instance_data.InstanceData(self.node)
self.instance_data.initialize_data()
示例4: setUp
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def setUp(self):
# create new scene & load plugin
cmds.file(new=True, f=True)
plugin = 'spore'
self.load_plugin('spore')
# setup a simple scene
plane = cmds.polyPlane(sx=10, sy=10, w=10, h=10)
# cone = cmds.polyCone()
# cmds.select(plane[0], cone[0])
# spore = cmds.spore()
# get new instance data object and connect it to the current node
# self.node = node_utils.get_mobject_from_name(spore[0])
self.plane = node_utils.get_dagpath_from_name(plane[0])
self.geo_cache = geo_cache.GeoCache()
示例5: runPB
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def runPB(quality, sequence, autoReview):
#Get the file unix path of the maya file
filePath = cmds.file(q=True, sceneName=True)
#Parse the unix path and convert it into a dpa fspattern
if quality < 50:
print "Lower than 50 percent quality may result in very poor imaging..."
cmds.deleteUI("PBQuality")
return
print "Percentage chosen: " + str(quality)
print "From Sequence: " + str(sequence)
print "AutoSubmit: " + str(autoReview)
#Attempts to create a playblast of the current maya scene
success = playblaster(quality, sequence, autoReview)
if success:
print "Successfully generated playblast :)"
else:
print "Failed to generate playblast :("
示例6: maya_import
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def maya_import():
temp = __name__.split('.')#nameは自分自身のモジュール名。splitでピリオドごとに3分割。
folderPath = os.path.join(os.getenv('MAYA_APP_DIR'),'Scripting_Files','go')
if not os.path.exists(folderPath):
os.makedirs(os.path.dirname(folderPath+'\\')) # 末尾\\が必要なので注意
#print folderPath
files = os.listdir(folderPath)
if files is not None:
for file in files:
print file
nameSpace = file.replace('.ma', '')
cmds.file(folderPath+'\\'+file, i=True, typ="mayaAscii", iv=True, mnc=False, options="v=0;", pr=True)
#重複マテリアルにファイル名が頭に付與されてしまうのを修正
allMat = cmds.ls(mat=True)
fileName = file.split('.')[0]
for mat in allMat:
if mat.startswith(fileName+'_'):
cmds.rename(mat, mat.replace(fileName+'_', ''))
cmds.inViewMessage( amg='<hl>Go Maya</hl> : Imoprt objects', pos='midCenterTop', fade=True, ta=0.75, a=0.5)
else:
cmds.inViewMessage( amg='<hl>Go Maya</hl> : There is no exported object', pos='midCenterTop', fade=True, ta=0.75, a=0.5)
示例7: check_open
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def check_open():
current_project = cmds.workspace(q=True, rootDirectory=True)
scene_path = cmds.file(q=True, sceneName=True)
scene_name = cmds.file(q=True, shortName=True, sceneName=True)
msg01 = lang.Lang(
en='Workspace not found',
ja=u'ワークスペースがみつかりません')
dir_list = scene_path.split('/')
for i in range(len(dir_list)):
dir_list = dir_list[:-1]
root_dir = '/'.join(dir_list)+'/'
try:
all_files = os.listdir(root_dir)
except:
cmds.inViewMessage( amg=msg01.output(), pos='midCenterTop', fade=True, ta=0.75, a=0.5)
return
for file in all_files:
if file == 'workspace.mel':
set_work_space(root_dir)
return
cmds.inViewMessage( amg=msg01.output(), pos='midCenterTop', fade=True, ta=0.75, a=0.5)
示例8: source_nodes
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def source_nodes():
cmds.file(new=True, force=True)
source1, _ = pm.polyCube(name="source1")
source2, _ = pm.polyCube(name="source2")
target, _ = pm.polyCube(name="target")
ch1 = att.addAttribute(source1,
"chanName",
"double",
0,
minValue=0,
maxValue=1)
ch2 = att.addAttribute(source2,
"chanName",
"double",
0,
minValue=0,
maxValue=1)
pm.connectAttr(ch1, source1.ty)
pm.connectAttr(ch2, source2.ty)
示例9: repath
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def repath(node, file, project_path):
matches = []
for root, dirnames, filenames in os.walk(project_path):
for x in filenames:
if x == file:
matches.append([root,os.path.join(root, x)])
elif x.split(".")[0] == file.split(".")[0]: #---> this second option is used when a file is useing ##### padding, we can match by name only
x_ext = x.split(".")[len(x.split("."))-1]
file_ext = file.split(".")[len(file.split("."))-1]
if x_ext == file_ext:
matches.append([root,os.path.join(root, x)])
if len(matches)>0:
return cmds.filePathEditor(node, repath=matches[0][0])
return None
示例10: _createResolutionComboBox
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def _createResolutionComboBox(self):
userProps = cross3d.UserProps(self._nativePointer)
# Local models have a resolution metadata.
# Maybe it's not a good idea.
if resolutionAttr in userProps:
del userProps[resolutionAttr]
resolutions = ':'.join(userProps.get('resolutions', []))
# Object should support referencing, but referencing hasn't been setup, so create the structure.
cmds.addAttr(self._nativeName(), longName=resolutionAttr, attributeType="enum", enumName=resolutions)
# Make the attribute viewable, but not keyable in the channelBox
try:
cmds.setAttr(self._attrName(), keyable=False, channelBox=True)
# Consume a runtime error if the resolution attribute was in the reference. This is only a
# issue with some of our first models, Asset Exporter will remove them from future exports.
except RuntimeError as error:
pattern = r"setAttr: The attribute '[^']+' is from a referenced file, thus the keyable state cannot be changed."
if not re.match(pattern, error.message):
raise
示例11: loadUiType
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def loadUiType(uiFile):
"""
Pyside lacks the "loadUiType" command, so we have to convert the ui file to py code in-memory first
and then execute it in a special frame to retrieve the form_class.
http://tech-artists.org/forum/showthread.php?3035-PySide-in-Maya-2013 (ChrisE)
"""
parsed = xml.parse(uiFile)
widget_class = parsed.find('widget').get('class')
form_class = parsed.find('class').text
with open(uiFile, 'r') as f:
o = StringIO()
frame = {}
pysideuic.compileUi(f, o, indent=0)
pyc = compile(o.getvalue(), '<string>', 'exec')
exec pyc in frame
#Fetch the base_class and form class based on their type in the xml from designer
form_class = frame['Ui_%s'%form_class]
base_class = eval('QtWidgets.%s'%widget_class)
return form_class, base_class
示例12: getP4Location
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def getP4Location(self, asset, root='//depot/ArtSource/', debug=1):
from p4python.P4 import P4, P4Exception
if asset:
p4 = P4()
try: p4.connect()
except:
print 'Cannot connect to P4!'
return False
try:
file = p4.run_files(root + '...' + asset)
depotLoc = file[0]['depotFile']
describe = p4.run_describe(file[0]['change'])
return [describe[0]['user'], depotLoc, describe[0]['desc'], file[0]['change']]
except Exception as e:
print "findFileP4>>>> Cannot find file.", asset
if debug: print e
return False
finally:
p4.disconnect()
示例13: missingNodes
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def missingNodes(self):
fileNodes = cmds.ls(type='file')
missingFiles = {}
for f in fileNodes:
filePath = cmds.getAttr(f + '.fileTextureName')
if filePath != '':
if not cmds.file(filePath, exists=1, q=1):
fileName = filePath.split('/')[-1]
path = filePath.replace(fileName,'')
missingFiles[fileName] = {'path':path, 'node':f}
return missingFiles
## SANITY CHECK
########################################################################
#general methods
示例14: test_nodereuse
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def test_nodereuse():
"""Node re-use works ok"""
import cmdx
nodeA = cmdx.createNode("transform", name="myNode")
nodeB = cmdx.createNode("transform", parent=nodeA)
assert_is(cmdx.encode("|myNode"), nodeA)
assert_is(nodeB.parent(), nodeA)
with tempdir() as tmp:
fname = os.path.join(tmp, "myScene.ma")
cmds.file(rename=fname)
cmds.file(save=True, type="mayaAscii")
cmds.file(fname, open=True, force=True)
# On scene open, the current scene is closed, triggering
# the nodeDestroyed callback which invalidates the node
# for cmdx. Upon encoding this node anew, cmdx will
# allocate a new instance for it.
assert_is_not(cmdx.encode("|myNode"), nodeA)
示例15: test_nodereuse_noexist
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import file [as 別名]
def test_nodereuse_noexist():
"""Node re-use works on non-existent nodes"""
nodeA = cmdx.createNode("transform", name="myNode")
nodeB = cmdx.createNode("transform", parent=nodeA)
assert_is(cmdx.encode("|myNode"), nodeA)
assert_is(nodeB.parent(), nodeA)
cmds.file(new=True, force=True)
# Even if it's available for re-use, it will still throw
# a cmdx.ExistError on account of trying to fetch an MObject
# from a non-existing node.
assert_raises(cmdx.ExistError, cmdx.encode, "|myNode")
# Any operation on a deleted node raises RuntimeError
assert_raises(RuntimeError, lambda: nodeA.name())