Having trouble making Python communicate with MEL

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2013
Having trouble making Python communicate with MEL

What I'm trying to do is write a Python script that (among many other things), allows you to specify the location of a MEL script that it will then run. However I'm having trouble using the maya.mel.eval command.

Namely, you can't use the source command to grab a MEL script with a variable. It has to be

source "file location" ;

And if you want to use a variable you have to do it using an eval. Easy.

string $scriptpath = "file location" ;
string $melSource = ("source \""+$scriptpath+"\" ;") ;
eval $melSource ;

So this works totally fine in MEL. However, Python seems to be having trouble doing it.

When I try

maya.mel.eval('string $melSource = ("source \""+$scriptpath+"\" ;") ;')

I get back that it tried to run

// Error: string $melSource = ("source ""+$scriptpath+"" ;") ; //

Which is NOT what I wrote. You can see that the integral \ are missing, which means the MEL script won't work. Why would python be removing those before running the MEL script? Can someone help me out with a way around this?
 
  03 March 2013
Why are you trying to grab the return value to a mel variable if you are working in python?
For example I have a mel script called addPadding.mel that takes two arguments, the original number and the number of chacters to pad it with, and it returns a string.

import pymel.core as pm
srcPath = 'U:/maya/scripts/utility/'
pm.mel.source(srcPath+'addPadding.mel')
num = pm.mel.addPadding(27, 3)
print num

# Result: u'027' # 


David

(nobody would really use mel to pad a number in python - just wanted to show a simple example)
__________________
http://www.djx.com.au
 
  03 March 2013
Here is another way:
import maya.mel 

pathName = '/Users/pieFun/Library/Preferences/Autodesk/maya/2013-x64/prefs/'
fileName = 'userPrefs.mel'

var = maya.mel.eval('source \"' + pathName + fileName +'\"' )
print var
__________________
Digital Characters R&D - Suntoucher Labs
 
  03 March 2013
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:41 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.