Python script - list of directions output only updated points

Hi, python script in the bottom is a piece of the raybounce code.
I want to tweak it slightly so that when I input a list of points and the same amount of directions, I only get an output of updated points.

this is what happens now: (example is 16 points and 16 directions and i get 16 new points for each point)
image

IN[1] is the list of directions

direction = XYZ(IN[1].X,IN[1].Y,IN[1].Z)

for p in points:
	ref = ri.FindNearest(p,direction)
	if ref == None:
		pts.append(None)
		elems.append(None)
	else:

continues from here

I don’t understand python well enough to tweak it.

Hello @Vorm ,
it is because, you are taking point one by one from for loop but still direction list contain 16 direction.
As per my understanding, in this case, you have list of 16 points and list of 16 direction.
and you want to map point 1 with direction 1,point 2 with direction 2, point 3 with direction 3 and so on.

Not the way you are getting now, point 1 in 16 direction, point 2 in 16 direction. point 3 in 16 direction and so on

for p in range(len(points)):
ref = ri.Findnearest(points[p],direction[p])
if ref == None:
pts.append(None)
elems.append(None)

Hi @honeyjain619 ,
You understood that perfectly thank you
but this change was not enough to get the desired result but I did figure it out.

the problem was that the script and node expected a single vector as input and that caused problems when making this change but I ended up with this:

if isinstance(IN[1],list):
	directions = [XYZ(UnitUtils.ConvertToInternalUnits(i.X,UIunit),UnitUtils.ConvertToInternalUnits(i.Y,UIunit),UnitUtils.ConvertToInternalUnits(i.Z,UIunit)) for i in IN[1]]
else:
	directions = [XYZ(UnitUtils.ConvertToInternalUnits(IN[1].X,UIunit),UnitUtils.ConvertToInternalUnits(IN[1].Y,UIunit),UnitUtils.ConvertToInternalUnits(IN[1].Z,UIunit))]

for p in range(len(points)):
	ref = ri.FindNearest(points[p],directions[p])
	if ref == None:
		pts.append(None)
		elems.append(None)
	else:

and needed to add

[]

to the end of the input:

Thank You for the help

1 Like