Lee, Andrew Hickinbottom (3D) Tank Girl, Pedro Conti (2D)

View Full Version : How to read out button label from buttons created in a loop

01-25-2011, 04:51 PM

I am working on a script to be able to import certain scenes based on a list of names in a .txt file.
I am trying to have the script make a button for each line in the .txt file.
I got some of the code to read out the .txt file from http://www.scriptswell.net/
And got the script to make buttons with the labels of the words in the .txt file.

Now i want to add a command when the button is pushed. But because my buttons are created in a loop I don't know how to call them in my procedure. I want to know which of the buttons is pressed.

I find it hard to explain, but hope it is clear and you guys can help me with having the procedure importFile() import a file with the same name as the corresponding line in my .txt file and thus the name of the button.

Thank you very much!

string $filePath = "D:/sceneList.txt";
string $window = `window -title "Long Name"
-iconName "Short Name"
-widthHeight 200 55`;
columnLayout -adjustableColumn true;

$fileId = `fopen $filePath "r"` ;

string $nextLine = `fgetline $fileId` ;

while (size($nextLine) > 0) {
string $cleanLine = strip($nextLine) ;

button -label $cleanLine -c "importFile()" ;

print ($cleanLine+"\n") ;

$nextLine = `fgetline $fileId` ;
setParent ..;
showWindow $window;

global proc importFile()

//here I want to have a command that will import the file with the name of the line in the .txt file.


01-25-2011, 08:17 PM
I don't think you need to know which button was pressed, you just need to make each button pass it's unique data to the function it calls. e.g.

button -label $cleanLine -c ("importFile "+$cleanLine) ;you then need to make the importFile function accept a string parameter:

global proc importFile(string $inputFile)if you DID want to know which button had been pressed the easiest way would be to pass an index, an id string or the button name to the function instead, but you'd rarely need to know the name of a button you've pressed.


CGTalk Moderation
01-25-2011, 08:17 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.