You could look into MSelectionList and MItSelectionList from the Open Maya module.
It lets you iterate over things quite fast. It is how Niels Peter and I traverse Geometry looking for issues in our model validation tool. It's probably not the fastest approach, but it is fairly straightforward to implement. You can look at the source code here for some examples: https://github.com/JakobJK/modelChecker/blob/master/src/modelChecker.py On Sat, 3 Apr 2021 at 21:00, João Victor <joaovictor...@gmail.com> wrote: > thanks a lot vince! > do u have any suggestion about how I can build this incidence matrix? > sorry, I have no idea. > > thanks! > > Em sábado, 3 de abril de 2021 às 21:06:16 UTC-3, vince touache escreveu: > >> if you're looking at querying many vertices per mesh, you might wanna >> building and caching an incidence matrix, instead of doing what you're >> doing now, that should save you a fair bit of redundancy >> >> Le samedi 3 avril 2021 à 18:47:40 UTC-4, joaovi...@gmail.com a écrit : >> >>> Hey Marcus! Thanks a lot for the suggestion! >>> As I understood in your code, you are getting the same vtx[10], right? >>> I was looking for something like this: >>> >>> >>> *#supposing this mesh has 100.000 vertices* >>> *for vtx in list_of_all_vertices_of_the_mesh: * >>> * vtxToEdges = cmds.polyListComponentConversion(vtx, fromVertex=True, >>> toEdge=True)* >>> * vtxToEdges = cmds.ls <http://cmds.ls>(edgeToVtx, flatten=True)* >>> * a = vtxToEdges* >>> >>> So it would get the edges around all 100.000 vertices and return 100.000 >>> different groups of edges (each one related to each vertex). >>> >>> The code above is taking 7.484 seconds, specially because I have to >>> flatten it, otherwise would take 2.047 seconds.. :/ >>> And I have to make it in 3 meshes, one of them needs more conversions, >>> sometimes from faces to vertices. >>> >>> So if there was a way to get it faster, instead throught conversions, >>> would be great to shrink down this time.. :) >>> >>> thanks a lot!!! >>> Em sábado, 3 de abril de 2021 às 17:22:49 UTC-3, Marcus Ottosson >>> escreveu: >>> >>>> Ok, I’m missing a lot of information haha. Let me try and fill in some >>>> gaps. >>>> >>>> Here’s finding edges for 1 vertex amongst 100,000 vertices. >>>> >>>> plane, _ = cmds.polyPlane(sx=1000, sy=100) >>>> cmds.scale(10, 1, 10) >>>> def measureMe(): >>>> vtx = plane + ".vtx[10]" >>>> cmds.polyListComponentConversion(vtx, fromVertex=True, toEdge=True) >>>> >>>> iterations = 100 >>>> result = timeit.timeit(measureMe, number=iterations) >>>> resultMs = result * 1000 >>>> resultPerIteration = resultMs / iterations >>>> print("%.2f ms/iteration" % resultPerIteration)# 0.50 ms/iteration >>>> >>>> It’s clocking in at half a millisecond. Now, is this what you mean by >>>> slow? What do you consider fast? What numbers are you hoping for? >>>> >>>> On Sat, 3 Apr 2021 at 21:00, João Victor <joaovi...@gmail.com> wrote: >>>> >>>>> Marcus, explanning better my previous email: >>>>> >>>>> For example, if I want to get the edges around this vertex, I would do >>>>> this: >>>>> >>>>> vtxToEdges = cmds.polyListComponentConversion(vtx, fromVertex=True, >>>>> toEdge=True) >>>>> >>>>> But it is taking too long in thousand loops. :/ >>>>> Em sábado, 3 de abril de 2021 às 16:58:01 UTC-3, João Victor escreveu: >>>>> >>>>>> Hey Marcus, thanks for replying. >>>>>> I have to loop it in thousands of times. >>>>>> converting with "polyListComponentConversion" takes too long. >>>>>> There is some way to get it, without having to convert? Or this is >>>>>> the only way? >>>>>> Im using API. >>>>>> thanks! >>>>>> >>>>>> Em sexta-feira, 2 de abril de 2021 às 13:29:12 UTC-3, Marcus Ottosson >>>>>> escreveu: >>>>>> >>>>>>> Faster than what? What have you tried and what was the performance >>>>>>> of it? >>>>>>> >>>>>>> On Fri, 2 Apr 2021 at 17:24, João Victor <joaovi...@gmail.com> >>>>>>> wrote: >>>>>>> >>>>>>>> Hey guys! >>>>>>>> Could somebody help me? >>>>>>>> >>>>>>>> What is the faster way to get vertices of a face? >>>>>>>> >>>>>>>> Simply converting the selecion? Or there is a smarter solution? >>>>>>>> >>>>>>>> Thanks! >>>>>>>> >>>>>>>> -- >>>>>>>> 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/dccecf9e-b015-487a-99e0-2581af29ff98n%40googlegroups.com >>>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/dccecf9e-b015-487a-99e0-2581af29ff98n%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_m...@googlegroups.com. >>>>> >>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/python_inside_maya/cfbdb039-4f09-4f0a-8fa3-d4c934f3c2ddn%40googlegroups.com >>>>> <https://groups.google.com/d/msgid/python_inside_maya/cfbdb039-4f09-4f0a-8fa3-d4c934f3c2ddn%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/dde82079-1103-4980-9442-5aa939563ad9n%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/dde82079-1103-4980-9442-5aa939563ad9n%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/CAEKd6bZ3Y%2BxJwJnz-Sq3RJpreqVS7hL3g8pJvE%3DpHiN0uPT9Ag%40mail.gmail.com.