View Full Version : 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!
|
|
ZeBoxx2
02-04-2009, 12:23 AM
try something like...
dirName = "D:\3D\Turk_DWG_Out\maxfiles"
for f in (getFiles (dirName+"\\*")) do
(
xrefs.addNewXrefFile f
)
works perfectly, thanks ZeBoxx2!!
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\name\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??
ZeBoxx2
02-04-2009, 08:18 PM
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:\3D<tab>urk_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 )
Piflik
02-04-2009, 08:29 PM
Using '/' instead of '\' should also work.
CGTalk Moderation
02-04-2009, 08:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.