Lock

Introduced

v4.0

Description

Locks an object and all its children, or lock a parameter.

Note: If you try to lock an object that is already locked, the History Pane displays the error message 'ERROR : "2087 - The object: is locked." and the command returns Nothing.

Scripting Syntax

Lock( [InputObjs], [Level] );

Parameters

Parameter Type Description
InputObjs String List of objects to lock. Can be objects or parameters.

Default Value: Current selection.

Level siLockLevel The lock level is a bit field value that represent a area that is locked. The maximum level is siLockLevelAll which is all the level combined. One or many level can be set on an object. When the level is 0 (siLockLevelNone) the lock is removed.

Default Value: siLockLevelAll

Examples

1. JScript Example

// JScript example that show basic lock and unlock usage

NewScene(null, null);

CreatePrim("Cone", "MeshSurface", null, null);

CreatePrim("Cylinder", "MeshSurface", null, null);

CopyPaste("cylinder", null, "cone", 1);

// This will lock in branch the cone. (the cylinder will also be locked.

Lock("B:Cone", siLockLevelAll);

// The object is locked so it cannot be modified, the following commented line

// for example would fail as follow: ERROR : "2009-EDIT-SetValue - Access denied"

// SetValue("cone.polymsh.geom.subdivu", 13, null);

// Now unlock the object in branch. 

SelectObj("cone", "BRANCH", null);

Unlock(null, siLockLevelAll, null, null);

// now the setvalue is working.

SetValue("cone.polymsh.geom.subdivu", 13, null);

2. JScript Example

// JScript example that show how to work with levels of locking.

NewScene(null, null);

CreatePrim("Disc", "MeshSurface", null, null);

CreatePrim("Cone", "MeshSurface", null, null);

Lock("cone", siLockLevelConstruction);

// The object is locked in construction, so we can change the parameters values but not the hierarchy.

// So this is working...

SetValue("cone.polymsh.geom.subdivu", 13, null);

// But not this...

//ERROR : "2087 - The object: cone is locked."

//ERROR : "2009-EDIT-CopyPaste - Access denied"

try {

CopyPaste("Disc", null, "cone", 1);

}

catch (e) {

	logmessage ("this is normal,since it is locked");

}

// Now add to the lock the manipulatio level that will prevent changing the parameter values.

Lock("cone", siLockLevelManipulation);

// Now this is not working...

//ERROR : "2087 - The object: cone.polymsh.geom.subdivu is locked."

//ERROR : "2009-EDIT-SetValue - Access denied"

try {

SetValue("cone.polymsh.geom.subdivu", 5, null);

}

catch (e) {

	logmessage ("this is normal,since it is locked");

}

// Display the lock level, ( in this case it is 5 which is siLockLevelConstruction & siLockLevelManipul

var oObj = GetValue("cone")

logmessage ("The level of lock for the cone is : " + oObj.LockLevel);

// Unlock just the construction level of the lock 

Unlock("cone", siLockLevelConstruction, null, null);

// Display the lock level, ( in this case it is 0 since by removing the construction level all other levels have been removed 

var oObj = GetValue("cone")

logmessage ("The level of lock for the cone is : " + oObj.LockLevel);

3. JScript Example

// JScript example that show how to lock a parameter

NewScene(null, null);

CreatePrim("Cone", "MeshSurface", null, null);

// This will lock only the subdivu parameter.

Lock("cone.polymsh.geom.subdivu", siLockLevelManipulation);

// The object is locked so it cannot be modified, for example this will fail.

//ERROR : "2009-EDIT-SetValue - Access denied"

try {

SetValue("cone.polymsh.geom.subdivu", 13, null);

}

catch (e) {

	logmessage ("this is normal,since it is locked");

}

// But the subdivv is working!

SetValue("cone.polymsh.geom.subdivv", 4, null);

// Now unlock the parameter.

Unlock("cone.polymsh.geom.subdivu", siLockLevelAll, null, null);

See Also

Unlock InspectLocks ProjectItem.SetLock ProjectItem.UnSetLock Parameter.SetLock Parameter.UnSetLock