How To ... Develop A Transform Lock Script

How To > Develop A Transform Lock Script

This simple tutorial is based on an actual real-world case – a 3ds Max user wanted to create a button to check all 9 checkboxes in the Hierarchy Panel>Link Info > Locks. Unfortunately, he discovered that the MacroRecorder does not output any code for this operation.

Below are the steps required to solve this case including searching the index of this Online Help...

Related Topics:

Defining Macroscripts

General Node Properties

NATURAL LANGUAGE

Open a new Script Editor by going to MAXScript>New Script in the Main menu.

Search the Online Help and locate a method that affects the Transformation locks.

  • Open the Online Help

  • Go to the "Search" tab of the Help System

  • Enter in the search field: "lock all transform" and press Enter

  • The first result (Rank 1) returned is "Node Common Properties, Operators and Methods".

  • Note that all occurrences of the search words will be highlighted in the help page.

  • Scroll down until you see the "setTransformLockFlags".

  • Copy the line and paste it into a new script editor.

  • Keep the Help file open for further reference.

Create a macroScript to be able to use the script as a button, menu item or shortcut.

Call the method for the current scene selection.

MAXSCRIPT

macroScript LockAllTransforms category: "HowTo"
(
setTransformLockFlags selection #all
) 

Step-By-Step:

macroScript LockAllTransforms category:"HowTo" (

The macroScript will be called LockAllTransforms. To use the script, you can go toMain Menu > Customize > Customize User Interface..., locate the category "HowTo"and drag the script to a toolbar, a menu, a quad menu or assign to a keyboard shortcut.

Defining Macro Scripts

setTransformLockFlags selection #all

The Help definition of this method lists it as --mapped. This means that it can be applied directly to a collection of objects without an additional MAXScript for loop. In our case we will use the current scene selection – the method will be called for each object in the selection.

General Node Properties

)

Using the Script

Evaluate the script. To use it, you can use Customize... to drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or to assign to a keyboard shortcut. Select some objects and launch the script – all checkboxes under Hierarchy Panel>Link Info > Locks will be checked.

Where to go from here

As already mentioned, by just replacing the #all keyword with #none, the script can be altered to uncheck all boxes instead. Feel free to write a second macroScript (probably called UnlockAllTransforms) for this operation...

Also note that in 3ds Max 4, the setTransformLockFlags method wasn’t mappable. In case you want your script to be backwards compatible with that version, you could use a for loop to change each object separately. The code would look like

for i in selection do setTransformLockFlags i #all

Update

Some users who did this tutorial in 3ds Max 5 actually went even further and tried to use the general BitArray access to the Lock Flags. Here are some details about the usage of BitArrays in this case.

The setTransformLockFlags method description under General Node Properties explains that there are 9 bits in the BitArray corresponding to the position, rotation and scale locks.

A BitArray is a list of binary values (bits) which can be either True or False. A BitArray is defined by # followed by curly braces {} containing the indices of the True bits separated by commas. For example, #{1,4,7} will set only the X-axis locks of all 3 categories to True.

When multiple bits are set to True, they can be written as the first and last index separated by .., for example #{1..9} defines a BitArray of 9 elements all of which are set to True. It would be equivalent to the #all flag when using with the setTransformLockFlags method. #{} would be equivalent to the #none flag. #{1..3} would only check the first 3 Locks while turning the other 6 off and so on.

Feel free to experiment with the BitArray values and define further macroScripts to set only the Position, the Rotation or the Scale locks.

Back to

"How To" Tutorials Index Page