TextA example

TextA example
 1# This example gets a text style sheet from the active drawing
 2# and creates a text entity at position 0,0 using the text style
 3# of the text style sheet. The horizontal and vertical positions
 4# of the text entity are then modified so that the centre point of
 5# the text entity lies at position 0,0. Although the text style
 6# of the text entity will be based on the text style of the specified
 7# text style sheet, it will not be linked to it.
 8
 9# create a local variable for the active block
10ab = impact.active_drawing.active_layer.active_block
11
12# create a local variable for the text style sheet to use
13text_style_sheet_name = "Palette Default"
14
15# attempt to get the specified text style sheet from the active drawing
16text_style_sheet = impact.active_drawing.text_style_sheets.item(text_style_sheet_name)
17
18# check that a text style sheet was found
19if not text_style_sheet.isNone():
20
21    # create local variables for the anchor and caption
22    anchor = impact.creator.vector(0,0)
23    caption = "Arden Software"
24
25    # create a text entity
26    text_entity = ab.text_a(anchor, caption, text_style_sheet.text_style)
27
28    # check the text entity was created
29    if text_entity is not None:
30
31        # modify the horizontal and vertical position of the text entity
32        text_entity.horizontal_position = ipHorzTextPos.htpCentre
33        text_entity.vertical_position = ipVertTextPos.vtpMiddle
34
35    else:
36
37        # display a message in the output toolbox
38        impact.gui.output_toolbox.add("An error occured creating the text entity")
39
40else:
41
42    # display a message in the output toolbox
43    impact.gui.output_toolbox.add("Unable to find the text style sheet '" + str(text_style_sheet_name) + "'")