def to_textgrid(self, filtin=[], filtex=[], regex=False):
from pympi.Praat import TextGrid<EOL>_, end = self.get_full_time_interval()<EOL>tgout = TextGrid(xmax=end/<NUM_LIT>)<EOL>func = (lambda x, y: re.match(x, y)) if regex else lambda x, y: x == y<EOL>for tier in self.tiers:<EOL><INDENT>if (filtin and not any(func(f, tier) for f in filtin)) or(filtex and any(func(f, tier) for f in filtex)):<EOL><INDENT>continue<EOL><DEDENT>ctier = tgout.add_tier(tier)<EOL>for intv in self.get_annotation_data_for_tier(tier):<EOL><INDENT>try:<EOL><INDENT>ctier.add_interval(intv[<NUM_LIT:0>]/<NUM_LIT>, intv[<NUM_LIT:1>]/<NUM_LIT>, intv[<NUM_LIT:2>])<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>return tgout<EOL>
Convert the object to a :class:`pympi.Praat.TextGrid` object.

        :param list filtin: Include only tiers in this list, if empty
            all tiers are included.
        :param list filtex: Exclude all tiers in this list.
        :param bool regex: If this flag is set the filters are seen as regexes.
        :returns: :class:`pympi.Praat.TextGrid` representation.
        :raises ImportError: If the pympi.Praat module can't be loaded.