OBJNames is the name of the object in the xref file i.e cone01
I’m a bit lost there - surely myNewObjs is the list of object names in the xref file?
I think you’re confusing objects and object names - they aren’t interchangable, and your “i” isn’t looping correctly - it will miss some shapes.
Note. I changed some of the variable names to more closely reflect their contents. Always a good idea to use names which give a clue as to what they contain because then you can see if they are of the correct type for the function you’re using. In this case, the instanceReplace requires 2 Nodes, not object Names.
In my test the files contain Box01, Box02, Sphere01, Sphere02.
The scene contained Box01_Shape, Box02_Shape, Box02_Shape01, Sphere01_Shape, Sphere02_Shape, Sphere02_Shape01.
(
xrefFileNames = #("xref_boxes.max", "xref_spheres.max")
for xrefFile in xrefFileNames do
(
xrefObjNames = getMAXFileObjectNames xrefFile
xrefs.addNewXRefObject xrefFile xrefObjNames modifiers: #merge manipulators: #merge
for i = 1 to xrefObjNames.count do
(
for obj in shapes where ((subString obj.name 1 xrefObjNames[i].count) == xrefObjNames[i]) do
( -- format "% % %\n" i obj.name xrefObjNames[i]
instanceReplace obj (getNodeByName xrefObjNames[i])
)
)
)
)
Now, the topic of this thread has something about preventing duplicates - I’ve not addressed that (yet) so you’ll have to explain exactly what you do and don’t want to happen.
Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|