@@ -128,6 +128,10 @@ def addFeatureToList(ps: PrintState, cf: Feature):
128128 # wipe_end marker for normal printing features to skip
129129 wipeEndMatch = re .match (WIPE_END , cl )
130130
131+ #Debug
132+ if f .tell () == 155194 :
133+ 0 == 0
134+
131135 # end if we find next layer marker
132136 if changeLayerMatch :
133137 printState .layerEnd = f .tell () - len (cl ) - (len (le )- 1 )
@@ -138,10 +142,6 @@ def addFeatureToList(ps: PrintState, cf: Feature):
138142 printState .layerEndOriginalColor = curOriginalColor
139143 break
140144
141- #Debug
142- if f .tell () == 125095 :
143- 0 == 0
144-
145145 checkAndUpdatePosition (cl = cl , pp = curStartPosition )
146146
147147 # If UNIVERSAL LAYER CHANGE END found first, look ahead to see if a new feature is the first thing on this layer or previous feature is continued.
@@ -191,7 +191,7 @@ def addFeatureToList(ps: PrintState, cf: Feature):
191191
192192 # Look for FEATURE to find feature type
193193 if featureTypeMatch or (len (printState .features ) == 0 and useFirstSpecialGcodeAsFeature and specialGcodeMatch ):
194- # print(f"found FEATURE match at {f.tell() - len(cl) - (len(le)-1)}")
194+ print (f"found FEATURE match { featureTypeMatch . groups ()[ 0 ] if featureTypeMatch else 'None' } at { f .tell () - len (cl ) - (len (le )- 1 )} " )
195195
196196 # Don't end prime tower if we found prime tower feature for Bambu
197197 if curFeature and curFeature .featureType == PRIME_TOWER and featureTypeMatch and (featureTypeMatch .groups ()[0 ] == PRIME_TOWER or featureTypeMatch .groups ()[0 ] == WIPE_TOWER ):
@@ -236,7 +236,7 @@ def addFeatureToList(ps: PrintState, cf: Feature):
236236 # A toolchange is found UNIVERSAL_TOOLCHANGE_START
237237 elif univeralToolchangeStartMatch :
238238 curFeature .toolchange = Feature ()
239- curFeature .toolchange .featureType = TOOLCHANGE
239+ curFeature .toolchange .featureType = TOOLCHANGE
240240 curFeature .toolchange .start = f .tell () - len (cl ) - (len (le )- 1 )
241241 #print(f"found toolchange start at {curFeature.toolchange.start}")
242242 continue
@@ -253,6 +253,7 @@ def addFeatureToList(ps: PrintState, cf: Feature):
253253 elif univeralToolchangeEndMatch :
254254 if curFeature .toolchange == None :
255255 print (f"toolchange end found before toolchange start at { f .tell ()} set .end to { f .tell () - len (cl ) - (len (le )- 1 )} " )
256+ 1 == 0 # assert crash
256257 break
257258 curFeature .toolchange .end = f .tell () - len (cl ) - (len (le )- 1 )
258259 #print(f"found toolchange end at {curFeature.toolchange.end}")
@@ -346,10 +347,14 @@ def checkAndInsertToolchange(ps: PrintState, f: typing.TextIO, out: typing.TextI
346347 nextAvailablePrimeTowerFeature = ps .primeTowerFeatures .pop (0 )
347348 cp = f .tell ()
348349 f .seek (nextAvailablePrimeTowerFeature .start , os .SEEK_SET )
349- while f .tell () <= nextAvailablePrimeTowerFeature .end :
350+ # We check if the position is != instead of <= because readline() with the next line being empty meaning it looks like double line endings leads to high tell() values that do not make sense but still seek to the correct position anyways.
351+ while f .tell () != nextAvailablePrimeTowerFeature .end :
350352 cl = f .readline ()
351353
352- # Skip WIPE_END of the inserted prime tower
354+ if f .tell () == 155194 :
355+ 0 == 0
356+
357+ # Skip WIPE_END of the nserted prime tower
353358 if nextAvailablePrimeTowerFeature .wipeEnd and f .tell () == nextAvailablePrimeTowerFeature .wipeEnd .start :
354359 writeWithFilters (out , cl , loadedColors )
355360 out .write (";WIPE_END placeholder for PrusaSlicer Gcode Viewer\n " )
0 commit comments