[Closed] Loop through files in folder, add xrefs
Hello, as the thread title states I am trying to loop through a folder on the D drive and add the files in that folder as Xrefs. Probably pretty simple but alas, I struggle nonetheless.
what I am after is…
for each file in folder
add xrefs
dirName = "D:\3D\Turk_DWG_Out\maxfiles"
for i = 1 to dirName.files.count do
(
New_Object = xrefs.addNewXrefFile i
)
this is most certainly wrong. Can anyone point me in the right direction?
Thanks!
try something like…
dirName = "D:\3D\Turk_DWG_Out\maxfiles"
for f in (getFiles (dirName+"\\*")) do
(
xrefs.addNewXrefFile f
)
OK now I am trying to save the file after importing all the xrefs. Again this should be simple but the methods I have tried aren’t working. They are…
dirName = "D:\3D\Turk_DWG_Out"
myPrefix="s20"
for f in (getFiles (dirName+"\\" + myPrefix + "*")) do
(
xrefs.addNewXrefFile f
)
theOuputFile = dirName+"\\" + myPrefix + "_Master.max"
saveMaxFile theOutputFile
or even
dirName = "D:\3D\Turk_DWG_Out"
myPrefix="s20"
for f in (getFiles (dirName+"\\" + myPrefix + "*")) do
(
xrefs.addNewXrefFile f
)
--theOuputFile = dirName+"\\" + myPrefix + "_Master.max"
saveMaxFile "myMaster.max"
this is the message out of the listener
"D:\3D\Turk_DWG_Out"
"s20"
OK
"D:\3D\Turk_DWG_Out\s20_Master"
-- Error occurred in anonymous codeblock; filename: D:\Documents and Settings
ame\My Documents\3dsmax\scripts\AddXrefs.ms; position: 0
-- Unable to convert: undefined to type: FileName
which looks like it’s trying to save the script file? yarg…
What am I doing wrong??
would help to know what line it highlights when it gives that error, but…
one thing to look out for is this:
dirName = "D:\3D\Turk_DWG_Out"
Always use double-backslashes when specifying filenames and the like, as the backslash is a string escape character in MaxScript strings. Right now that reads… “D:\3Durk_DWG_Out”.
So use…
dirName = "D:\\3D\\Turk_DWG_Out"
( there’s also the @“etc.” method added in later max versions, but not everything plays nice with that – wish I could remember what, exactly, didn’t )