python format of a mel code


#1

This script is working properly in mel.
{
vrayCreateProxy

-exportType 1

-previewFaces 10000 -dir “D:\jay” -fname “a.vrmesh” -overwrite 1;
}

Now I am trying to embed this script in python with eval. But it is not working.
And this error is showing “EOL while scanning string literal”

import maya.mel as mm

mm.eval( 'vrayCreateProxy

-exportType 1

-previewFaces 10000 -dir “D:\jay” -fname “a.vrmesh” -overwrite 1;’)

What will be the correct version of this mel script?


#2

Python does not allow to split one string over several lines. You have to mask the newline:

s = 'this is
a test'

will not work.

s = 'this is \
a test'

will work better.

But you can do it witout using too much mel:

import pymel as pm
outputDir = "d:/outdir"
pm.vrayCreateProxy(exportType=1, previewFaces=10000, dir=outputDir, fname="a.vrmesh",overwrite=1)

This makes it easier to manipulate the variables.


#3

Thanks haggi.
But vrayCreateProxy function is not working in python.
Is there some other option in python for vrayCreateProxy?
I want to embed the mel script in python. Then again the eval is not working.


#4

Still the same error message? Post your updated code here, then we can help.


#5

import pymel as pm
outputDir = “d:/outdir”
pm.vrayCreateProxy(exportType=1, previewFaces=10000, dir=outputDir, fname=“a.vrmesh”,overwrite=1)

The error is: ‘module’ object has no attribute ‘vrayCreateProxy’


#6

import maya.cmds as cmds

outputDir = “d:/outdir”
cmds.vray(‘vrayCreateProxy’,exportType=True,previewFaces=10000,dir=outputDir,fname=“abcd.vrmesh”,overwrite =True)

This is not showing any error.
But it is not creating any proxy either.


#7

I usually do it the lazy way…

from maya import mel

command = “”"
whatever mel you need
whatever mel you need
whatever mel you need
whatever mel you need
“”""

mel.eval(command)


#8

Good point.

I’m sorry I forgot to add something:

import pymel.core as pm

#9

Thanks haggi. But still not working.

Thanks Panupat. The code is working perfectly with mel.eval.

I will get the directory and file name as input. So that will be in python variable.
How can I use the python variable (outputDir and fileName) in the mel command?

from maya import mel
outputDir = “D:\directory1”
fname= fileName
mel.eval( ‘vrayCreateProxy -exportType 1 -previewFaces 10000 -dir outputDir -fname fileName -overwrite 1;’)


#10

You are right, just tested it, vray seems not to like the way the command is called.

You can construct the mel string this way:

outputDir = "D:/directory1" #use forward slases because normally a \ mask the next character
 fname= fileName
cmd = 'vrayCreateProxy -exportType 1 -previewFaces 10000 -dir "{0}" -fname "{1}" -overwrite 1;'.format(outputDir, fname)
mel.eval(cmd)

#11

Thanks haggi. It is working perfectly.