FieldAutoTextList class

FieldAutoTextList class

Implements the AUTOTEXTLIST field. To learn more, visit the Working with Fields documentation article.

Remarks

Creates a shortcut menu based on AutoText entries in the active template.

Inheritance: FieldAutoTextListField

Constructors

NameDescription
FieldAutoTextList()The default constructor.

Properties

NameDescription
display_resultGets the text that represents the displayed field result.
(Inherited from Field)
endGets the node that represents the field end.
(Inherited from Field)
entry_nameGets or sets the name of the AutoText entry.
formatGets a FieldFormat object that provides typed access to field’s formatting.
(Inherited from Field)
is_dirtyGets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
(Inherited from Field)
is_lockedGets or sets whether the field is locked (should not recalculate its result).
(Inherited from Field)
list_styleGets or sets the name of the style on which the list to contain entries is based.
locale_idGets or sets the LCID of the field.
(Inherited from Field)
resultGets or sets text that is between the field separator and field end.
(Inherited from Field)
screen_tipGets or sets the text of the ScreenTip to show.
separatorGets the node that represents the field separator. Can be None.
(Inherited from Field)
startGets the node that represents the start of the field.
(Inherited from Field)
typeGets the Microsoft Word field type.
(Inherited from Field)

Methods

NameDescription
get_field_code()Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included.
(Inherited from Field)
get_field_code(include_child_field_codes)Returns text between field start and field separator (or field end if there is no separator).
(Inherited from Field)
remove()Removes the field from the document. Returns a node right after the field. If the field’s end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns None.
(Inherited from Field)
unlink()Performs the field unlink.
(Inherited from Field)
update()Performs the field update. Throws if the field is being updated already.
(Inherited from Field)
update(ignore_merge_format)Performs a field update. Throws if the field is being updated already.
(Inherited from Field)

Examples

Shows how to use an AUTOTEXTLIST field to select from a list of AutoText entries.

def test_field_auto_text_list(self):

    doc = aw.Document()

    # Create a glossary document and populate it with auto text entries.
    doc.glossary_document = aw.buildingblocks.GlossaryDocument()
    ExField.append_auto_text_entry(doc.glossary_document, "AutoText 1", "Contents of AutoText 1")
    ExField.append_auto_text_entry(doc.glossary_document, "AutoText 2", "Contents of AutoText 2")
    ExField.append_auto_text_entry(doc.glossary_document, "AutoText 3", "Contents of AutoText 3")

    builder = aw.DocumentBuilder(doc)

    # Create an AUTOTEXTLIST field and set the text that the field will display in Microsoft Word.
    # Set the text to prompt the user to right-click this field to select an AutoText building block,
    # whose contents the field will display.
    field = builder.insert_field(aw.fields.FieldType.FIELD_AUTO_TEXT_LIST, True).as_field_auto_text_list()
    field.entry_name = "Right click here to select an AutoText block"
    field.list_style = "Heading 1"
    field.screen_tip = "Hover tip text for AutoTextList goes here"

    self.assertEqual(" AUTOTEXTLIST  \"Right click here to select an AutoText block\" " +
                    "\\s \"Heading 1\" " +
                    "\\t \"Hover tip text for AutoTextList goes here\"", field.get_field_code())

    doc.save(ARTIFACTS_DIR + "Field.field_auto_text_list.dotx")

@staticmethod
def append_auto_text_entry(glossary_doc: aw.buildingblocks.GlossaryDocument, name: str, contents: str):
    """Create an AutoText-type building block and add it to a glossary document."""

    building_block = aw.buildingblocks.BuildingBlock(glossary_doc)
    building_block.name = name
    building_block.gallery = aw.buildingblocks.BuildingBlockGallery.AUTO_TEXT
    building_block.category = "General"
    building_block.behavior = aw.buildingblocks.BuildingBlockBehavior.PARAGRAPH

    section = aw.Section(glossary_doc)
    section.append_child(aw.Body(glossary_doc))
    section.body.append_paragraph(contents)
    building_block.append_child(section)

    glossary_doc.append_child(building_block)

See Also