Also:
for cur in cur_list:
cmds.select(cur, add=True)
Can this not be done in a single call to select()?
On Thu, Jun 1, 2017 at 12:37 PM Michael Boon <[email protected]> wrote:
> Yeah read up on cProfile if you haven't already. It's really useful.
>
> This section looks very slow
> for edge in edges:
> vtx = cmds.ls(cmds.polyListComponentConversion(edge,fe=1,tv=1),fl=1)
> p1 = cmds.pointPosition(vtx[0])
> p2 = cmds.pointPosition(vtx[1])
> created_curve = cmds.curve(d=1,p=(p1,p2))
> cur_list.append(created_curve)
> The cmds.ls would be slow, and the cmds.curve would too, but without
> profiling I'm not sure if both are significant here.
> By switching to maya.api.OpenMaya and using an MFnMesh, you could iterate
> through the edges and find vertices much, much faster.
> I assume you could also create one big, complex curve instead of thousands
> of small ones. I'm not sure if you can do that using cmds or if you'd have
> to use the API for that too.
>
> Some stuff further down might need work too. I think you can select all of
> cur_list in a single call, for example: cmds.select(cur_list)
>
> This section:
> for obj in grp_list:
> list_all.extend(shape_list)
> list_all.extend(grp_list)
> will be very slow if grp_list is in the hundreds of thousands.
> I'm not sure you want to be adding both lists over and over again like
> that. You end up with a really gigantic list with a lot of duplicate
> entries, and it seems to be just so you can select it.
>
>
> On Thursday, 1 June 2017 10:08:19 UTC+10, Justin Israel wrote:
>
>>
>>
>> On Thu, Jun 1, 2017 at 11:48 AM likage <[email protected]> wrote:
>>
>>> I am trying to 'extract and convert' all the edges of the polygon (based
>>> on selection) into curves, then parent the curves as one. This is like a
>>> curve-based wireframe model.
>>>
>>> While Maya has a functionality that allows all edges to be converted
>>> into curves, but the functionality - "Polygon Edges to Curves", it works
>>> but not very ideal in my case as I would want all the created curves to be
>>> combined into one.
>>>
>>> import maya.cmds as cmds
>>> import pymel.core as pm
>>>
>>> edges =
>>> cmds.filterExpand(cmds.polyListComponentConversion(te=1),sm=32,ex=1)
>>> cur_list = []
>>> for edge in edges:
>>> vtx = cmds.ls(cmds.polyListComponentConversion(edge,fe=1,tv=1),fl=1)
>>> p1 = cmds.pointPosition(vtx[0])
>>> p2 = cmds.pointPosition(vtx[1])
>>> created_curve = cmds.curve(d=1,p=(p1,p2))
>>> cur_list.append(created_curve)
>>>
>>> # Select all the newly created curves
>>> for cur in cur_list:
>>> cmds.select(cur, add=True)
>>>
>>> # Get list of objects
>>> shape_list = pm.ls(pm.listRelatives(c=True))
>>> grp_list = pm.ls(pm.group(em=True, n='curve#'))
>>> list_all = []
>>> for obj in grp_list:
>>> list_all.extend(shape_list)
>>> list_all.extend(grp_list)
>>>
>>> # Parent (shape) objects to one Curve
>>> pm.select(list_all)
>>> pm.parent(r=True, s=True)
>>>
>>>
>>> While this code of mine does work, but if I tried to use it on a higher
>>> subdivision polygon, for example, create a normal pSphere and sets both its
>>> "Subdivisions Axis" and "Subdivisions Height" to 100, and execute the code
>>> I wrote.
>>> What happens here is that:
>>>
>>> - Maya seems to be hanging
>>> - Took a very long while to be process (seems to be more than 1 hour
>>> plus before that current maya session of mine crashes.)
>>>
>>> What can be done to minimize this long processing time? I am assuming
>>> that part of this 'long' time is due to the commands that I am using it to
>>> derive the vertex and creating them?
>>>
>>
>> Did you profile the different parts of your code to know for sure?
>>
>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/71af008c-fbce-46a8-b150-887888e300bb%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/71af008c-fbce-46a8-b150-887888e300bb%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/a5b72dff-2d28-40dd-9c98-5a02af3529b0%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/a5b72dff-2d28-40dd-9c98-5a02af3529b0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3uo8K%2BvqrASm_EBVsgM0HDk9DPKqSgKUr7BbbXHHShdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.