Parent into underworld?

Parent into underworld?

FirespriteNate
Advocate Advocate
639 Views
2 Replies
Message 1 of 3

Parent into underworld?

FirespriteNate
Advocate
Advocate

Is there any way to parent an existing transform into a curves underworld? It seems you can create a transform node directly in the underworld, but you can't re-parent one into it đŸ˜•

Here's some code to demonstrate:

# first create an ordinary NURBS curve:
curve = cmds.curve(d=1, p=((-2,0,0),(2,0,0)))
curveShape = cmds.listRelatives(curve, shapes=True)[0]

# this works fine, I get a transform UNDER the shape (underworld)
cmds.createNode('transform', p=curveShape)

# this variant however doesn't work, no matter what flags used :(
tr = cmds.createNode('transform')
cmds.parent(tr, curveShape)

I've tried all the different parent flags (shape=True, etc..) but nothing seems to work. Does anyone know if it's even possible? seems stupid that the former method works fine, but the parent command doesn't.

Accepted solutions (1)
640 Views
2 Replies
Replies (2)
Message 2 of 3

jmreinhart
Advisor
Advisor
Accepted solution

Yep, seems like the parent command can't do it. But you can do it using the maya API

import maya.api.OpenMaya as om2

sel = om2.MSelectionList()
sel.add('curveShape1')
sel.add('null1')
crv = sel.getDagPath(0)
grp = sel.getDependNode(1)

om2.MFnDagNode(crv).addChild(grp)

I'm curious, is there a practical reason to do this? The only time I've encountered it in vanilla Maya is using the projectCurveOnSurface functionality.  

Message 3 of 3

FirespriteNate
Advocate
Advocate

Thanks for that, I considered trying the API to do it, but before I could muster up the motivation to look into it I realised what I was trying to do was futile, so I abandonded the idea.

I was making a context tool that allowed users to drag over any meshes in the scene that were being conformed to an underlying curve. As they drag over the mesh I find the associated point on the driver curve and wanted to display it using a paramDimension. However, there could be many mesh-curve objects in the scene and I wanted to only create one paramDimension node and then re-parent it to whichever curve was under the mesh the user dragged over, rather than having to create one for every curve and keep track of and delete them as the user drags.

However, after posting I realised this was not really the way I wanted the context to ultimately work, so I ditched the idea, but thanks for the reply anyway, it's useful to know.

0 Likes