Exploding text entities¶
Exploding text entities¶
1# this example creates a text entity and explodes it
2
3# Create a local variable for the impact.gui
4g = impact.gui
5
6# create a local variable for the output toolbox
7ot = g.output_toolbox
8
9# clear the output toolbox
10ot.clear()
11
12# create a local variable for the active drawing
13ad = impact.active_drawing
14
15# check there is an active drawing
16if ad.isNone():
17
18 # display a message in the output toolbox
19 ot.add("Unable to continue: there is no active drawing")
20
21else:
22
23 # create a local variable for the active block
24 ab = ad.active_layer.active_block
25
26 # move to the origin of the active block
27 ab.move_ad(0, 0)
28
29 # create a local variable for the text style sheet to find
30 text_style_sheet_name = "Palette Default"
31
32 # get the specified text style sheet from the active drawing
33 text_style_sheet = ad.text_style_sheets.item(text_style_sheet_name)
34
35 # check a text style sheet was found
36 if not text_style_sheet.isNone():
37
38 # create a text entity
39 text_entity = ab.text_ad(0, 0, "Arden Software", text_style_sheet.text_style)
40
41 # check the text entity was created successfully
42 if text_entity is None:
43
44 # display a message in the output toolbox
45 ot.add("failed to create a text entity")
46
47 else:
48
49 # select the text entity
50 text_entity.selected = True
51
52 # create a structure to hold the explode options
53 explode_options = impact.creator.explode_options()
54
55 # only explode text entities
56 explode_options.text = True
57
58 # create a local variable to store the new entities created
59 # by the explode operation
60 entities = None
61
62 # explode the selected entities
63 entities = ab.explode(explode_options)
64
65 # Wrap variant return items with Impact.py wrapper
66 if entities is not None:
67 entities = [IEntity(item) for item in entities]
68
69 # check that some entities were returned
70 if entities:
71
72 # display the type of each entity in the output toolbox
73 for entity in entities:
74 ot.add(entity.entity_type)
75
76 # view the extents of the active window
77 g.active_window.view_extents()
78
79 else:
80
81 # display a message in the output toolbox
82 ot.add("Unable to find the text style sheet '" + str(text_style_sheet_name) + "'")