PDA

View Full Version : fileDialog problem..


CGmonkey
10-23-2003, 03:41 PM
Hi all, this is my second day of serious MEL scripting and I've ran into a problem.. Any help is greatly appriciated! :wavey:

I have a textScrollList and I need to browse files which will be viewed in the textScollList. I use fileDialog to get the file and then append to the textScrollList.

Here's the code..

global proc string getFileName(string $file)
{
$file = `fileDialog -dm "*.bmp"` ;
return $file;
}


The problem is, it displays the full name with directories and I just want the filename.. Is there any way to achieve this?

Another small issue, does anyone know how to set specific commands to different inputs in the textScrollList?

Thanks for taking the time to read ^^

wgreenlee1
10-23-2003, 03:57 PM
ReturnValue
string[] an array of file names
Description

Flags
-fld/-folder string return a directory listing
-fs/-filespec string wildcard specifier for search.

Examples

// List the contents of the user's projects directory
//
getFileList -folder `internalVar -userWorkspaceDir`;

// List all MEL files in the user's script directory
//
getFileList -folder `internalVar -userScriptDir` -filespec "*.mel";





"-file spec" maybe....
I guess i should try it myself but seems like you have to use that to get to the specific files....
yes i know im lost but its seems right....

CGmonkey
10-23-2003, 04:40 PM
wgreenlee - It didn't work >_< but when I searched for getFileList I found "file" command which returns the filename of a file you imported..

file -i $file;
return $file;

But it didn't work either >_<
Thank you anyway! :)

wgreenlee1
10-23-2003, 04:44 PM
i can get the mel example to work but cant get it to query the disk to find any .bmps

my brain is on fire after all that thinking...lol

CGmonkey
10-23-2003, 04:46 PM
Haha thanks for trying >_< it's driving me mad! ;) hehe

chips__
10-23-2003, 04:49 PM
i've recently written a filebrowser that works on all (still beta, i havent testet on all systems etc) operating systems. maybe you can see some of the code in there?

anyone else, please play around with it.

// filebrowser for all operating systems beta 0.1
// (c) peter hartwig 2003 / peter@hartwig.dk

/* usage : phFileBrowse (window title, ok button title, cancel button title,
start dir)

When the ok button is pressed, the optionVar phBrowseFile is updated.
a quick example would be:

phFileBrowse("Select outputfile","OK","Cancel","/net/homes/phartwig/");

scriptJob -uiDeleted phBrowseWindow " phUpdateOut " ;
proc phUpdateOut()
{
string $x = `optionVar -q phBrowseFile`;
print $x;
}

*/

/*
updates to come, hopefully
-sorting by name, date etc.
-history
-if possible, and if people want it, some way of returning the filename directly
-a nicer interface?
*/


global proc phFileBrowse(string $phBrowseWinTitle, string $phBrowseOkBtn,
string $phBrowseCnlBtn, string $phBrowseDir)
{
chdir $phBrowseDir;
string $window = `window -title $phBrowseWinTitle -width 300 -height 500 phBrowseWindow`;
string $form = `formLayout -numberOfDivisions 100`;
string $b1 = `textScrollList -dcc updatelist DirList`;
string $b2 = `textScrollList -sc updatetextfield FileList`;
string $b3 = `textField FileText`;
string $column = `columnLayout -adjustableColumn true`;
button -label $phBrowseOkBtn -c phBrowseOk; button -label $phBrowseCnlBtn -c phBrowseCancel;

formLayout -edit
-attachForm $b1 "top" 2
-attachForm $b1 "left" 2
-attachControl $b1 "bottom" 2 $b2
-attachPosition $b1 "right" 2 75

-attachControl $b3 "top" 2 $b2
-attachForm $b3 "left" 2
-attachForm $b3 "right" 2
-attachForm $b3 "bottom" 2

-attachForm $b2 "top" 200
-attachForm $b2 "left" 2
-attachForm $b2 "bottom" 30
-attachForm $b2 "right" 2

-attachForm $column "top" 2
-attachPosition $column "left" 0 75
-attachControl $column "bottom" 2 $b2
-attachForm $column "right" 2
$form;
showWindow $window;

phBrowseUpdateDirs;
}

global proc phBrowseUpdateDirs()
{
textScrollList -e -ra DirList;
$currentDir = (`pwd`+"/");

string $dirs[] = `getFileList -folder $currentDir`;
string $dir;
int $dirTest=0;
int $dirNo = 0;
textScrollList -e -append ".." DirList;
for ($dir in $dirs)
{
$dirTest = `filetest -d $dirs[$dirNo]`;
if ($dirTest == true)
{
textScrollList -e -append $dirs[$dirNo] DirList;
};
$dirNo = $dirNo +1;
};

}

global proc updatelist()
{
textScrollList -e -ra FileList;
string $selectedItem[] = `textScrollList -query -selectItem DirList`;
chdir ($selectedItem[0]+"/");
string $currentDir = (`pwd`+"/");
string $b[] = `getFileList -folder ($currentDir)`;
string $x;
string $fileTest = 0;
int $i = 0;
for ($x in $b)
{
$fileTest = `filetest -f $b[$i]`;
if ($fileTest == 1)
{
textScrollList -e -append $b[$i] FileList;
}
$i=$i+1;
};
phBrowseUpdateDirs;
}

global proc updatetextfield()
{
string $selectedFile[] = `textScrollList -q -selectItem FileList`;
textField -e -tx $selectedFile[0] FileText;
}

global proc phBrowseOk()
{
string $phBrowseFile = ((`pwd`+"/")+ `textField -q -tx FileText`);
optionVar -stringValue phBrowseFile $phBrowseFile;
deleteUI -window phBrowseWindow;
}

global proc phBrowseCancel()
{
deleteUI -window phBrowseWindow;
}

wgreenlee1
10-23-2003, 05:16 PM
@chips_
i put it in the script ed and it doesnt do anthing...loaded through the script ed and still nothing...:hmm:

winXP

chips__
10-23-2003, 05:19 PM
at the top of the script, theres a note about how to use it

phFileBrowse("Select outputfile","OK","Cancel","/net/homes/phartwig/");

scriptJob -uiDeleted phBrowseWindow " phUpdateOut " ;
proc phUpdateOut()
{
string $x = `optionVar -q phBrowseFile`;
print $x;
}

run that in your script editor after having run the script itself

Doogie
10-23-2003, 11:25 PM
hows this?? it should work

string $file = "C:/Documents and Settings/Doogie/Desktop/pics/charCtrls2_03.bmp";
string $fileNames[];

int $n = `tokenize $file "/" $fileNames`;
print $fileNames[$n-1];

Doogie
10-23-2003, 11:57 PM
hah, found this command too

basename(string $path, string $extension)

mark_wilkins
10-24-2003, 03:36 AM
I usually use tokenize to pull the filename off a path.

-- Mark

Marcel
12-19-2004, 08:04 PM
*Post edited*
never mind, problem solved...nothing to see here :)

CGTalk Moderation
01-16-2006, 12:00 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.