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. 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_x = 0
22 anchor_y = 0
23 caption = "Arden Software"
24
25 # create a text entity
26 text_entity = ab.text_ad2(anchor_x, anchor_y, caption, text_style_sheet)
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) + "'")