def getPrintZValue(lineBlock):
 lastZ = (-1)
 for line in lineBlock:
  lastZ = getValue(line, 'Z', lastZ)
  if (line.startswith('G1 ') and ((getValue(line, 'X', None) is not None) or (getValue(line, 'Y', None) is not None))):
   break
 return lastZ

def getPrintZValue ( lineBlock ) : lastZ = ( - 1 ) for line in lineBlock : lastZ = getValue ( line , 'Z' , lastZ ) if ( line . startswith ( 'G1 ' ) and ( ( getValue ( line , 'X' , None ) is not None ) or ( getValue ( line , 'Y' , None ) is not None ) ) ) : break return lastZ
look for the last z value found just before g1 code in the given block .