mel syntax error - processing to maya


#1

Hi I’m wanting to send a mel string message to a custom string attribute (“myData”) that i’ve set up on a locator in maya from processing sketch.
I’m getting the error
// Error: Line 1.36: Syntax error //
// Error: setAttr -type string locator1.myData “888”; //
Maybe somebody can set me straight on the correct syntax because theres something wrong in.

String message = ("setAttr -type string locator1.myData " + '"' + $w + '"');

just to clarify i want “888” (including the “”) in the attribute.

for reference heres the maya script editor output if doing it directly on the attribute in maya

setAttr -type "string" locator1.myData "\"888\"";

i’ve tried various variations with the \ and " and quotes around and not around the “string” but can’t get it to work.
Heres the processing sketch


// this app sends data from Processing to string attribute in Maya 

//import the .net library
import processing.net.*;

//instantiate a Client instance
Client mayaClient;

//variables
String $w = "888";
// mel script string message to set value of string of attribute "myData" on locator1
String message = ("setAttr -type string locator1.myData " + '"' + $w + '"');

void setup()
{
  // this = parent; a wrapper class; localhost = same computer; 6004 = port
  mayaClient = new Client(this, "127.0.0.1", 6004);
  frameRate(25);
}

void draw()
{
  mayaClient.write(message);
}

for those who want to follow along you will need to open a port within maya.
open command port in maya

commandPort -name "127.0.0.1:6004"

close command port in maya

commandPort -name "127.0.0.1:6004" -cl

Cheers guys
Luke


#2

Since “string” is a keyword in MEL, you need to wrap it in quotes as well, so try this:

String message = ("setAttr -type \"string\" locator1.myData " + '"' + $w + '"');

#3

thanks for the answer Keilun,
pymel/python is my thing, having kicked mel scripting to the curb years ago.
mel is fugly to write and read :slight_smile:
your usful suggestion using the ‘’

String $w = "888";
String message = ("setAttr -type \"string\" locator1.myData " + '"' + $w + '"');

gives us 888
reading up elsewhere in order to get “888”
I tried

 String $w = "\"888\"";

but get // Error: line 1: setAttr: Too much data was provided. The last 1 elements were not used. //

now to bypass all the mel foolishness and just mel to call a python script
if i was calling a python script from mel this works

python ("import callFromMel 
callPython() ")

from within the processing script trying

String message = ("python (\"import callFromMel 
 callPython() \")");

theres a error Wrong number of arguments on call to callPython. //

any ideas whats going on?
Thanks


#4

I don’t know what language you’re using to send the message across the commandPort, but at the end of the day, the way the MEL command needs to look is:

setAttr -type "string" locator1.myData "888";

In MEL, if you wanted to capture this into a string, you would write it like this:

string $cmd = "setAttr -type \"string\" locator1.myData \"888\";"

You’ll need to sort out how to escape the " character to properly build the above string in whatever language your processing program is written in.

As for the calling Python from MEL, I can’t really help there since you haven’t provided any of the details of your callFromMel module. Presumably, callPython is a function defined in the callFromMel module, which would suggest you would need to call it like this:

python("import callFromMel
callFromMel.callPython()")

But that’s just a guess without seeing the actual code.