TextA2 example¶
TextA2 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. The text style of the text
6# entity will be linked to that of the specified text style sheet.
7
8# create a local variable for the active block
9ab = impact.active_drawing.active_layer.active_block
10
11# create a local variable for the text style sheet to use
12text_style_sheet_name = "Palette Default"
13
14# attempt to get the specified text style sheet from the active drawing
15text_style_sheet = impact.active_drawing.text_style_sheets.item(text_style_sheet_name)
16
17# check that a text style sheet was found
18if not text_style_sheet.isNone():
19
20 # create local variables for the anchor and caption
21 anchor = impact.creator.vector(0,0)
22 caption = "Arden Software"
23
24 # create a text entity
25 text_entity = ab.text_a2(anchor, caption, text_style_sheet)
26
27 # check the text entity was created
28 if not text_entity.isNone():
29
30 # modify the horizontal and vertical position of the text entity
31 text_entity.horizontal_position = ipHorzTextPos.htpCentre
32 text_entity.vertical_position = ipVertTextPos.vtpMiddle
33
34 else:
35
36 # display a message in the output toolbox
37 impact.gui.output_toolbox.add("An error occured creating the text entity")
38
39else:
40
41 # display a message in the output toolbox
42 impact.gui.output_toolbox.add("Unable to find the text style sheet '" + str(text_style_sheet_name) + "'")
43