Maya 2017 自动选择或导出视口对象



我想批量选择所选列表中的对象,如何使用python进行操作?

  1. 在 3D 视口或大纲视图中使用鼠标选择某个对象。
  2. 从选定对象中获取列表。
  3. 并且我想将列出的项目中的批处理(逐个对象(导出为列出的对象中每个对象的不同文件。

当我使用我的脚本导出rsProxy(Redshift Proxy like OBJ(时,所选所有对象都导出到同一场景。但是我想从整体选定的对象中进行批处理。

哗啦啦。 F

我不知道 Redshift 的确切语法,但这里有一个关于如何在列表中逐个对象导出对象的一般示例。您最终会得到一堆文件,每个文件都只包含您在循环的每次迭代中选择的内容。

import pymel.core as pm
# get a list of the selected objects / nodes to export
export_objects = pm.ls(selection=True)
for obj in export_objects:
# generate unique filepath
filepath = "C:someexportpath{}.obj".format(obj.shortName())
# select just one of your objects for export
pm.select(obj, replace=True)
# use exportSelected for most filetypes 
# (or the redshift export command in your case)
pm.exportSelected(filepath)

以上可能回答了您的问题。

我要求ChatGPT做类似的事情。将所有选定的对象移动到 0,0,0,将每个文件导出为 .rs - 以防它在这里有用:

法典:

获取所选对象 字符串 $selectedObjects[] =ls -selection;

循环遍历每个选定对象 对于($object$selectedObjects( { 获取对象名称 字符串 $objectName =match "[^|]+$" $object;

// Move the object to the origin using setAttr
setAttr ($object + ".translate") 0 0 0;
// Construct the export path
string $exportPath = "C:/YourPath/" + $objectName + ".rs";
// Create a temporary group and parent the object under it
string $tempGroup = `group -em -n ($objectName + "_tempGroup")`;
parent $object $tempGroup;
// Export the temporary group as a Redshift proxy file
rsProxy -fp $exportPath -sl $tempGroup;
// Unparent the object from the temporary group
parent -w $object;
// Delete the temporary group
delete $tempGroup;
print("Exported " + $object + " as " + $exportPath + "n");

}

最新更新