I have 3 lists.
A nested list of points.
A list of vectors
A list of widths.
Each sublist of points is a point along a line which corresponds to the vector of the same index.
So sublist [0] of points are all along a line with vector at index [0]
I’m taking a random point and offsetting it by a width along that vector.
It works fine for anything in a list with an even index.
but if the list has an odd index the vector remains normalized.
Why?
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import Point, Vector
import random
# Inputs
line_vectors = IN[0] # Vectors of the lines input
placement_points = IN[1] # Nested list of points along the lines
widths = IN[2] # List of widths
offset_points = []
# Debugging list
test = []
# Iterate through each width
for width in widths:
# Randomly select a sublist index
sublist_index = random.randint(0, len(placement_points) - 1)
# Get the corresponding vector and sublist of points
vector = line_vectors[sublist_index]
points_sublist = placement_points[sublist_index]
# Select a random point from the sublist
random_point = random.choice(points_sublist)
# Scale the vector by the width ... THIS ONLY WORKS FOR EVEN INDICIES... WHY ????
offset_vector = vector.Scale(width)
# Calculate the offset point
offset_point = random_point.Add(offset_vector)
# Append the offset point to the output list
offset_points.append(offset_point)
# Collect debug information
test.append(f"Index: {sublist_index}, Vector: {vector}, Width: {width}, Offset Vector: {offset_vector}")
OUT = test
If I do this it works… but I want to know why the method above doesn’t work.
offset_vector = Vector.ByCoordinates(vector.X * width, vector.Y * width, vector.Z * width)