Re: [Maya-Python] Re: Find Compound Array Attribute, by Name

2018-08-27 Thread Marcus Ottosson
Thanks for confirming, Pedro!

On Tue, 28 Aug 2018 at 04:59, Pedro Bellini  wrote:

> Hey,
> First there is nothing wrong with the way you got it to work.
> Second, have you tried getting the plug straight from MSelectionList() ?
> it could work for you...
>
> ie.
>
> Yeah, maybe it works. If not, your way is fine too.
> from maya.api import OpenMaya
> from maya import cmds
>
> pma = cmds.createNode('plusMinusAverage')
> plug = OpenMaya.MSelectionList().add(pma+'.input3D[1].input3Dx').getPlug(0)
>
> plug.name()
> # Result: u'plusMinusAverage1.input3D[1].input3Dx' #
> plug.asFloat()
> # Result: 0.0 #
>
> plug2 = OpenMaya.MSelectionList().add('persp.t').getPlug(0)
>
> pcst = cmds.createNode('parentConstraint')
> plug3 =
> OpenMaya.MSelectionList().add(pcst+'.target[0].targetOffsetTranslate').getPlug(0)
> plug3.name()
> # Result: u'parentConstraint1.target[0].targetOffsetTranslate' #
> plug3.isCompound
> # Result: True #
>
> plug3b =
> OpenMaya.MSelectionList().add(pcst+'.target[0].targetOffsetTranslateX').getPlug(0)
> plug3b.asFloat()
> # Result: 0.0 #
>
> # for some reason this does not work in a few of attributes (not sure why)
> # rotatePivot
> plugFail = OpenMaya.MSelectionList().add('persp.rotatePivot').getPlug(0)
> # TypeError: item is not a plug #
> cmds.objExists('persp.rotatePivot')
> # Result: True #
>
> # which makes me get it the other way you mentioned
> fnDg =
> OpenMaya.MFnDependencyNode(OpenMaya.MSelectionList().add('persp').getDependNode(0))
> plugRp = fnDg.findPlug('rotatePivot', False)
> plugRp.isCompound
> # Result: True #
> plugRp.numChildren()
> # Result: 3 #
>
>
> Cheers.
>
>
> On Monday, August 27, 2018 at 7:22:31 AM UTC-7, Marcus Ottosson wrote:
>>
>> Hi all,
>>
>> I’m looking for how to query a compound plug within an array plug, by
>> name.
>>
>> With non-compound attributes, you can query plugs using the function set.
>>
>> from maya.api import OpenMaya as om
>> node = fn.create("wtAddMatrix")
>> fn = om.MFnDependencyNode()
>> nodeState = fn.findPlug("nodeState", False)
>>
>> Likewise, I can get to the compound plug and its first index like this..
>>
>> mplug = fn.findPlug("wtMatrix", False)assert mplug.name().rsplit(".", 1)[-1] 
>> == "wtMatrix"assert mplug.isArray and mplug.isCompound
>> first = mplug.elementByLogicalIndex(0)assert first.name().rsplit(".", 1)[-1] 
>> == "wtMatrix[0]"
>>
>> And I can guess my way to the weightIn attribute, by grabbing it by an
>> arbitrary index.
>>
>> # wtAddMatrix#   [0]#  .matrixIn#  .weightIn#   [1]#  .matrixIn# 
>>  .weightIn#..
>> weigthIn = first.child(1)assert weigthIn.name().rsplit(".", 1)[-1] == 
>> "weightIn"
>>
>> But how can I get to nested the wtAddMatrix.wtMatrix[0].weightIn
>> attribute by name?
>>
>> weightIn = ... # By name?
>>
>> Seeing as it’s the function set of a node that enables findPlug(), I
>> can’t figure out how to apply this to the MPlug itself.
>>
>> For the moment, I’ve “hacked” it by iterating through children till I
>> find a match.
>>
>> for index in range(first.numChildren()):
>>   child = first.child(index)
>>   if child.name().rsplit(".", 1)[-1] == "weightIn":
>> return child
>>
>> But it doesn’t look right.
>>
>> Any ideas?
>>
>> Best,
>> Marcus
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/81d19ff3-3192-4b9f-8bce-e991f1ab9a79%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODD27u8MfeJUd-809vZXzVxOfezRB8N1hZ7%2BfSfiatKww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: Find Compound Array Attribute, by Name

2018-08-27 Thread Pedro Bellini
Hey, 
First there is nothing wrong with the way you got it to work. 
Second, have you tried getting the plug straight from MSelectionList() ? it 
could work for you...

ie.

Yeah, maybe it works. If not, your way is fine too.
from maya.api import OpenMaya
from maya import cmds

pma = cmds.createNode('plusMinusAverage')
plug = OpenMaya.MSelectionList().add(pma+'.input3D[1].input3Dx').getPlug(0)

plug.name()
# Result: u'plusMinusAverage1.input3D[1].input3Dx' # 
plug.asFloat()
# Result: 0.0 # 

plug2 = OpenMaya.MSelectionList().add('persp.t').getPlug(0)

