I have a question about Maya API scripting

I have a question about Maya API scripting

malcolm_341
Collaborator Collaborator
491 Views
2 Replies
Message 1 of 3

I have a question about Maya API scripting

malcolm_341
Collaborator
Collaborator

Hi, I don't know anything about the API, I was told it's much faster than mel script for running loops so I have two questions:

 

1. Is there a way to use the API in conjunction with a mel script to run loops much faster for querying each UV shells position on a mesh for example, in mel this is too slow for my needs.

 

2. If the API does allow for fast loops, where should I go to start learning API scripting?

0 Likes
Accepted solutions (1)
492 Views
2 Replies
Replies (2)
Message 2 of 3

e_honda
Enthusiast
Enthusiast
Accepted solution

Hi,


I suppose you're talking about the Python's OpenMaya API and not the C++ API.
There are so many things that could be related to your question, so I'll point some of them.

https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=Maya_SDK_cpp_ref_annotated_html

https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=Maya_SDK_py_ref_namespace_open_maya_html

 


OpenMaya API
Maya have two OpenMaya APIs. The "old" and the "new" one.
To use the old one, you must write the code in a more C-like way, allocating memory and passing pointers to functions.
The new one is more pythonic, but some functions are not yet implemented.
Both of them are fast, but it does not means that using them you'll get something faster than Python or MEL commands.
Sometimes MEL is the fastest option.
Everything depends on what you want to do and how.

# Maya Python cmds
from maya import cmds

# "old" API
from maya import OpenMaya
# "new" API
from maya.api import OpenMaya

 

Faster
To make a script faster, you have many things that you could do.
Some examples:
- Change language or API
- Change algorithm
- Find bottlenecks and try to avoid them
- Try to do threading or parallelization
- Minor optimizations (premature optimization is something to avoid)
- something else

Changing the programming language, the API and so on could have effect. It could make things really faster.
But it is not as simpler as just switching from one to another.
You must test every option and check the execution speed for your use case.
Sometimes the same script is the fastest for one type of geometry but very slow for others.
Make sure that what your choice is the best option for your task.(And unfortunately, it is not something easy)


That said:


1. Is there a way to use the API in conjunction with a mel script to run loops much faster for querying each UV shells position on a mesh for example, in mel this is too slow for my needs.


You can call a Python script from MEL and vice versa.

If it will be faster or not, just depends. You must do some profiling.

MEL calling python

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/Commands/python.html

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/Commands/callPython.html

Python calling mel

https://download.autodesk.com/us/maya/2010help/CommandsPython/eval.html

 

 


2. If the API does allow for fast loops, where should I go to start learning API scripting?


I'm sorry, it is not clear for me if you're looking for ways to learn how to use OpenMaya or Python itself (and the Python's maya.cmds).
In either way, you should do some google for github repositories and gists of simple Maya scripts.
Maybe just checking Maya's docs could be really helpful.

 

 

Anyway, somebody else should complement what I wrote.

Or have a totally different point of view.

 

Hope it helps

Message 3 of 3

malcolm_341
Collaborator
Collaborator

Thanks for your help, it's the OpenMaya API I guess that I'm looking for because Python is not supported in Maya LT.

0 Likes