makeIdentity Won't Run Before Parent Command

117 views
Skip to first unread message

Kevin C. Burke

unread,
Oct 19, 2016, 11:42:06 PM10/19/16
to Python Programming for Autodesk Maya


Hello,
I'm trying to write a script for combining multiple NURBS curves. If I scale the curves, then try to combine them, they don't keep their transformations.

import pymel.core as pm

curves
= pm.selected()

for curve in curves:
    pm
.makeIdentity(curve, apply=True, translate=1, rotate=1, scale=1)

for curve in curves[1:]:
    shape
= curve.getShape()
    pm
.parent(shape, curves[0], relative=True, shape=True)
    pm
.delete(curve)


For some reason, the makeIdentity command (aka Freeze Transformations) won't run before the parent command. I've tried:
  • time.sleep
  • flushIdleQueue: froze Maya 2016
  • parenting the transforms to the master transform (curves[0], below) before running makeIdentity
If I take out the parent command, the makeIdentity works as expected.

I'm running out of ideas. Can anyone help please? Thank you!



Mahmoodreza Aarabi

unread,
Oct 20, 2016, 3:55:55 AM10/20/16
to python_in...@googlegroups.com
Hey man
For combining curve it is better to put all shapes of them inside one transform node.

Before:

Inline image 1

After:

Inline image 2

--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2d9a378d-8a1f-49a0-b60a-6c8d14ea39a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

Neil Roche

unread,
Oct 20, 2016, 5:47:26 AM10/20/16
to Python Programming for Autodesk Maya
Try assigning your sliced list (curves) to separate variables:


import pymel.core as pm

curves =pm.selected()
masterCurve = curves[0]
slaveCurves = curves[1:]

for crv in curves:
    pm.makeIdentity(crv, apply=True, translate=1, rotate=1, scale=1)

for crv in slaveCurves:   
    pm.parent(crv.getShape(), masterCurve, relative=True, shape=True)
    pm.delete(crv)

It works for me.

Neil

Kevin C. Burke

unread,
Oct 20, 2016, 9:48:42 PM10/20/16
to python_in...@googlegroups.com
Thanks Mahmoodreza & Neil for the help.

Neither of these worked for me, unfortunately.

First, I want the three shapes to appear within one transform. It is definitely possible if I do it manually, but through scripting, it's not working. I think it is better to only have one object to select in the Outliner, rather than three.

I have attached a Maya file with three curves. All of them have Scale transformations applied to them.

If I run my code or Neil's code, the Curves don't have makeIdentity applied to them before the parenting.

Here is a video demonstrating this and the Maya file is attached.

Any help on why this happens would be fantastic. Thank you!

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/gCuOuAXy4Uc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9ff2224a-5bdd-49c0-89e2-cb9e4c8e889f%40googlegroups.com.
ThreeCurves.zip

Neil Roche

unread,
Oct 21, 2016, 5:47:23 AM10/21/16
to Python Programming for Autodesk Maya
Your code is actually working, if you select a curveShape and switch to component mode you can see the NurbsCurve cvs are in the correct frozen position it's just that the curve shape has not been updated.  You can use the NurbsCurve.updateCurve() method to redraw the curve in the right position.

If you reselect the transform and run:

for shape in selected()[0].getShapes():
    shape.updateCurve()

But, strangely this won't work as part of the same script??




Neil Roche

unread,
Oct 21, 2016, 6:27:05 AM10/21/16
to Python Programming for Autodesk Maya
It's actually a Viewport 2.0 error, it's not redrawing the curves correctly.

Your code is fine and that's why it worked yesterday for me as well, I must have had Legacy Default Viewport set.


Neil Roche

unread,
Oct 21, 2016, 6:29:16 AM10/21/16
to Python Programming for Autodesk Maya
You also don't need to put the makeIdentity command into a loop, it can accept a list as an argument too.
Reply all
Reply to author
Forward
0 new messages