Notifications
Clear all

[Closed] Select, Align and Parent

I have little to no max script experience.
Hello I have hundreds of cars that i need to attach to paths.
I have already placed and animated dummies on the path
Lets say i have
Car001 & Dummy001
+
Car002 & Dummy002

i need to automate the selection, alignment and parenting of
Car001 to Dummy001
and then
Car002 & Dummy002
etc etc

thanks

6 Replies

This might work for you. If the objects are named as you said. Just change numberOfCars to whatever you need.

I don’t see the need to select anything if you just want to align and parent things.


(
	--NUMBER OF CARS TO OPERATE ON
	numberOfCars = 200
	car = "Car"
	dum = "Dummy"
	
	--FUNCTION TO ADD LEADING ZEROS TO NUMBERS
	fn Pad val =
	(
		str = val as string
		if val < 10 do str = "0" + str
		if val < 100 do str = "0" + str
		str
	)
	
	undo "Align Cars" on
	(
		--LOOP THROUGH THE CARS AND LINK THEM TO DUMMIES
		for i = 1 to numberOfCars do
		(
			carObj = getNodeByName(car + Pad i)
			dumObj = getNodeByName(dum + Pad i)
			
			if carObj != undefined and dumObj != undefined do
			(
				carObj.transform = dumObj.transform
				carObj.parent = dumObj
			)
		)
	)
)

all above is correct… let’s try to make a little cleaner:

source_base = "car"
target_base = "dummy"
for d in objects where (k = findstring d.name target_base) != undefined do
(
    source_name = replace d.name k target_base.count source_base
    if (sources = getnodebyname source_name all:on).count > 0 do
    (
        sources.parent = d
        sources.transform = d.transform
    )
)

(sorry but i don’t have a chance to test the code in max… the code is written blind and sent from my phone)

edited… bug fixed

thanks for your input. I will give it a try and report back
cheers

copied the text from DenisT
saved it into a script and ran it.
error
“–Unable to convert: undefined to type: Integer”

Martinez
I got no error but nothing happened.

OK so let me be a little clearer.

I have (for example) 50 cars named
“Car00001” etc

and i have (for eg) 50 dummies named
“Dummy001” etc

I have a line named Line001

I want to

  1. Align each car with its corresponding dummy
  2. Link each car with its corresponding dummy
  3. Place each linked dummy on Line001 with a follow path position controller
  4. Have the dummy (car) animate from 0% to 100% over 1000 frames with lets say 10 frames between each car.

Maybe it would be better to take it steps?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

change

 != -1 

to

 != undefined 

in my code