ScriptSpot home

Link Array (directional)

Downloads

Release history (1)
  • Version 1Listed version

    Listing updated

    No download linked to this version

3ds Max compatibility
Unknown
Community reviewsNo reviews yet.

Listing details

Version
1
Author’s update date
Legacy votes
14
Listing created
How compatibility works

Compatibility comes from the author’s supported range or requirements in the original listing. A tested version records what the author tried.

“2020 unconfirmed” in the catalog means support for 3ds Max 2020 is still unknown.

Community reports record successful tests on specific releases.

Posted by

JokerMartini

More by this author

Description

This code simply allows a users to link a selection of objects based on the order of selection. You can use either 0 or 1 to define the direction. That allows you to link everything forwards or backwards. Rather simple code but I figured someone would find use for it.


clearlistener()

fn fnLinkArray arr dir:0= (

if dir != 0 then (
reverseArr = for i = arr.count to 1 by -1 collect arr[i]
arr = reverseArr
)

for o in arr do o.parent = undefined

for i = 1 to (arr.count-1) do
(
child = arr[i]
parent = arr[i+1]
child.parent = parent
print (child.name + "---->" + parent.name)
)
)

fnLinkArray selection dir:0
fnLinkArray selection dir:1

Comments (3)
Panayot Karabakalov

I'm fine, thanks

Yeah, thats the idea to make the functions separate. This way they become re-usable for other scripts, the base logic then build function library.

JokerMartini

Hey Anubis - how's it going?

You definitely simplified it.
I had originally have two separate functions, one which reversed the array. I then decided to combine it into one.
I think it makes more sense to have it separate like you have posted above.

Essentially could make one function which just links the given array.
Then use other functions to build arrays out of selections.
That way users could use other functions to build arrays based on options, example being qsort based on distance from an object.
Then the user could decide whether or not they want to reverse it before running the linking function.

Just some ideas.

Panayot Karabakalov

Hey John

I hope its welcome to append similar function...

-- simple function
fn LinkArray arr = (
	for i = 1 to (arr.count - 1) do
	append arr[i].children arr[i + 1]
)

And if the main idea is to make it working with optional direction argument...

fn ReverseArray arr = ( -- operate on input array
	local delta = arr.count/2, zeta = arr.count+1
	for i = 1 to delta do swap arr[i] arr[zeta-i]
)

fn LinkArray arr = ( -- just link in order
	if arr.count > 0 do (
		arr.parent = undefined
		for i = 2 to arr.count do
		arr[i].parent = arr[i-1]
	)
)

-- mixin version with optional direction argument 
-- (used above 2 functions)
fn LinkArrayInDir arr dir:0 = (
	if dir != 0 do ReverseArray arr
	LinkArray arr
)

Cheers!