MaxScript Help - sorting delimited strings into multidimensional array

MaxScript Help - sorting delimited strings into multidimensional array

Anonymous
Not applicable
1,386 Views
4 Replies
Message 1 of 5

MaxScript Help - sorting delimited strings into multidimensional array

Anonymous
Not applicable

Running into a roadblock with this script and can't figure out how to proceed. I have an inkling I should be using some kind of recurssive script, but just get lost when dealing with Nth dimensional arrays.

Sort these arrays of a delimited string names:
#("SelectionGroup","All")
#("SelectionGroup","Legs","IK")
#("SelectionGroup","Legs","Left","IK")
#("SelectionGroup","Legs","Right","IK")
#("SelectionGroup","Torso")

Into a single multi-dimensional array like this:
a_names[1] = "All"
a_names[2] = "Legs"
a_names[3][1] = "IK"
a_names[3][2] = "Left"
a_names[3][2][1] = "IK"
a_names[3][3] = "Right"
a_names[3][3][1] = "IK"
a_names[3] = "Torso"

 

Any suggestions?

0 Likes
Accepted solutions (2)
1,387 Views
4 Replies
Replies (4)
Message 2 of 5

michael_lawler
Enthusiast
Enthusiast
Accepted solution

I don't have time to cook-up the script for you... but these links should give you all the info you need to accomplish what you want to achieve:

 

http://www.scriptspot.com/forums/3ds-max/general-scripting/example-how-to-sort-multidimensional-arra...

 

http://www.scriptspot.com/3ds-max/scripts/multi-dimensional-array-support

 

http://stackoverflow.com/questions/24717682/store-multidimensional-array-in-modifier-with-maxscript

 

Hope that you find this helpful.  Good luck. Smiley Wink

0 Likes
Message 3 of 5

Anonymous
Not applicable
Accepted solution

Is this what you are looking for?

 

function insertTree nodes parent =
(
	local name = nodes[1]
	local node = undefined

	for existingNode in parent where existingNode[1] == name do
	(
		node = existingNode
		break
	)

	if node == undefined then 
	(
		node = #(name)
		append parent node
	)

	if nodes.count > 1 then 
	(
		local children = (for i = 2 to nodes.count collect nodes[i])
		insertTree children node
	)
)

selectionGroups = #(
	#("SelectionGroup", "All"),
	#("SelectionGroup", "Legs","IK"),
	#("SelectionGroup", "Legs","Left","IK"),
	#("SelectionGroup", "Legs","Right","IK"),
	#("SelectionGroup", "Torso")
)

a_names = #()

for selectionGroup in selectionGroups do
(
	local nodes = for i = 2 to selectionGroup.count collect selectionGroup[i]
	insertTree nodes a_names
)

format "\n%\n" a_names

 The output of this script is

#(#("All"), #("Legs", #("IK"), #("Left", #("IK")), #("Right", #("IK"))), #("Torso"))

 

 

0 Likes
Message 4 of 5

michael_lawler
Enthusiast
Enthusiast

@Anonymous-- if you assign your result to his example variable "a_names" and then try to index into the array your script doesn't quite return the results he's wanting, in comparison yours returns the following (e.g.):

 

a_names[1]
#("All")


a_names[2]
#("Legs", #("IK"), #("Left", #("IK")), #("Right", #("IK")))


a_names[3][1]
"Torso"

 

...one of the links I posted provides a method to do the indexing like he's wanting.

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks for the links and code examples. You've put me on the right track.

0 Likes