How to: Automate Linking process using MaxScript

A detailed tutorial guide that demonstrates how to automate linking process in 3ds max and link multiple objects with the help of Maxscript.

In this short tutorial I will be showing you a great trick that you can use to automate the linking process in 3ds max with the help of Maxscript.

You can, however, link objects together with the help of Select and Link tool but it would be real pain if you want to create a hierarchy of, let’s say, 50 objects.

No worries, we can easily link multiple objects through Maxscript. Let’s go ahead and learn how to do it.


Step 1

Objects for Linking

Here, I have 5 boxes and I want to link them together. Linking of the boxes will go like:

Box01 > Box02 > Box03 > Box04 > Box05

where Box01 being the leaf and Box05 being the root in the hierarchy.


Step 2

The resulting hierarchy will be based on the selection order so we have to be careful while selecting the objects. Let’s take a look at this example to understand how exactly selection order can affect the linking.

Select these objects following an order (5,3,2,4,1) then go to Maxscript Listener and write Print Selection. Press Shift + Enter key on your keyboard to execute the command.

The Selection Order

Notice that we got the objects printed in the same order that we have used during selection. 3ds max remembers the selection order of the objects so, whenever we execute a Maxscript, it goes through each object as per the selection order.

Since we are using Maxscript for the linking, the selection order will affect the resulting hierarchy. I would recommend using Paint Selection Region tool for selection purpose.



Step 3

Now, let’s go ahead and select all the 5 boxes with the help of Paint Selection Region tool. Once we have our selection, the only thing we have to do is to write a simple script to automate the linking process.

Go to Scripting menu and choose Maxscript Editor… from the menu. Now, write the script given below.

for i=1 to selection.count do
(
	$[i].parent = $[i+1]
)

Press Ctrl + E to evaluate the script and we are done. This script will link the current object to the object that comes next in the selection and create a parent-child relationship between them.


Step 4

To check the linking you can select and move the individual object or just go to Graph Editors > New Schematic View…. There you can easily see that the objects have been correctly linked together.

Checking the Linking

I hope you enjoyed this tutorial and learn something new and useful. If you have any questions or suggestions just comment them below or send them to me via email. Thanks!