Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Python API 2.0 - executeCommand

Python API 2.0 - executeCommand

Anonymous
Not applicable
632 Views
2 Replies
Message 1 of 3

Python API 2.0 - executeCommand

Anonymous
Not applicable

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 #

 

633 Views
2 Replies
Replies (2)
Message 2 of 3

zewt
Collaborator
Collaborator

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)

 

Message 3 of 3

Anonymous
Not applicable

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.