Entities example¶
Entities example¶
1# this example displays the type of each entity in the active block in the
2# output toolbox
3if impact.active_drawing.isNone():
4
5 # display a message in the output toolbox
6 impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
7
8else:
9
10 # create a local variable for the active block
11 ab = impact.active_drawing.active_layer.active_block
12
13 # create a local variable for the entities in the active block
14 entities = ab.entities
15
16 # iterate the entities and display the type of each entity in the output
17 # toolbox
18 for entity in entities:
19
20 # initalise a string to display
21 entity_type_string = "unknown entity type"
22
23 # set the string to display if possible
24 if entity.entity_type == ipEntityType.etLine:
25 entity_type_string = "ipEntityType.etLine"
26 elif entity.entity_type == ipEntityType.etArc:
27 entity_type_string = "ipEntityType.etArc"
28 elif entity.entity_type == ipEntityType.etText:
29 entity_type_string = "ipEntityType.etText"
30 elif entity.entity_type == ipEntityType.etDimension:
31 entity_type_string = "ipEntityType.etDimension"
32 elif entity.entity_type == ipEntityType.etBorderPlot:
33 entity_type_string = "ipEntityType.etBorderPlot"
34 elif entity.entity_type == ipEntityType.etGraphic:
35 entity_type_string = "ipEntityType.etGraphic"
36 elif entity.entity_type == ipEntityType.etInsert:
37 entity_type_string = "ipEntityType.etInsert"
38 elif entity.entity_type == ipEntityType.etOther:
39 entity_type_string = "ipEntityType.etOther"
40 elif entity.entity_type == ipEntityType.etBezier:
41 entity_type_string = "ipEntityType.etBezier"
42 elif entity.entity_type == ipEntityType.etRubber:
43 entity_type_string = "ipEntityType.etRubber"
44
45
46 # display the entity type in the output toolbox
47 impact.gui.output_toolbox.add("Entity Type: " + str(entity_type_string))
48