PDA

View Full Version : Dumb issue with array full of path names


joconnell
11-23-2010, 11:13 AM
Heya folks,

I'm getting an idiotic error with a simple script that creates a set of uniformly named folders in a set of directories. I've got an array of folder names and I'm using the new @ symbol so that things like \t aren't being picked up as a variable for tab but I'm finding that when I now wrap a ui around it all, the array is giving me an error. If I comment out the array it works fine and if I remove the ui entirely it also gives me the result I want - am I doing something dumb with the @ symbol or is there something else daft going on here? Ideally it'd be great to keep the @ Usage so I could later on add in the ability to edit the folder list using the format you'd copy and paste the location from windows explorer.

Cheers for any help - I'm sure it's a dumb one, just getting back into scripting after a few years!

Rollout ss_make_folders "SS Make Shot Folders"

(

--Screenscene make folders 01

global theSeasonNum = undefined
global theEpisodeNum = undefined
global theShotNum = undefined
Global TheFolderArray = undefined
Global Shotname = undefined

-- shotname = "101_002_wa_0020_clean_tail"

EditText Shotname "Shot Name" Width:300 align:#right
Button MkFolders "Make Folders" Width:300 align:#right

TheFolderArray = #(@"N:\Renders\3d",@"N:\Renders\Jpegs",@"N:\Renders\Nuke",@"M:\Playouts",@"P:\Projects\2d\textures",@"P:\Projects\3d\animation",@"P:\Projects\3d\setups",@"P:\Projects\3d_tracking",@"P:\Projects\Nuke",@"L:\Library\2d\textures")

On mkFolders pressed do
(

theNameArray = filterstring shotname.text "_"

-- check Episode number to see if it's over 10

if ((theNameArray[1] as string).count == 3) then
(

theSeasonNum = substring (theNameArray[1] as string) 1 1
theEpisodeNum = substring (theNameArray[1] as string) 2 2
theShotNum = (theNameArray[2] as string)

Print ("The season number is " + theSeasonNum as string + ", the Episode number is " + theEpisodeNum as string + " and the shot number is " + theShotNum as string)

) else (

theSeasonNum = substring (theNameArray[1] as string) 1 2
theEpisodeNum = substring (theNameArray[1] as string) 3 2
theShotNum = (theNameArray[2] as string)

Print ("The season number is " + theSeasonNum as string + ", the Episode number is " + theEpisodeNum as string + " and the shot number is " + theShotNum as string)

)

-- End check episode number

for f = 1 to TheFolderArray.count do
(

-- Split the folder based on a back slash

PathFilt = filterstring TheFolderArray[f] @"\"

-- Set a temp variable top hold our new folder name in

theFiltPath = ""

-- Take our exploded path and replace in a correct backslash

for p = 1 to Pathfilt.count do
(
theFiltPath = theFiltPath + PathFilt[p]

if p != Pathfilt.count then
(
theFiltPath = theFiltPath + "\\"
)
)

-- Make our end path name

theFolder = ("makedir @" + "\"" + theFiltPath as string + "\\" + "ep_" + theEpisodeNum as string + "\\" + theshotNum as string + "\"")

print theFolder

)

-- Filter and
)
)

createdialog ss_make_folders width:340

Gravey
11-23-2010, 01:20 PM
TheFolderArray = ... should be: local TheFolderArray = ... since you are using it as a local rollout variable

joconnell
11-23-2010, 02:09 PM
Hmm - would have thought making a variable global first would prevent any of those issues - I'll have a read through the docs on the two scopes. Much appreciated for the help!

PEN
11-23-2010, 02:31 PM
Really you want to avoid making any globals and keep them all local. If you have lots of globals floating around they could get over written by another tool that just happens to use the same global name.

joconnell
11-25-2010, 11:03 AM
Very good point - I clearly know just enough to get myself in trouble :D

CGTalk Moderation
11-25-2010, 11:03 AM
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.