pcst = cmds.createNode('parentConstraint')
plug3 = 
OpenMaya.MSelectionList().add(pcst+'.target[0].targetOffsetTranslate').getPlug(0)
plug3.name()
# Result: u'parentConstraint1.target[0].targetOffsetTranslate' # 
plug3.isCompound
# Result: True # 

plug3b = 
OpenMaya.MSelectionList().add(pcst+'.target[0].targetOffsetTranslateX').getPlug(0)
plug3b.asFloat()
# Result: 0.0 # 

# for some reason this does not work in a few of attributes (not sure why)
# rotatePivot
plugFail = OpenMaya.MSelectionList().add('persp.rotatePivot').getPlug(0)
# TypeError: item is not a plug # 
cmds.objExists('persp.rotatePivot')
# Result: True # 

# which makes me get it the other way you mentioned
fnDg = 
OpenMaya.MFnDependencyNode(OpenMaya.MSelectionList().add('persp').getDependNode(0))
plugRp = fnDg.findPlug('rotatePivot', False)
plugRp.isCompound
# Result: True # 
plugRp.numChildren()
# Result: 3 # 


Cheers.


On Monday, August 27, 2018 at 7:22:31 AM UTC-7, Marcus Ottosson wrote:
>
> Hi all,
>
> I’m looking for how to query a compound plug within an array plug, by name.
>
> With non-compound attributes, you can query plugs using the function set.
>
> from maya.api import OpenMaya as om
> node = fn.create("wtAddMatrix")
> fn = om.MFnDependencyNode()
> nodeState = fn.findPlug("nodeState", False)
>
> Likewise, I can get to the compound plug and its first index like this..
>
> mplug = fn.findPlug("wtMatrix", False)assert mplug.name().rsplit(".", 1)[-1] 
> == "wtMatrix"assert mplug.isArray and mplug.isCompound
> first = mplug.elementByLogicalIndex(0)assert first.name().rsplit(".", 1)[-1] 
> == "wtMatrix[0]"
>
> And I can guess my way to the weightIn attribute, by grabbing it by an 
> arbitrary index.
>
> # wtAddMatrix#   [0]#  .matrixIn#  .weightIn#   [1]#  .matrixIn#  
> .weightIn#..
> weigthIn = first.child(1)assert weigthIn.name().rsplit(".", 1)[-1] == 
> "weightIn"
>
> But how can I get to nested the wtAddMatrix.wtMatrix[0].weightIn 
> attribute by name?
>
> weightIn = ... # By name?
>
> Seeing as it’s the function set of a node that enables findPlug(), I 
> can’t figure out how to apply this to the MPlug itself.
>
> For the moment, I’ve “hacked” it by iterating through children till I find 
> a match.
>
> for index in range(first.numChildren()):
>   child = first.child(index)
>   if child.name().rsplit(".", 1)[-1] == "weightIn":
> return child
>
> But it doesn’t look right.
>
> Any ideas?
>
> Best,
> Marcus
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/81d19ff3-3192-4b9f-8bce-e991f1ab9a79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Re: Get the current Maya session

2018-08-27 Thread Justin Israel
On Tue, Aug 28, 2018, 4:50 AM kiteh  wrote:

> Hi all, many thanks for getting back.
>
> It is upon the use of QSettings that I started to notice and wanted to
> implement checking conditions, as what Michael has mentioned, especially
> so, if there are 2 Maya sessions opened..
> Will look into implementing callbacks then.
>


Oh sorry. I thought you meant dealing with new sessions within one Maya
instance as opposed to "session" meaning a second Maya process.
QSettings has a "sync()" method, which usually is called automatically for
you when the QSettings is being destroyed. But you could call it manually
at points when you want to flush your changes to the file and to pick up
external changes. You can still have to instances stomping on each other
but at least they can be writing their changes sooner instead of on Maya
shut down.
For multiple instances of Maya, you could check the process list for
running pids.


> Thanks again!
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/3c806381-a6b4-4aaf-8db7-366c88ae871a%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3eLK6-%2Bdk6h03psiwJRKj6EMMG4ZUim-eNX3zAP%3DW8pg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: Maya API: rotate around certain point without affecting rotate pivot

2018-08-27 Thread igo rov
Hi thanks, 
your code has some helpful information for me...
this is what i got so far, though the locator is no vertex... and you have 
to execute first part, then rotate reference locator and then execute 
second part. Since api 1.0 has no" MMatrix.setElement" I find the very 
useful MTransformationMatrix. But as always when using API I find myself 
going long and indirect ways to reach my goal...

import maya.OpenMaya as om

# execute this to initialize the selections and get the positions

selCube = om.MSelectionList()
selCube.add("pCube1")
mDagCube = om.MDagPath()
selCube.getDagPath(0, mDagCube)
fnTransCube = om.MFnTransform(mDagCube)
posCube = fnTransCube.translation(4)

selLoc = om.MSelectionList()
selLoc.add("locator1")
mDagLoc = om.MDagPath()
selLoc.getDagPath(0, mDagLoc)
fnTransLoc = om.MFnTransform(mDagLoc)
posLoc = fnTransLoc.translation(4)

