Hello community,
SourcePoints = self.SourcePoints
TargetPoints = self.TargetPoints
print("SourcePoints: ", self.SourcePoints)
print("TargetPoints: ", self.TargetPoints)
for point in SourcePoints:
for i in range(len(point)):
point[i] = Origin[i] + point[i] * Spacing[i]
for point in TargetPoints:
for i in range(len(point)):
point[i] = Origin[i] + point[i] * Spacing[i]
print("SourcePoints: ", self.SourcePoints)
print("TargetPoints: ", self.TargetPoints)
What you probably need to know for context: - self.SourcePoints/self.TargetPoints is initialized once an instance of the class (that inherits the code) is created. There is no other section where the lists are manipulated. - self.SourcePoints/self.TargetPoints are lists of lists - the code snipped is part of a function within the class
I am by far not an expert in programming, so i might oversee something obvious here, but i cant see it and it drives me crazy, because the two print commands dont have the same output...and the script crashes (ofc) because self.SourcePoints/self.TargetPoints are "wrong" in the subsequent iteration.
So you might say now, by writing
SourcePoints = self.SourcePoints
you dont make a copy, but create a reference to the list, so naturally the origin-list gets changed during the for-loops. Makes perfect sense to me, thats why i tried
SourcePoints = copy.copy(self.SourcePoints)
and
SourcePoints = self.SourcePoints.copy()
which both didnt change anything.
Then i said to myself, maybe its because of the identical name of the lists. So the script thinks if i take the variable "SourcePoints" within a class function i want to change the variable self.SourcePoints. So i changed everything to
srcPoints = self.SourcePoints.copy()
And it still doesnt work... I have really no idea what is going on and it drives me crazy. Fortunately i have a bypass for the script, but i am still trying to figure out why this keeps happening. It makes absolutely no sense to my how the two print commands dont have identical output. Yet, the computer is just doing what i tell him to do.
Can somebody enlighten me?
Greets, Void