Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python API 2.0 - executeCommand

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
459 Views, 2 Replies

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 #

 

Python API 2.0 - executeCommand

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 #

 

2 REPLIES 2
Message 2 of 3
zewt
in reply to: Anonymous

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)

 

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
in reply to: zewt

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.

 

 

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.

Post to forums  

Autodesk Design & Make Report