Select object and link it to another object with maxscript

Hi everyone, I'm new to maxscript(also new to 3dsmax) and has been wondering whether the following can be done.
Here's the scenario
I am creating tank treads with "spline IK solver" according to a tutorial on youtube.
After creating the bones and tank treads, I have to connect an individual tread to a certain bone.
i.e
tread001 linked to bone001
tread002 linked to bone002
tread003 linked to bone003
the rest goes on repeatedly.

I first think of using a for loop to complete this task according to my previous matlab coding experiences.
However after a night of google search, I still can't find the syntax to assign my loop variable to the object name.
Can it be done in max or it should be done with a different logic?

Thank you!!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

Use this function

fn linker childName: parentName: =
(
	local childrens = #(), parents = #()
	for o in objects do 
	(
		if matchpattern o.name pattern:(childName+"*") ignoreCase:on do append childrens o.name
		if matchpattern o.name pattern:(parentName+"*") ignoreCase:on do append parents o.name
	)
 
	sort childrens ; sort parents
	--format "parents = % \nchildrens = %\n" parents childrens
	for c in childrens where (i = findItem parents (parentName+(trimleft c childName))) != 0 do
	(
		(getnodebyname c).parent = (getnodebyname parents[i])
	)
)
-- add base name of parent and child name in "shildName" and "parentName" arguments
linker childName:"tread" parentName:"bone"

bga

ryoreal's picture

Problem solved!! Thank you so much!!

Thank you so much for the help!!
I've been stuck at this point for 2 weeks.
I haven't got a complete understanding to this script yet but I'm already amazed.
I'm gonna dig in and study this script.

Thanks again for the help!!

barigazy's picture

...

Use maxscrpt help document. It will help a lot to understand any code

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.