I am trying to figure out how I can read in a block of code from a text file to be executed in a MEL script.
I have separate windows that are populated by the same buttons. If I want to update all the windows, I need to open the separate MEL files and add the new code to each. It would be preferable if there was a single Master Text File that I could update, which would then propagate to all the different windows, drawing from that one file.
Is it possible to save just the button code in a text document and then call on that to be inserted and executed for each window script?
I have been able to read the text file contents into a variable that I can then print, but I haven't figured out how to execute the code in that text file within a script.
So far I've explored solutions with feof
, fgetline
, fopen
, fread
, freadAllText
.
Here's an example of what I'm looking to do....
window -title "WINDOW" -rtf true -s false myWindow;
gridLayout -numberOfColumns 5 0cellWidthHeight 50 50;
// -- THIS IS THE BLOCK I'D LIKE TO READ IN TO EXECUTE -- //
// BUTTON
symbolButton -i "/image1.png" -c "myCommand1"
// BUTTON
symbolButton -i "/image2.png" -c "myCommand2"
// BUTTON
symbolButton -i "/image3.png" -c "myCommand3"
// BUTTON
symbolButton -i "/image4.png" -c "myCommand4"
// -- END BLOCK TO READ IN TO EXECUTE -- //
showWindow myWindow;
The text file I save out would be....
//
//-- BLOCK TO READ IN TO EXECUTE -- //
// BUTTON
symbolButton -i "/image1.png" -c "myCommand1"
// BUTTON
symbolButton -i "/image2.png" -c "myCommand2"
// BUTTON
symbolButton -i "/image3.png" -c "myCommand3"
// BUTTON
symbolButton -i "/image4.png" -c "myCommand4"
// -- END BLOCK TO READ IN TO EXECUTE -- //
... and then I would like to read that into multiple scripts, so I can just update that file and it will propagate, looking something like this...
window -title "WINDOW" -rtf true -s false myWindow;
gridLayout -numberOfColumns 5 0cellWidthHeight 50 50;
magicReadInAndExecute "/directory/file.txt";
showWindow myWindow;
MEL or Python solutions are welcome. I'm more proficient at MEL but am beginning to transition to Python.