Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating Old MEL Script for Maya 2018

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
joel.hornby
1156 Views, 2 Replies

Updating Old MEL Script for Maya 2018

Hi everyone,

I have a MEL script from a book written for Maya 2006, I think, that I am trying to use in Maya 2018.

 

It's giving me quite a lot of errors, please see below, but I don't think I should be sharing the script in a forum due to copyright. Probably goes without saying, but I am also very new to MEL and programming in general too.

 

But does anyone have any recommendations for fixing these errors?

 

Thank you for reading,

 

Joel

 

 

// Error: if (frame == 1) { //
// Error: Line 82.12: Invalid use of Maya object "frame". //
// Error: $x = $cellPos[(int)(frame-1)][$i*2]; //
// Error: Line 168.28: Invalid use of Maya object "frame". //
// Error: $z = $cellPos[(int)(frame-1)][$i*2+1]; //
// Error: Line 169.28: Invalid use of Maya object "frame". //
// Error: $x = $cellPos[(int)(frame-1)][$i*2]; //
// Error: Line 196.28: Invalid use of Maya object "frame". //
// Error: $z = $cellPos[(int)(frame-1)][$i*2+1]; //
// Error: Line 197.28: Invalid use of Maya object "frame". //
// Error: $x = $cellPos[(int)(frame-2)][$i*2]; //
// Error: Line 209.28: Invalid use of Maya object "frame". //
// Error: $z = $cellPos[(int)(frame-2)][$i*2+1]; //
// Error: Line 210.28: Invalid use of Maya object "frame". //
// Error: if (frame == 4) { // Add a Paint Effects stroke to each curve. //
// Error: Line 219.12: Invalid use of Maya object "frame". //
// Error: if (frame == `playbackOptions -q -max`) { //
// Error: Line 242.12: Invalid use of Maya object "frame". //
// Error: $x = $cellPos[(int)(frame-1)][$i*2]; //
// Error: Line 249.28: Invalid use of Maya object "frame". //
// Error: $z = $cellPos[(int)(frame-1)][$i*2+1]; //
// Error: Line 250.28: Invalid use of Maya object "frame". //
// Error: fprint $fileID $dataOut; //
// Error: Line 294.26: "$dataOut" is an undeclared variable. //

2 REPLIES 2
Message 2 of 3
mspeer
in reply to: joel.hornby

Hi!

Please make sure to use this in an expression, it will not work in standard MEL / Script Editor.

Message 3 of 3
joel.hornby
in reply to: mspeer

Thank you very much @mspeer !

 

I ran the script as an expression, any idea why I now get the 'Procedure has multiple parameters named "$fileName".' error?

 

I have also been doing tutorials to learn more about MEL, but any tips on how to update this script would be much appreciated!

 

