In Python API 2.0 executeCommand was removed.
What way now to perform MEL code In Python API 2.0?
In Python API 1.0 this way is work fine -
import maya.OpenMaya as OpenMayaOld
mIntArray = OpenMayaOld.MIntArray()
cmd = ("global string $gPlayBackSlider; "
"$gPlayBackSlider = $gPlayBackSlider;"
"$temp2 = `timeControl -q -ra $gPlayBackSlider`;")
OpenMayaOld.MGlobal.executeCommand( cmd, mIntArray, False, False )
print (mIntArray)
#[1, 4]
In Python API 2.0 this way is NOT work -
import maya.api.OpenMaya as OpenMaya
cmd = ("global string $gPlayBackSlider; "
"$gPlayBackSlider = $gPlayBackSlider;"
"$temp2 = `timeControl -q -ra $gPlayBackSlider`;")
result = OpenMaya.MGlobal.executeCommandStringResult( cmd, False, False )
print (result)
# Error: (kFailure): Unexpected Internal Failure
# Traceback (most recent call last):
# File "<maya console>", line 7, in <module>
# RuntimeError: (kFailure): Unexpected Internal Failure #
In Python API 2.0 executeCommand was removed.
What way now to perform MEL code In Python API 2.0?
In Python API 1.0 this way is work fine -
import maya.OpenMaya as OpenMayaOld
mIntArray = OpenMayaOld.MIntArray()
cmd = ("global string $gPlayBackSlider; "
"$gPlayBackSlider = $gPlayBackSlider;"
"$temp2 = `timeControl -q -ra $gPlayBackSlider`;")
OpenMayaOld.MGlobal.executeCommand( cmd, mIntArray, False, False )
print (mIntArray)
#[1, 4]
In Python API 2.0 this way is NOT work -
import maya.api.OpenMaya as OpenMaya
cmd = ("global string $gPlayBackSlider; "
"$gPlayBackSlider = $gPlayBackSlider;"
"$temp2 = `timeControl -q -ra $gPlayBackSlider`;")
result = OpenMaya.MGlobal.executeCommandStringResult( cmd, False, False )
print (result)
# Error: (kFailure): Unexpected Internal Failure
# Traceback (most recent call last):
# File "<maya console>", line 7, in <module>
# RuntimeError: (kFailure): Unexpected Internal Failure #
I don't know why this function doesn't work, though since it's an array result, getting a string back would be pretty awkward even if it did. I don't know where MGlobal.executeCommand is. You can just use OpenMaya1 for this, that's what Maya's own Python scripts do.
FWIW, for this particular example I'd just use PyMEL:
import pymel.core as pm
start, end = pm.timeControl(pm.mel.globals['gPlayBackSlider'], q=True, ra=True)
print(start, end)
I don't know why this function doesn't work, though since it's an array result, getting a string back would be pretty awkward even if it did. I don't know where MGlobal.executeCommand is. You can just use OpenMaya1 for this, that's what Maya's own Python scripts do.
FWIW, for this particular example I'd just use PyMEL:
import pymel.core as pm
start, end = pm.timeControl(pm.mel.globals['gPlayBackSlider'], q=True, ra=True)
print(start, end)
Yes, the reason of error is because "executeCommandStringResult" return result in this case as arrray of integers, not string. I think too now.
Yes, now i use just old API for this function, i mean i use "executeCommand" for get highlighted range.
I just want to use only Python API 2.0, i am trying to avoid any Mel, cmds, or pymel methods. I want later rewrite this scripts on C++, if will have time. But C++ in Maya as i saw have "executeCommand".
Thanks.
Yes, the reason of error is because "executeCommandStringResult" return result in this case as arrray of integers, not string. I think too now.
Yes, now i use just old API for this function, i mean i use "executeCommand" for get highlighted range.
I just want to use only Python API 2.0, i am trying to avoid any Mel, cmds, or pymel methods. I want later rewrite this scripts on C++, if will have time. But C++ in Maya as i saw have "executeCommand".
Thanks.
Can't find what you're looking for? Ask the community or share your knowledge.