Notifications
Clear all

[Closed] Float script that affects an array of objects?

I’m looking for each yellow dot to be applied a script in the percentage property “since they have applied path constraint to each yellow null” that manages to make each yellow dot be placed in the same position as each green dot. Only make it work that all go to a specific green null. thank you all!

VArray = ($GreenPoint*)
arr = ($YellowPoint*)

path1 = $Spline

for i=1 to arr.count do
(

	a = arr.pos.controller = Path_Constraint path: path1
	b = a.percent.controller = float_script()
	c = a.percent.controller.script = "nearestPathParam path1 $GreenPoint_001.pos steps: 300"

)

6 Replies

I’m not completely sure I understand what you are trying to do but, as I see it, you have two alternatives. One is to create the yellow points as needed and the other is to search the existing yellow points trying to match the digits on the name:

function createPoints pointArray = (
	for i = 1 to pointArray.count do (
		p = Point name:("YellowPoint_" + (formattedprint i format:"03d"))
		a = p.pos.controller = Path_Constraint path:$Spline
		b = a.percent.controller = float_script()
		c = a.percent.controller.script = ("nearestPathParam $Spline $" + pointArray[i].name + ".pos steps: 300")
	)
)

function matchPoints pointArray = (
	for i = 1 to pointArray.count do (
		n = pointArray[i].name
		id = (filterstring n "_")[2]
		p = getNodeByName ("YellowPoint_" + id)
		if p == undefined then (
			print ("Could not find " + n + " matching YellowPoint")
		)
		else (
			a = p.pos.controller = Path_Constraint path:$Spline
			b = a.percent.controller = float_script()
			c = a.percent.controller.script = ("nearestPathParam $Spline $" + n + ".pos steps: 300")
		)
	)
)

createPoints ($GreenPoint*)
--matchPoints ($GreenPoint*)

It’s exactly what I was looking for, it works like a charm, thank you very much for your contribution.

I need one more help, the code works perfect if there is only one path in the scene, and if there are 2 how would you change the code?

the problem seems to be that I can not apply 2 objects path in this line of code, only works with 1 single object
c = a.percent.controller.script = (“nearestPathParam $Spline $” + pointArray[i].name + “.pos steps: 300”)

You can change the function to something like this to create the points on a specific path:

function createPathPoints targetPath pointArray = (
	for i = 1 to pointArray.count do (
		p = Point name:(uniqueName "YellowPoint_")
		a = p.pos.controller = Path_Constraint path:targetPath
		a.percent.controller = float_script()
		a.percent.controller.script = ("nearestPathParam $" + targetPath.name + " $" + pointArray[i].name + ".pos steps: 300")
	)
)

And call it like this to create the points on all the scene splines

for s in shapes do createPathPoints s ($GreenPoint*)

or like this to create the points only on the selected splines:

 for s in selection where superclassof s == shape do createPathPoints s ($GreenPoint*)

Excellent!., thank you very much for all the help.

You are welcome