diff --git a/PyReconstruct/modules/datatypes/series.py b/PyReconstruct/modules/datatypes/series.py index 7ba7f53bb..7f23d7e46 100644 --- a/PyReconstruct/modules/datatypes/series.py +++ b/PyReconstruct/modules/datatypes/series.py @@ -932,7 +932,7 @@ def createZtrace( self, obj_name : str, cross_sectioned : bool = True, - z_points : list = [], + z_points : list = None, ztrace_color : tuple = (0, 0, 0), log_event=True ): @@ -945,7 +945,16 @@ def createZtrace( ztrace_color (tuple): color of ztrace to display in field log_event (bool): True if event should be logged """ - if not z_points: # append name with "_zlen" if creating from obj + # A fresh list per call: a shared mutable default would let the points + # generated for one object leak into the next from-object ztrace. + if z_points is None: + z_points = [] + + # Decide this once, before the from-object branch below fills z_points: + # the alignment choice at the end must not see the filled list. + from_object = not z_points + + if from_object: # append name with "_zlen" if creating from obj ztrace_name = f"{obj_name}_zlen" else: # use tracing_trace name ztrace_name = obj_name @@ -956,7 +965,7 @@ def createZtrace( del(self.ztraces[ztrace_name]) if log_event: self.addLog(ztrace_name, None, "Updated ztrace") - if not z_points: # generate points from already traced object if non provided + if from_object: # generate points from already traced object if non provided ## If create on midpoints, make one point per section @@ -998,7 +1007,7 @@ def createZtrace( ) ## Assign alignement to ztrace - if not z_points: # use obj alignment + if from_object: # use obj alignment alignment = self.getAttr(obj_name, "alignment") else: # use current alignment alignment = self.alignment