The performTopoSort function performs a topographical sort using Depth-First Search (DFS).
<Array> performTopoSort <int> <array <datapair <int, {<int> | array<int>} > > >The first argument is the number of tasks.
The second argument is an array of dependencies between tasks. Each dependency is a datapair where the first value is a task number and the second arg is either a task number or an array of task numbers. All task numbers must be in the range of [1 : # of tasks].
If a circular dependency exists, the value 'undefined' is returned.
Available in 3ds Max 2025 and higher.
EXAMPLE
-- Set up 6 tasks where 1 and 6 each depend on 2, and 4 depends on 1 and 6. Independent set where 3 depends on 5 performTopoSort 6 #(datapair 1 2, datapair 6 2, datapair 4 #(1, 6), datapair 3 5) --> #(5, 3, 2, 6, 1, 4) -- Set up 8 tasks where 8 depends on 1 and 4, 3 depends on 6 and 7, 7 depends on 1 and 4, 6 depends on 1 and 5, 5 depends on 1 and 4, and 4 depends on 2 performTopoSort 8 #(datapair 8 #(1, 4), datapair 3 #(6, 7), datapair 7 #(1, 4), datapair 6 #(1, 5), datapair 5 #(1, 4), datapair 4 2) --> #(2, 4, 1, 5, 6, 7, 3, 8) -- Set up 6 tasks where 1 depends on 4, 2 depends on 1, 3 depends on 1, and 4 depends on 2 and 3. Independent set where 6 depends on 5. -- Since 1 depends on 4, 4 depends on 2, and 2 depends on 1, a circular dependency exists, performTopoSort 6 #(datapair 1 4, datapair 2 1, datapair 3 1, datapair 4 #(2, 3), datapair 6 5) --> undefined