[英]How to get the list of root parents created in a scene - Autodesk Maya / Python?
[英]Maya Python: How do I get the scene name but not the path or extension
我只想获取当前打开的文件的场景名称。 不是路径或扩展名。
cmds.file(q=True, sn=True)
我不能使用上面的,因为它返回完整路径。
谢谢
os
模块包括用于此的实用程序:
filepath = cmds.file(q=True, sn=True)
filename = os.path.basename(filepath)
raw_name, extension = os.path.splitext(filename)
cmds.file(q=True, sn=True, shn=True)
theodox的答案是正确的答案(使用 Python 'os' 模块):
filepath = cmds.file(q=True, sn=True)
filename = os.path.basename(filepath)
raw_name, extension = os.path.splitext(filename)
您可以通过结合Serious Sam的答案(它给出带扩展名的文件名,但在单个指令中而不是在theodox的答案中使用 2 )来缩短它:
filename = cmds.file(q=True, sn=True, shn=True)
raw_name, extension = os.path.splitext(filename)
import os
# a= "Full File Path of the scene"
a= r"C:\Python36\Lib\site-packages\anytree\node\nodemixin.py"
print(os.path.split(a)[1].split('.')[0])
'节点混合'
print(os.path.splitext(a)[0].split('\\')[-1])
'节点混合'
在 Maya 中使用 Python 时,可以使用file
命令。 当您根据/
拆分它时,您将获得一个列表作为结果,然后您只需从后面 [-1] 开始计数。 这将为您提供字符串形式的当前 Maya 场景文件名。
cmds.file(q=True, sn=True).split('/')[-1]
这工作正常:
import maya.cmds as cmds
scene = cmds.file(q=True, sn=True)
scene = scene.split('/')[-1]
print(scene)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.