write "Set Matrix to Identify" in python?

write "Set Matrix to Identify" in python?

sabathyus00
Participant Participant
948 Views
4 Replies
Message 1 of 5

write "Set Matrix to Identify" in python?

sabathyus00
Participant
Participant

sabathyus00_0-1670695297050.png

Does anyone know the secret to zero out an offsetParentMatrix?  how to write  the equivalent of "Set Matrix To Identify "(per picture) in python?   I'm getting no help from online or Echo All Commands. 

Accepted solutions (1)
949 Views
4 Replies
Replies (4)
Message 2 of 5

saihtam
Collaborator
Collaborator
Accepted solution

That UI is just a little shortcut to edit the offsetParentMatrix that lives on the transform. So all you'd have to do is create an identity matrix and set that on the offsetParentMatrix. Like this(code tested on 2023, where you don't need the * before identity matrix. I believe in Python 2.7 we need that):

identity_matrix = [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
cmds.setAttr('pSphere1.offsetParentMatrix', *identity_matrix, type='matrix')
- Mathias
Message 3 of 5

sabathyus00
Participant
Participant

Huge thanks!   I'm curious.  What purpose does the '*' do?  It seems to work in python 2.7 without it.

Message 4 of 5

saihtam
Collaborator
Collaborator

The * unpacks a list in Python if you put it in front of a list. There are some commands in Maya that expected values to be passed in as multiple arguments, instead of a list of values. So the difference between

someFunction(a, [b, c, d])

 and

someFunction(a, b, c, d).

Having to pass in each value by it self could be a pain, especially if you have long lists, like using setAttr, which you could use to set weights. So imagine having to do this for however many verts you have

cmds.setAttr('def.weightList[0].weights', 0.121, 0.2335, 0.23423, 0.1324 [and keep going until you've done all the values])

Instead you could use * to have Python unpack the list for you. So you could do this instead

cmds.setAttr('def.weightList[0].weights', *weights)

Which is exactly what I'm doing with my weight code. Hope that clears it up, if not, let us know 🙂

- Mathias
Message 5 of 5

sabathyus00
Participant
Participant

thank you!

0 Likes