API error

76 views
Skip to first unread message

Abdelhalim abulmagd

unread,
May 20, 2023, 8:00:59 PM5/20/23
to Python Programming for Autodesk Maya
i got this error when i run my first api code .. can anyone help me please !

--------------------------
the error :

Error: TypeError: file C:/Users/abdelhalim.abdo/Documents/maya/2024/plug-ins/api_learning.py line 26: argument 1 must be OpenMaya.MObject, not MObject #

-----------------

the code :


import maya.api.OpenMaya as om

import maya.cmds as cmds



def use_NewAPI():

pass


class MyCmd(om.MPxCommand):

NAME = 'heycmd'

def __init__(self):

super(MyCmd, self).__init__()

def doIt(self, args):

print('this my first cmd :)')

@classmethod

def c(cls):

return MyCmd()


def initializePlugin(p):

vendor = 'abdo'

version = '1.0.0'

mfn = om.MFnPlugin(p, vendor, version)

mfn.registerCommand(MyCmd.NAME, MyCmd.c)

def uninitializePlugin(p):

mfn = om.MFnPlugin(p)

mfn.deregisterCommand(MyCmd.NAME)



if __name__ == "__main__":
   
    p_name = 'api_learning.py'
    cmds.evalDeferred(f'if cmds.pluginInfo("{p_name}", q=1, loaded=1): cmds.unloadPlugin("{p_name}")')
    cmds.evalDeferred(f'if not cmds.pluginInfo("{p_name}", q=1, loaded=1): cmds.loadPlugin("{p_name}")')


Justin Israel

unread,
May 20, 2023, 9:52:05 PM5/20/23
to python_in...@googlegroups.com
Do you need to rename use_NewAPI -> maya_useNewAPI ?

Also for future code, it would be better to use a pastebin or gist to retain the formatting, so that when your error contains line references, they can actually be located by others.

Justin


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ee6a4d53-823c-4c06-a9a0-c7d53f4219c4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages