make a sphere and instance it

 >>> s1 = polySphere()[0]
 >>> s2 = instance(s1)[0]
 >>> s1
Transform(u'pSphere1')
 >>> s2
Transform(u'pSphere2')


get the shapes and their parents

 >>> shp1 = s1.getShape()
 >>> shp2 = s2.getShape()
 >>> shp1
Mesh(u'pSphere1|pSphereShape1')
 >>> shp2
Mesh(u'pSphere2|pSphereShape1')
 >>> shp1.getParent()
Transform(u'pSphere1')
 >>> shp2.getParent()
Transform(u'pSphere2')

so, as long as we have the full dag path, we get the correct parent.  
the same thing is true if we start from a string

 >>> PyNode(u'pSphere1|pSphereShape1').getParent()
Transform(u'pSphere1')
 >>> PyNode(u'pSphere2|pSphereShape1').getParent()
Transform(u'pSphere2')


however, if we do not provide the full dag path, we get the first  
instance.

 >>> PyNode(u'pSphereShape1').getParent()
Transform(u'pSphere1')

perhaps there's something more subtle that i'm missing.

-chad



On Apr 9, 2009, at 9:40 AM, Olivier Renouard wrote:

> But I think in the instance case it's not just a name thing. It's  
> actually the same dag node (shape) having multiple transforms.
>
> That's the reason why worldMatrix is a multiple attribute. Though  
> you usually use worldMatrix[0], in case of an instanced shape you  
> can have multiple worldMatrix :
>
> polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
> // Result: pCube1 polyCube1 //
> instance; move -r 1 0 0;
> getAttr pCube1.worldMatrix;
> // Result: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 //
> getAttr pCube2.worldMatrix;
> // Result: 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 //
> getAttr pCubeShape1.worldMatrix[0];
> // Result: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 //
> getAttr pCubeShape1.worldMatrix[1];
> // Result: 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 //
>
> Chad Dombrova wrote:
>>
>> I think it's ok in pymel's case because your shape will be a  
>> uniquely identified dagNode.
>>
>> -chad
>>
>>
>>
>> On Apr 9, 2009, at 6:33 AM, Sylvain Berger wrote:
>>
>>> ho yeah.... you are right... i'll check my code using the  
>>> getParent() function to see what appens... i'm guessing a fail :)
>>>
>>> Thanks
>>>
>>> On Thu, Apr 9, 2009 at 9:22 AM, Olivier Renouard 
>>> <[email protected] 
>>> > wrote:
>>> I think you would have to account for the cases where a single  
>>> shape can have more than one transform if you did that, ie instances
>>>
>>> Sylvain Berger wrote:
>>>>
>>>> Thanks for this great explanation.  It is not a big deal because  
>>>> I can always asume that the direct parent of a shape is the  
>>>> transform, so i can live with the getParent() method :)
>>>>
>>>>
>>>>
>>>> On Wed, Apr 8, 2009 at 4:47 PM, chadrik <[email protected]> wrote:
>>>>
>>>>
>>>> MEL supports automatic propagation from transforms to shapes:
>>>>
>>>> import maya.cmds as cmds
>>>> transform = cmds.polyCube()[0]
>>>> cmds.getAttr( transform + ".primaryVisibility" )
>>>> # Result: 1 #
>>>>
>>>> in the example above primaryVisibility is an attribute of the mesh,
>>>> but it can be accessed from the transform. PyMEL supports this same
>>>> transform-to-shape propagation in its object-oriented design:
>>>>
>>>> #continuing from the example above
>>>> pytrans = PyNode( transform )
>>>> pytrans.primaryVisibility.get()  # an attribute of Mesh
>>>> # Result: 1 #
>>>> pytrans.numVertices()  # a method of Mesh
>>>> # Result: 8 #
>>>>
>>>>
>>>> MEL does not support propagating back UP the dag.
>>>>
>>>> #continuing from the example above
>>>> mesh = cmds.listRelatives( transform, s=1 )[0]
>>>> cmds.getAttr(mesh + ".tx" )
>>>> # Error: Object pCubeShape3.tx is invalid
>>>> # Traceback (most recent call last):
>>>> #   File "<maya console>", line 1, in <module>
>>>> # TypeError: Object pCubeShape3.tx is invalid #
>>>>
>>>> Including this feature is worth considering, but i personally don't
>>>> feel that it is consistent with the conventions that have been
>>>> established in Maya: a transform "owns" a shape, but a shape does  
>>>> not
>>>> "own" a transform.
>>>>
>>>>
>>>> -chad
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> -- 
>>>> They say, "Evil prevails when good men fail to act." What they  
>>>> ought to say is, "Evil prevails."
>>>> Nicolas Cage as Yuri Orlov in Lord of War.
>>>>
>>>>
>>>
>>>
>>> -- 
>>> Olivier Renouard
>>>
>>>
>>>
>>>
>>>
>>>
>>> -- 
>>> They say, "Evil prevails when good men fail to act." What they  
>>> ought to say is, "Evil prevails."
>>> Nicolas Cage as Yuri Orlov in Lord of War.
>>>
>>>
>>>
>>
>>
>>
>
>
> -- 
> Olivier Renouard
>
> >


--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to