从 MaxScript 中的对象列表创建一个数组并将它们添加到新层

Create an Array from list of objects in MaxScript and add them to a new layer

我是 Maxscript 的超级新手,想自动化一个过程,我一直在看一些教程,但我 运行 遇到了 selection 的问题。我想要做的是,我有一个字符串列表(我可能必须添加到)代表我想要 select(如果它们存在于该文件中)的 max 文件中的对象,然后添加到新图层。

例如:

/* I have a big long list of objects I want to mass select, this has to be hardcoded because its a similar list that exists in a ton of max files */
rObj1 = "testObj1"
rObj2 = "sampleObj2"
""
rObj99 = "newObj90"

/*I want to then add it to an array
removeList = #(rObj***)

/* Then run through each entry in the array to make sure it exists and then add it to my selection
for i in removeList do
    (
    if i != undefined then select (i)   
    )

/*Then Add what I have selected to a new layer

newLayer = LayerManager.newLayerFromName "removed_list"
for obj in selection do newLayer.addNode obj

当涉及到 selection 时,我总是收到错误消息,作为 Max 的新手,我不知道该怎么做。

您正在尝试 select 在您应该 select 创建(或添加到图层)一个对象的位置:

newLayer = LayerManager.newLayerFromName "removed_list"
for objName in removeList where isValidNode (getNodeByName objName) do
    newLayer.addNode (getNodeByName objName)