# execute this to get the hypothetical child Matrix
vec = posCube - posLoc 

mChildTransMatr = om.MTransformationMatrix()
mChildTransMatr.setTranslation(vec, 4)
childMatr = mChildTransMatr.asMatrix()

# now you can move and rotate your parent object and again get his matrix
parentMatr = mDagLoc.inclusiveMatrix()


# this gets the child's world matrix
childWorldMatr = childMatr * parentMatr

# last step is to apply the matrix to the hypothetical child
chMatr = om.MTransformationMatrix(childWorldMatr)
quatRotation = om.MQuaternion()
rot = chMatr.rotation()
trans = chMatr.translation(4)
fnTransCube.setTranslation(trans, 4)
fnTransCube.setRotation(rot,4)



Am Montag, 27. August 2018 05:22:13 UTC+2 schrieb Pedro Bellini:
>
>  Hi, see if this works
>
> Basically you need to compute the transformation matrix that represents 
> the rotation from a specific point ("vertex" in your case). That can be 
> generally done by matrix composition m1*m2-1*transform*m2. Where m1 is 
> the matrix of the object you want to move, m2-1 is the inverse matrix of 
> the object you want to use as reference (parent space), transform is your 
> rotation matrix, then you move it back to world by multiplying back m2.
>
> A quick example in maya can look like this:
>
> from maya.api import OpenMaya
> from maya import cmds
>
> cube = cmds.polyCube()[0]
> vtx = cube+'.vtx[2]'
> vtx_pos = cmds.xform(vtx, q=1,ws=1,t=1)
> # vertex does not have orientation, so will keep world
> # you can use vertex normals or custom...
> # ill just extract the position
> vtx_world_mmat = OpenMaya.MMatrix()
> for i in xrange(3):
> vtx_world_mmat.setElement(3,i, vtx_pos[i])
>
> grp = cmds.createNode('transform')
> cmds.xform(grp, t=(5,0,0))
> obj = cmds.polyPrism()[0]
> cmds.parent(obj,grp,r=1)
> obj_world_mat = cmds.xform(obj, q=1,ws=1,m=1)
>
> # compose the rotation matrix however you want, ill just make from euler 
> rotation
> rot_eu = OpenMaya.MEulerRotation()
> rot_eu.y=3.1415*.5 # 90 deg (ish)
> rot_mmat = rot_eu.asMatrix()
>
> obj_world_mmat = OpenMaya.MMatrix(obj_world_mat)
>
> # transform
> *resulting_mmat = obj_world_mmat * vtx_world_mmat.inverse() * rot_mmat * 
> vtx_world_mmat*
> # rotate
> cmds.xform(obj, ws=1, m=list(resulting_mmat))
>
> If I understood you correctly this should be it.
>
> Cheers.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/07851383-12c6-4119-b941-ee486a1e94c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: Get the current Maya session

2018-08-27 Thread kiteh
Hi all, many thanks for getting back.

It is upon the use of QSettings that I started to notice and wanted to 
implement checking conditions, as what Michael has mentioned, especially 
so, if there are 2 Maya sessions opened..
Will look into implementing callbacks then.

Thanks again!

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/3c806381-a6b4-4aaf-8db7-366c88ae871a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Find Compound Array Attribute, by Name

2018-08-27 Thread Marcus Ottosson
Hi all,

I’m looking for how to query a compound plug within an array plug, by name.

With non-compound attributes, you can query plugs using the function set.

from maya.api import OpenMaya as om
node = fn.create("wtAddMatrix")
fn = om.MFnDependencyNode()
nodeState = fn.findPlug("nodeState", False)

Likewise, I can get to the compound plug and its first index like this..

mplug = fn.findPlug("wtMatrix", False)assert mplug.name().rsplit(".",
1)[-1] == "wtMatrix"assert mplug.isArray and mplug.isCompound
first = mplug.elementByLogicalIndex(0)assert first.name().rsplit(".",
1)[-1] == "wtMatrix[0]"

And I can guess my way to the weightIn attribute, by grabbing it by an
arbitrary index.

# wtAddMatrix#   [0]#  .matrixIn#  .weightIn#   [1]#
.matrixIn#  .weightIn#..
weigthIn = first.child(1)assert weigthIn.name().rsplit(".", 1)[-1] == "weightIn"

But how can I get to nested the wtAddMatrix.wtMatrix[0].weightIn attribute
by name?

weightIn = ... # By name?

Seeing as it’s the function set of a node that enables findPlug(), I can’t
figure out how to apply this to the MPlug itself.

For the moment, I’ve “hacked” it by iterating through children till I find
a match.

for index in range(first.numChildren()):
  child = first.child(index)
  if child.name().rsplit(".", 1)[-1] == "weightIn":
return child

But it doesn’t look right.

Any ideas?

Best,
Marcus

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOArKjOKBYpeAYtq0HOHqzquPkSDCJ8%2BGTHEsNM2LEtW3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.