ignore_fields property

FindReplaceOptions.ignore_fields property

Gets or sets a boolean value indicating either to ignore text inside fields. The default value is False.

@property
def ignore_fields(self) -> bool:
    ...

@ignore_fields.setter
def ignore_fields(self, value: bool):
    ...

Remarks

This option affects whole field (all nodes between NodeType.FIELD_START and NodeType.FIELD_END).

To ignore only field codes, please use corresponding option FindReplaceOptions.ignore_field_codes.

Examples

Shows how to ignore text inside fields.

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.writeln('Hello world!')
builder.insert_field(field_code='QUOTE', field_value='Hello again!')
# We can use a "FindReplaceOptions" object to modify the find-and-replace process.
options = aw.replacing.FindReplaceOptions()
# Set the "IgnoreFields" flag to "true" to get the find-and-replace
# operation to ignore text inside fields.
# Set the "IgnoreFields" flag to "false" to get the find-and-replace
# operation to also search for text inside fields.
options.ignore_fields = ignore_text_inside_fields
doc.range.replace(pattern='Hello', replacement='Greetings', options=options)
self.assertEqual('Greetings world!\r\x13QUOTE\x14Hello again!\x15' if ignore_text_inside_fields else 'Greetings world!\r\x13QUOTE\x14Greetings again!\x15', doc.get_text().strip())

See Also