有没有办法在Maya的参考编辑器中自动更改未解析的名称?



我不确定这是否是一个初学者的问题,但我一直在网上搜索,似乎没有什么能解决我的问题。

我正在从事一个项目,该项目需要将场景中引用对象的unresolved name更改为相对名称的形式。假设我在场景所在的同一文件夹中有一个球体,并且我将该球体引用到场景中,那么当我打开引用编辑器时,该球体的"未解析名称"可能类似于pathtothesphere。我只需要将其更改为sphere,现在我正在手动执行。有没有一种方法可以通过Python实现这一过程的自动化?

我以前处理过编辑纹理的路径,但这很容易,因为我可以使用fileTextureName属性来更改路径并直接设置路径。如果参考节点有类似的属性,那就太好了

我预计unresolved name的结果将是从类似pathtotheref到仅ref

这是我前一段时间制定的一种方法,用于将与我们的快照一起传播的ABC文件重新路由到相对路径,因此即使推送到内部资产服务器,它们也会解析。

你的问题有点模糊,但如果你仔细看下面的方法,忽略你不想要的任何检查,并且明显地重写以处理.mb或你正在使用的任何东西,我认为你可以让它做你需要的事情。

请忽略不需要的正在使用的模块,如consoleLogconfig

def repathAlembicsRelative():
'''Repath all alembics in scene, residing in subfolder MISC, to a relative path'''
out = classes.output()
out.warnings = []
consoleLog('Repathing Alembic caches (sims, etc. Not assets)...')
localFile = cmds.file(query=True, l=True)[0]
localFolder = os.path.dirname(localFile).replace('\', '/')
for obj in cmds.ls(type='reference'):
try:
filename = cmds.referenceQuery(obj, filename=True, withoutCopyNumber=True)
filename = filename.replace('\', '/').replace('//', '/')
base = os.path.basename(filename)
dir = os.path.dirname(filename)
# Ref is NOT alembic
if not filename.lower().endswith(config.EXTENSIONS[config.KEY_ALEMBIC]):
consoleLog('Reference {} is NOT an alembic file. Skipping'.format(obj))
continue
# Ref is already on ASSETDIR
if filename.startswith(config.ASSETDIR):
consoleLog('Reference {} resides on ASSETDIR ({}). Skipping'.format(obj, config.ASSETDIR))
continue
# Ref is NOT in subfolder MISC
miscPath = '{}/{}'.format(localFolder, config.KEY_MISC)
miscPathFull = '{}/{}'.format(miscPath, base)
if not filename == miscPathFull:
consoleLog('Reference {} is local, but NOT in the MISC folder. Collecting file before repathing'.format(obj))
try:
if not os.path.isdir(miscPath):
os.makedirs(miscPath)
shutil.copy(filename, miscPathFull)
consoleLog('Copied file {} to {}'.format(filename, miscPathFull))
except Exception as ex:
warning = 'Unable to collect file {}: {}'.format(filename, ex)
consoleLog(warning)
out.warnings.append(warning)
continue
# Failsafe
if not os.path.isfile(miscPathFull):
warning = 'File {} passed all checks, but somehow the file does not exist. This is not good.'.format(miscPathFull)
consoleLog(warning)
out.warnings.append(warning)
continue
# Skip repath if the UNRESOLVED path is already the same as what we're intending to set it to
relPath = '{}/{}'.format(config.KEY_MISC, base)
try:
unresolved = cmds.referenceQuery(obj, filename=True, unresolvedName=True)
if unresolved == relPath:
consoleLog('Unresolved filename for {} ({}) is already correct. Skipping'.format(obj, unresolved))
continue
except Exception as ex:
consoleLog('Unable to read unresolved filename for {}. Proceeding with pathmapping'.format(obj))
# Passed all checks, repath to relative
consoleLog('Repathing {} to {}'.format(filename, relPath))
cmds.file(relPath, loadReference=obj, type='Alembic', options='v=0')
except Exception as e:
consoleLog('Unable to process reference node {}: {}'.format(obj, e))
continue
out.success = True # This method is always successful, but may produce warnings
consoleLog('Done!')
return out

非常感谢@itypewithmyhands!!!我不知道我们可以使用maya-file命令直接从相对路径加载(或重新加载(引用。所以我想出了一个简单的解决方案(我之前在上面的代码中发现的所有异常(

for i in sel:
charRefPath = cmds.referenceQuery(i, filename = 1)
#REPATH UNRESOLVED REFERENCE NAME WITH RELATIVE NAME
refNode = cmds.referenceQuery(i, referenceNode = True)
relPath = charRefPath.split('/')[-1]
cmds.file(relPath, loadReference = refNode)

最新更新