TextAd example¶
TextAd 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_x = 0
23 anchor_y = 0
24 caption = "Arden Software"
25
26 # create a text entity
27 text_entity = ab.text_ad(anchor_x, anchor_y, caption, text_style_sheet.text_style)
28
29 # check the text entity was created
30 if text_entity is not None:
31
32 # modify the horizontal and vertical position of the text entity
33 text_entity.horizontal_position = ipHorzTextPos.htpCentre
34 text_entity.vertical_position = ipVertTextPos.vtpMiddle
35
36 else:
37
38 # display a message in the output toolbox
39 impact.gui.output_toolbox.add("An error occured creating the text entity")
40
41else:
42
43 # display a message in the output toolbox
44 impact.gui.output_toolbox.add("Unable to find the text style sheet '" + str(text_style_sheet_name) + "'")