issues with shape parenting script

73 views
Skip to first unread message

vilkdage

unread,
Sep 27, 2016, 8:37:02 AM9/27/16
to Python Programming for Autodesk Maya
Any ideas why it only works on shapes with surfaces (polygon and NURB primitives, but not curves or Volume Primitives)?


import pymel.core as pm

selected = pm.ls (selection = True)
if len(selected) == 1:
    pm.warning('Must select 2 or more objects...');
elif len(selected) >= 2:
    selected.reverse()
    sel_end = selected[0]
    sel_child = selected[1:]
    pm.parent(sel_child, sel_end)
    for allObjects in sel_child:
        pm.makeIdentity(allObjects, a = True, t = True, r = True, s = True)
        findShape = pm.listRelatives(allObjects, s = True, ad = True)
        pm.select(d = True)
        pm.parent(findShape, sel_end, r = True, s = True)
        pm.delete(allObjects)
        pm.select()

Justin Israel

unread,
Sep 27, 2016, 5:20:12 PM9/27/16
to Python Programming for Autodesk Maya
Can you be more specific about what doesn't work as expected?


--
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/07de4863-5a93-4e4e-8902-49cb68326774%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vilkdage

unread,
Sep 27, 2016, 11:49:37 PM9/27/16
to Python Programming for Autodesk Maya
Sure.
If you were to run a script on objects with surface you will notice that they do not move from where they were. Their shapes has been parented and now they move as one object while staying in different positions in the world.

On the other hand, curves children jumps into place where their parent is. That is a problem as I want them not to move from their original position.

Justin Israel

unread,
Sep 29, 2016, 6:23:25 PM9/29/16
to python_in...@googlegroups.com
When I make the following changes, it works for me:

import pymel.core as pm

selected = pm.ls (selection = True)
if len(selected) == 1:
    pm.warning('Must select 2 or more objects...');
elif len(selected) >= 2:
    selected.reverse()
    sel_end = selected[0]
    sel_child = selected[1
:]
    pm.parent(sel_child, sel_end, a=True) # <-- absolute

    for allObjects in sel_child:
        pm.makeIdentity(allObjects, a = True, t = True, r = True, s = True)
        findShape = pm.listRelatives(allObjects, s = True, ad = True)
        pm.select(d = True
)
        pm.parent(findShape, sel_end, a = True, s = True) # <-- absolute
        pm.delete(allObjects)
        pm.select()

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.
Message has been deleted

vilkdage

unread,
Sep 30, 2016, 3:03:36 AM9/30/16
to Python Programming for Autodesk Maya
it still offsets, but what I found that works is if i run this script first:

import pymel.core as pm
selected = pm.ls(sl=True)

if len(selected) == 1:
    pm.warning('Must select 2 or more objects...');
elif len(selected) >= 2:
    selected.reverse()
    sel_end = selected[0]
    sel_child = selected [1:]
    locator = pm.spaceLocator()
    constraint = pm.parentConstraint(sel_end, locator)
    pm.delete(constraint)
    piv = pm.xform (locator, piv=True, q=True, ws=True)

    pm.parent(sel_child, sel_end)
    for allObjects in sel_child:
        pm.xform(allObjects, ws=True, piv=(piv[0], piv[1], piv[2]))

        pm.makeIdentity(allObjects, a = True, t = True, r = True, s = True)
    pm.delete(locator)
    pm.select(selected)


and without deselecting anything I run this part:


for allObjects in sel_child:

    findShape = pm.listRelatives(allObjects, s = True, ad = True)
    pm.select(d = True)
    pm.parent(findShape, sel_end, r = True, s = True)
    pm.delete(allObjects)
    pm.select()    


I have no idea why I can't combine these two parts, but it works and curves maintain offset.
Thanks a bunch for help! I will keep in mind that I should not forget "a" flag
Reply all
Reply to author
Forward
0 new messages