Hello! I can shed some light on these.

I tried to work the Python Loop part with C++ MPxCommand, but I couldn’t
find a way to return data by executing the Arguments in the form of
Float3Array (Point Positions) and the corresponding command. (Return :
IntArray)

If you are certain that looping isn’t going to be fast enough in Python,
which I don't doubt, then yes this is what I would do. You won’t be able to
return data outside of simple types like integers, floats and strings. But
what you can do is serialise the data into e.g. JSON and output a string,
and then deserialise it from Python. This is what I normally do. At a
certain point, deserialising can become a bottleneck, at which point you
have a JSON deserialiser in PySide2 which may be faster.

It is said that the part can be written in C++ using PyBind, but I know
that the For Loop speed is limited due to the same GIL issue. Is there any
way to solve it??

This point was what prompted me to reply - don’t do it! :D

Both MPxCommand and PyBind can work outside of any GIL - they are both
called outside of Python - and while PyBind *can* return more complex types
like vectors and even Python objects it is terribly inconvenient to work
with in Maya. Because Maya - and Python in general - cannot reload or
unload a binary Python module. Yes, you read that right. Once you import
myBinaryModule you cannot unload it. At all. The only recourse is
restarting Maya.

Other than that, if that isn’t a problem, then PyBind is a good option for
this. You can even pass a NumPy data structure, which would bypass Python
even further and keep all data - especially heavy data - in C++ and be as
fast as it can be.

It seems that there is no way to increase the speed of the current Python
Loop by raising the speed of the loop as much as possible.

Hard to say without having an example. Loops in Python shouldn’t be a
bottleneck in general; but it’s possible the repeated access to a Maya API
class could. Are you able to share a small reproducible? Would be curious
to see what the problem may be.

Best,
Marcus

On Fri, 23 Sept 2022 at 07:20, daeseok chae <cds7...@gmail.com> wrote:

> Hello,
>
> I am writing a script that extracts a Point located in a mesh using
> anyIntersection of MFnMesh.
>
> However, there are too many points, so the performance does not come out
> while looping.
>
> So I'm trying to find another way, but it's not easy to find example code.
> Here's the method I've tried:
>
> 1. I tried to work the Python Loop part with C++ MPxCommand, but I
> couldn't find a way to return data by executing the Arguments in the form
> of Float3Array (Point Positions) and the corresponding command. (Return :
> IntArray)
> 2. It is said that the part can be written in C++ using PyBind, but I know
> that the For Loop speed is limited due to the same GIL issue. Is there any
> way to solve it??
> 3. It seems that there is no way to increase the speed of the current
> Python Loop by raising the speed of the loop as much as possible.
>
> Loop Count : 1,000,0000 Under
> anyIntersection: 4 Direction (Up, Left, Right, Down)
>
> thank you
>
> --
> 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_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/cc20157f-7440-454a-a230-e5cd1d84e47en%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/cc20157f-7440-454a-a230-e5cd1d84e47en%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAVecqMiSvMHTnsYDOTsmLDW2XbBXrUxnc_W3J9a5TWAw%40mail.gmail.com.

Reply via email to