Maya Python type problem const & in C++

Maya Python type problem const & in C++

Anonymous
Not applicable
821 Views
2 Replies
Message 1 of 3

Maya Python type problem const & in C++

Anonymous
Not applicable

Hi everyone,

 

I've been trying to change the type of cursor used in Maya via python in a context command but I still didn't have any sucess and I've been trying this for some days already... 😕

 

class DrawContext( OpenMayaMPx.MPxContext 😞
    
    def __init__(self):
        ''' Constructor. '''
        OpenMayaMPx.MPxContext.__init__(self)
   
    def toolOnSetup(self, event):
        self._setCursor(OpenMayaUI.MCursor.pencilCursor)

And I allways get this error:

// Error: TypeError: in method 'MPxContext__setCursor', argument 2 of type 'MCursor const &' //

 

the python function is defined as _setCursor(*args).... and I know that in c++ it is only necessary to do setCursor(MCursor::pencilCursor)... I'm completely lost by this point... I already tryed passing as a list or tuple, and thought of MScriptUtil but it doesn't have this kind of conversion...


Any idea on how to solve this would be awesome!

Thank you!

 

0 Likes
822 Views
2 Replies
Replies (2)
Message 2 of 3

cyrille
Alumni
Alumni

Hi,

 

You should try the following

 

try: 
     cursor = OpenMayaUI.MCursor.pencilCursor.fget() 
     self._setCursor(cursor) 
except: 
     print "set did not work" 

 

because in Python this is not a constant, but the actual cursor representation.

Hope that helps

 

cheers

-cyrille

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi!

 

It works! I think.. even though it doesn't change the cursor.. it doesn't crash anymore 😄

 

I thought that python would convert the types automatically, but now I know how to circunvent these cases. Thanks!

 

Best,

José

0 Likes