MEL:Get the selected directory


#1

Hello.
I’m creating a tool to get the selected directory.
I have a problem when I select the second item.
I think the second optionMenu is wrong, but how should I write it?
3rd item becomes an error.
help me…

↓test
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
global proc string optionMenuSample1(string $mainpath)
{
int $num = optionMenu -q -ni subFolderOptionMenu;
string $fname = optionMenu -q -v foldersOptionMenu;
string $names[] = getFileList -fld ($mainpath + $fname + "/") -fs "*.";
int $i = 0;
for($n in $names){
if($i < $num){
menuItem -e -l $n(“subFolderMenuItem” + $i);
return $fname;
}else{
menuItem -p subFolderOptionMenu -l $n (“subFolderMenuItem” + $i);
return $fname;
}
$i++;
}
for(; $i < $num; $i++){
deleteUI (“subFolderMenuItem” + $i);
}
}
global proc string optionMenuSample2(string $mainpath ){
int $num = optionMenu -q -ni btmFolderOptionMenu;
string $fname = optionMenu -q -v subFolderOptionMenu;
string $names[] = getFileList -fld ($mainpath + $fname + "/") -fs "*.";
int $i = 0;
for($n in $names){
if($i < $num){
menuItem -e -l $n(“btmFolderMenuItem” + $i);
return $fname;
}else{
menuItem -p btmFolderOptionMenu -l $n (“btmFolderMenuItem” + $i);
return $fname;
}
$i++;
}
for(; $i < $num; $i++){
deleteUI (“btmFolderMenuItem” + $i);
}
}
{
window;
columnLayout;
string $drive = “C”;
string $mainpath = $drive + “:/Autodesk/”;
optionMenu -l “1st” -cc (“optionMenuSample1(”" + $mainpath + “”)") foldersOptionMenu;
string $names1[] = getFileList -fld $mainpath -fs "*.";
for($n in $names1){
menuItem -label $n;
}
optionMenu -l “2nd” -cc (“optionMenuSample2(”" + $mainpath + “”)") subFolderOptionMenu;
string $names2[] = getFileList -fld ($mainpath + $names1[0] + "/") -fs "*.";
int $i = 0;
for($n in $names2){
menuItem -l $n (“subFolderMenuItem” + $i);
$i++;
}
optionMenu -l “3rd” btmFolderOptionMenu;
string $names3[] = getFileList -fld ($mainpath + $names1[0] + "/" + $names2[0]+ "/") -fs "*.";
int $a = 0;
for($n in $names3){
menuItem -l $n (“btmFolderMenuItem” + $a);
$a++;
}
showWindow;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////