Python API 2.0 MPlug attributes

Python API 2.0 MPlug attributes

Anonymous
Not applicable
2,139 Views
4 Replies
Message 1 of 5

Python API 2.0 MPlug attributes

Anonymous
Not applicable

I am trying to use the Python API 2.0 and MPlug in particular.  I can't find a way to lock the attribute.  There is a "isLocked" which gives a boolean result.  But how do you set the locked state?  The API 2.0 discussion says that the attributes should be available to be set directly.  But there is an error when trying MPlug.locked = True.  What am I missing?

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

vijaya.prakash
Alumni
Alumni

Hi,

 

In C++, you can use MPlug.setLocked(True) but in Python, you should use MPlug.setAttribute() with "lock" parameter.

 

Thanks,

Vijaya Prakash.

0 Likes
Message 3 of 5

vijaya.prakash
Alumni
Alumni

Hi,

 

Use the below python code to set the lock attribute, there is no specific API in Python 2.0 API in OpenMaya.

 

import maya.cmds as cmds

cmds.sphere( n="sphere" )
cmds.setAttr( 'sphere.translateX', 5 )
cmds.setAttr( 'sphere.translateX', lock=True )

 

Thanks,

Vijaya Prakash.

 

 

0 Likes
Message 4 of 5

Anonymous
Not applicable
Accepted solution

You are incorrect in your information.  API 2.0 does provide this functionality.  I assumed "isLocked" was read only.  It actually can be set as well.

 

MPlug.isLocked = True

Message 5 of 5

vijaya.prakash
Alumni
Alumni

Hi,

 

Yes, You are correct. there is no "setLocked()" API in OpenMaya Python 2.0. Instead we have to use "isLocked()" method for both setting the lock as well as checking the lock. Below is the actual documentation of isLocked() method.  It has both Read and Write access.

 

OpenMaya.MPlug.isLocked
static
 True if plug is locked against changes.
Name: isLocked
Type: bool
Access: RW
Description: True if plug is locked against changes.

 

 

Thanks,

Vijaya Prakash.

0 Likes