Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Can't Parent NURBS Curves with Transformations

Can't Parent NURBS Curves with Transformations

blastframe
Enthusiast Enthusiast
1,218 Views
1 Reply
Message 1 of 2

Can't Parent NURBS Curves with Transformations

blastframe
Enthusiast
Enthusiast

Hi,
I have a script that combines NURBS curves. Curves with transforms, however won't freeze their transformations before parenting.

For example, I create two NURBS curves. I scale one down. I select the outer Curve (with no scale), then the inner Curve with a scale transformation. 

Curve_with_Transform.PNG

Then I run this script.

import pymel.core as pm

#creating a list of the selected Curves' transforms
transforms = pm.ls( selection=True, type="transform")

#freezing transformations on all Curves transforms
pm.makeIdentity( apply=True, translate=1, rotate=1, scale=1 )

#seems to have worked at this point...
for x in transforms:
    print (x.getTranslation(),x.getRotation(),x.getScale())
#(dt.Vector([0.0, 0.0, 0.0]), dt.EulerRotation([0.0, 0.0, 0.0]), [1.0, 1.0, 1.0])
#(dt.Vector([0.0, 0.0, 0.0]), dt.EulerRotation([0.0, 0.0, 0.0]), [1.0, 1.0, 1.0])

#selecting the shapes within the Curves transforms
pm.pickWalk( type='nodes', direction='down')

#creating a list of the shapes
shapes = pm.ls( selection = True )

#reselecting the transforms
pm.select( transforms )

#removing the first shape from the list so it doesn't get parented to its own transform
shapes.pop(0)

#selecting the shapes list
pm.select( shapes )

#selecting the first transform last so it will be the parent transform
pm.select( transforms[0], add=True )

#parenting the selected shapes to the selected transform
pm.parent( relative=True, shape=True )

 

 

For some reason, the makeIdentity command (AKA Freeze Transformations) doesn't happen before the parenting and any NURBS curve with a transform, rotation, or scale selected AFTER a curve with a different transform gets resized.

 

If I freeze transformations, then run this script, it works correctly.

 

How can I make sure that makeIdentity has been run before I run the parent command? Thank you!

0 Likes
1,219 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Hi blast

 

This is a really strange one, and it turns out that this is a bug in Maya. It looks like it was introduced in version 2016.

 

I was having a play with your code and tried a few things out but ended up with the same issue as you. In the end I tried to boil your code down to a very small bit of MEL and tried to execute it in all versions from 2014 up to 2017. in 2014 and 2015 its fine, but in 2016 and up it is broken.

 

I would suggest that this needs to be reported as a bug. (Any Autodesk support guys who are viewing this, please take note). Here are simple repro steps:

 

1) Run this script (Maya 2016 or above) which will create 2 circles and scales one of them up, and then selects them

 

// Create the two circles
string $circle1[] = `circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1`;
string $circle2[] = `duplicate -rr`;
scale -r 4 4 4;

// Select them
select $circle1[0] $circle2[0];

2) Now run this script which should freeze transforms and re-parent the shape of one circle to the transform of another

 

// Now run the code which "should" work but doesn't...
string $transforms[] = `ls -sl -type "transform"`;
string $shapes[] = `ls -dag -sl -type "nurbsCurve"`;
makeIdentity -apply true $transforms;
parent -r -shape $shapes[1] $transforms[0];

You will see the circle doesn't seem to have had its CVs baked and they end up being the same size.

 

 

However!

 

One thing I noticed while doing this was that if I ran both of the above snippets as a single script, the operation actually succeeded...!?? Whereas if I run them separately it fails. WTF??

 

I can only assume that the actual baking down of information from the transform to the shape isn't happening at the right time during the makeIdentity command.

 

So this led me on to thinking that you could work around your problem by actually creating and re-parenting your circles in the same execution call. I don't know if this is any good to you but if you add a duplicate call just after selecting the curves, the operation will work on the duplicated versions and for some reason the makeIdentity call actually does what its supposed to:

 

// Put this just after the circles have been selected
string $dups[] = `duplicate -rr`;

// Now do the rest of your code which seems to work ok
string $transforms[] = `ls -sl -type "transform"`;
string $shapes[] = `ls -dag -sl -type "nurbsCurve"`;
makeIdentity -apply true $transforms;
parent -r -shape $shapes[1] $transforms[0];

My apologies that I have written the solution in MEL but I find it easier to quickly write MEL. This solution should work fine with your python code. The only issue with this is that you will now have duplicates of your objects, but a simple call to "delete" should solve that I guess.

 

Hope this helps

 

Cheers

 

Mike

0 Likes