EEapplyCB;
expression -s "/***** moveCells.txt *****/\n/*\nDate: August 2007\nAuthors: Donny Ly and Jason Sharpe\n\nDescription: \nThis expression reads in cell migration data from an external text file and \nuses it to move objects called \"cell1\", \"cell2\", etc. The cells are created if \nthey donít already exist in the scene file. This expression also calculates L, \nDnet, and Dc for the cells and prints the results to a text file.\n\nTo use this script: \nStart a new Maya scene, then copy and paste this entire script into Mayaís \nExpression Editor and press the Create button. Locate and load the data file \nwhen prompted by the file browser. Press play to animate the cells and generate \nthe summary report.\n*/\n\n\n/***** DECLARE THE VARIABLES *****/\n\n/*\n$fileName\tThe name of the open data file, cellData.txt. At frame 230 it \n\t\twill be used to store the name of your summary report file.\n$coord\t\tA temporary holder for the X and Z coordinate values.\n$line\t\tThe result of the fgetline command.\n$name\t\tThe current cell or curve name.\n$Lstring\tThe $L values for writing to the summary file.\ndNetString\tThe $dNet values for the summary file.\n$DcString \tThe Dc values for the summary file.\n*/\nstring $fileName, $coords[], $line, $name, $Lstring, $dNetString, $DcString;\n\n/*\n$dataOut\tA single string containing all of the information to be written\n\t\tto your summary file.\n*/\nglobal string $dataOut;\n\n/*\n$cellPos[][]\tThe XZ coordinates of the cells for all time steps.\n*/\nglobal matrix $cellPos[230][12];\n\n/*\n$fileID\t\tThe data file handle and is assigned by fopen.\n$cellCount\tThe number of cells, 6.\n*/\nglobal int $fileID, $cellCount;\n\n/*\n$L[]\t\tThe total distance by each cell.\n$dNet[]\t\tThe net displacement of each cell.\n$Dc[]\t\tThe directedness coefficient of each cell.\n*/\nglobal float $L[], $dNet[], $Dc[];\n\n/*\n$dNetSum\tUsed to calculate the average $dNet value.\n$Lsum\t\tUsed to calculate the average $Lsum value.\n$scale\t\tThe spatial scale of the simulation: 1.4 µm per video pixel.\n$x\t\tA Temporary holder for the cell x coordinate.\n$z\t\tA Temporary holder for the cell z coordinate.\n*/\nfloat $dNetSum, $Lsum, $scale, $x, $z;\n\n/*\n$newPos\t\tThe position of the current cell in the current frame. \n$oldPos \tThe position of the current cell in the previous frame. \n\t\tThe above values are used to calculate the distance travelled \n\t\tby the cell in one time step.\n*/\nvector $newPos, $newPos;\n\n/*\n$i\t\tA counter for matrix rows.\n$j\t\tA counter for matrix columns.\n*/\nint $i, $j;\n\n\nif (frame == 1) {\n\t\n\t\n\t/***** INITIALIZE THE VARIABLES *****/\n\t\n\t$cellCount = 6;\n\t$scale = 1.4;\n\t$dNetSum = $Lsum = 0;\n\t\n\t\n\t/***** MAIN BODY *****/\n\t\n\t// Set the playback speed (0 = play every frame) and range.\n\tplaybackOptions -playbackSpeed 0 -loop once -min 1 -max 230;\n\t\n\t// Define a procedure to fopen the data file.\n\tglobal proc fopenFile(string $mode, string $fileName, string $type) {\n\n\t\t// Open the file for reading.\n\t\t$fileID = `fopen $fileName $mode`;\t\n\t}\n\t\n\t/***** LOAD THE DATA *****/\n\n\t/* Check if the data has already been loaded. If it has, the file ID\n\twill not be 0. */\n\tif (!$fileID) {\n\t\n\t\t// Open a file browser and send the \"r\" mode argument to fopenFile.\n\t\tfileBrowserDialog -m 0 -fc (\"fopenFile\" + \" \\\"r\\\" \") -ft \"\" -an \"Open_File\";\n\t\t\n\t\t// Stop the expression if the user doesn't select a file.\n\t\tif ($fileID == 0) {\n\t\t\t\n\t\t\terror \"No file chosen\";\n\t\t}\n\t\t\t\n\n\t\t/* Run fgetline twice to increment to the start of the numerical data\n\t\t(past two lines of header text). */\n\t\tfgetline $fileID;\n\t\tfgetline $fileID;\n\n\t\t$i = 0; // The row counter.\n\t\t$line = `fgetline $fileID`;\n\n\t\twhile (!`feof $fileID`) { // feof returns 1 at the file end.\n\n\t\t\t// Break $line into tokens and store them in $cellNames.\n\t\t\ttokenizeList($line, $coords);\n\n\t\t\tfor ($j = 0; $j < $cellCount; $j++) { // The column counter.\n\t\t\t\n\t\t\t\t$cellPos[$i][$j*2] = (float) $coords[$j*2+1] * $scale;\n\t\t\t\t$cellPos[$i][$j*2+1] = (float) $coords[$j*2+2] * $scale;\n\t\t\t}\n\n\t\t\t$line = `fgetline $fileID`; // Get the next line of data.\n\t\t\t$i++; // Increment the row counter.\n\n\t\t} // End while loop.\n\t\n\t} // End if ($fileID) statement.\n\t\n\t\n\t/***** PREPARE THE SPHERES AND CURVES *****/\n\t// Sphere represent the cells, and the curves,the cell paths.\n\t\n\t// Delete existing curves.\n\tstring $tmpStr[];\n\t$tmpStr = `ls -tr \"curve*\"`; // Make a list of curves.\n\tif (`size $tmpStr` > 0) delete $tmpStr; // Delete the curves.\n\t\n\t// Delete existing Paint Effects strokes.\n\t$tmpStr = `ls -tr \"stroke*\"`; // Make a list of strokes.\n\tif (`size $tmpStr`) delete $tmpStr; // Delete the strokes.\n\t\n\t// Delete existing Paint Effects brushes.\n\t$tmpStr = `ls -tr \"brush*\"`; // Make a list of brushes.\n\tif (`size $tmpStr`) delete $tmpStr; // Delete the brushes.\n\t\n\t\n\t// Make and/or position the spheres, and make the curves.\n\tfor ($i = 0; $i < $cellCount; $i++) {\n\t\t\n\t\t// Store the cell coordinates in the variables $x and $y.\n\t\t$x = $cellPos[(int)(frame-1)][$i*2];\n\t\t$z = $cellPos[(int)(frame-1)][$i*2+1];\n\t\t\n\t\t$name = \"cell\" + $i; // $name is the cell name.\n\t\t// Make a sphere if one doesn't already exist.\n\t\tif (!`objExists $name`)\tsphere -r 5 -n $name; \t\t\n\t\t\n\t\t// Move the sphere into position.\n\t\tmove -absolute $x 0 $z $name;\n\t\t\n\t\t// Make the curve.\n\t\t// The curve command doesnít require a -name flag in create mode.\n\t\tcurve -point $x 0 $z -name (\"curve\" + $i);\n\t}\n\t\n\t// Clear the migration statistics variables.\n\tclear $L; clear $dNet; clear $Dc;\n\t$dataOut = $Lstring = $dNetString = $DcString = \"\";\n\n\t\n} // End if (frame == 1) statement.\n\n\nelse { // Frame > 1\n\t// Position the cells.\n\tfor ($i = 0; $i < $cellCount; $i++) {\n\n\t\t// Store the cell coordinates in the variables $x and $z.\n\t\t$x = $cellPos[(int)(frame-1)][$i*2];\n\t\t$z = $cellPos[(int)(frame-1)][$i*2+1];\n\n\t\t$name = \"cell\" + $i;\n\t\tmove -absolute $x 0 $z $name;\n\n\t\t// Add to each cell's trajectory curve.\n\t\t$name = \"curve\" + $i;\n\t\t// The -append flag tells the curve command to add to an existing curve.\n\t\tcurve -append -point $x 0 $z $name;\n\t\t\n\t\t$newPos = <<$x, 0, $z>>;\n\t\t\n\t\t$x = $cellPos[(int)(frame-2)][$i*2];\n\t\t$z = $cellPos[(int)(frame-2)][$i*2+1];\n\t\t\n\t\t$oldPos = <<$x, 0, $z>>;\n\t\t\n\t\t// Calculate the displacement, L, for cell $i.\n\t\t$L[$i] += `mag ($newPos - $oldPos)`; // mag returns the scalar length of the vector.\n\t}\n}\n\nif (frame == 4) { // Add a Paint Effects stroke to each curve.\n\t\t\n\t// Make the Paint Effects strokes.\n\tselect `ls -tr \"curve*\"`;\n\tAttachBrushToCurves;\n\tconvertCurvesToStrokes;\n\tstring $strokes[] = `ls -tr \"stroke*\"`;\n\tselect $strokes;\n\tShareOneBrush;\n\t\n\tstring $name;\n\tfor ($name in $strokes){\n\t\n\t\tstring $tmp[] = `listRelatives -children $name`;\n\t\tsetAttr ($tmp[0] + \".sampleDensity\") 50;\n\t\tsetAttr ($tmp[0] + \".useNormal\") 1;\n\t}\n\n\tstring $list[] = `listConnections strokeShape1`;\n\tsetAttr ($list[0] + \".color1\") -type double3 1 1 1; // Make the stroke white.\n\tsetAttr ($list[0] + \".brushWidth\") 0.2; // Set the brush width.\n}\n\nif (frame == `playbackOptions -q -max`) {\n\t\n\t/* Calculate the Net displacement, Dnet, and the average values for each parameter.*/\n\tfor ($i = 0; $i < 6; $i++) {\n\t\n\t\t// Net displacement.\n\t\t\n\t\t$x = $cellPos[(int)(frame-1)][$i*2];\n\t\t$z = $cellPos[(int)(frame-1)][$i*2+1];\n\t\t$newPos = <<$x, 0, $z>>;\n\t\t\n\t\t$x = $cellPos[(int)0][$i*2];\n\t\t$z = $cellPos[(int)0][$i*2+1];\n\t\t$oldPos = <<$x, 0, $z>>;\n\t\t\n\t\t$dNet[$i] = `mag ($newPos - $oldPos)`;\n\t\t$dNetSum += $dNet[$i]; // Sum the net displacement for all eight cells.\n\t\t$Lsum += $L[$i]; // Sum the total distance travelled for all cells.\n\t\t$Dc[$i] = $dNet[$i]/$L[$i]; // Calculate the directedness ratio.\n\t\t\n\t}\n\t\t\n\t$dNet[6] = $dNetSum/6; // Average net displacement for all cells.\n\t$L[6] = $Lsum/6; // Average distance travelled for all cells.\n\t$Dc[6] = $dNet[6]/$L[6]; // Averate directedness ratio for all cells.\n\t\n\t/* \n\tPut $N, $D, and $L arrays into single-value strings to print to the text file. \n\tThe first character in each string identifies the variable: L, Dnet, or Dc. \n\tTab characters are used to separate each array element.\n\t*/\n\tfor ($i = 0; $i < 7; $i++) {\n\t\n\t\t$Lstring = $Lstring + \"\\t\" + $L[$i];\n\t\t$dNetString = $dNetString + \"\\t\" + $dNet[$i];\n\t\t$DcString = $DcString + \"\\t\" + $Dc[$i];\n\t}\n\t\n\t// Compose the migration parameters for printing.\n\t$dataOut = \"Title: Cell Migration Summary Data\\nAuthor: Your Name\\n************************************\\n\\n\";\n\t$dataOut = $dataOut + \"***** Directedness Coefficient *****\\n\";\n\t$dataOut = $dataOut + \"Cell:\\t0\\t1\\t2\\t3\\t4\\t5\\tAvg.\\n\";\n\t$dataOut = $dataOut + \"L\" + $Lstring + \"\\n\";\n\t$dataOut = $dataOut + \"N\" + $dNetString + \"\\n\";\n\t$dataOut = $dataOut + \"D\" + $DcString;\n\n\t// Define a procedure to fopen and fprint the data file.\n\tglobal proc fprintFile(string $mode, string $fileName, string $type) {\n\n\t\t// Open the file for reading.\n\t\t$fileID = `fopen $fileName $mode`;\n\t\t// Print the data string and close the file.\n\t\tfprint $fileID $dataOut;\n\t\tfclose $fileID;\n\t}\n\n\t// Open a file browser and send the \"w\" mode argument to fprintFile.\n\tfileBrowserDialog -m 1 -fc (\"fprintFile\" + \" \\\"w\\\" \") -ft \"\" -an \"Save_File\";\n}" -o "" -n "moveCells" -ae 1 -uc all ;
EEnodeAdded moveCells;
// Error: global proc fopenFile(string $mode, string $fileName, string $type) { //
// Error: Line 97.54: Procedure has multiple parameters named "$fileName". //
// Error: global proc fprintFile(string $mode, string $fileName, string $type) { //
// Error: Line 288.55: Procedure has multiple parameters named "$fileName". //
EEnodeRemoved moveCells;
setFilterScript "initialShadingGroup";
// Result: 0 //
setFilterScript "initialParticleSE";
// Result: 0 //
setFilterScript "defaultLightSet";
// Result: 1 //
setFilterScript "defaultObjectSet";
// Result: 1 //
mayaHasRenderSetup;
// Result: 1 //

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report