Exploding text entities (Python)¶
Exploding text entities (Python)¶
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 textStyleSheetName = "Palette Default"
31
32 # get the specified text style sheet from the active drawing
33 textStyleSheet = None
34 try:
35 textStyleSheet = ad.text_style_sheets.item( textStyleSheetName )
36 except Exception as exc:
37 pass
38 impact.gui.output_toolbox.add(f"Failed to create object via ad.text_style_sheets.item(): {exc}")
39
40 # check a text style sheet was found
41 if not textStyleSheet.isNone():
42
43 # create a text entity
44 textEntity = ab.text_ad( 0, 0, "Arden Software", textStyleSheet.text_style )
45
46 # check the text entity was created successfully
47 if textEntity.isNone():
48
49 # display a message in the output toolbox
50 ot.add("failed to create a text entity")
51
52 else:
53
54 # select the text entity
55 textEntity.selected = True
56
57 # create a structure to hold the explode options
58 explodeOptions = impact.creator.explode_options()
59
60 # only explode text entities
61 explodeOptions.text = True
62
63 # create a local variable to store the new entities created
64 # by the explode operation
65 entities = None
66
67 # explode the selected entities
68 entities = None
69 try:
70 entities = ab.explode( explodeOptions )
71 except Exception as exc:
72 impact.gui.output_toolbox.add(f"Failed to create object via ab.explode(): {exc}")
73
74 # check that some entities were returned
75 if isinstance( entities ):
76
77 # display the type of each entity in the output toolbox
78 for entity in entities:
79 ot.add( entity.entity_type )
80
81 # view the extents of the active window
82 g.active_window.view_extents()
83
84 else:
85
86 # display a message in the output toolbox
87 ot.add("Unable to find the text style sheet '" + textStyleSheetName + "'")