Entities example (Python)¶
Entities example (Python)¶
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 entityTypeString = "unknown entity type"
22
23 # set the string to display if possible
24 if entity.entity_type == ipEntityType.etLine:
25
26 entityTypeString = "ipEntityType.etLine"
27 elif entity.entity_type == ipEntityType.etArc:
28 entityTypeString = "ipEntityType.etArc"
29 elif entity.entity_type == ipEntityType.etText:
30 entityTypeString = "ipEntityType.etText"
31 elif entity.entity_type == ipEntityType.etDimension:
32 entityTypeString = "ipEntityType.etDimension"
33 elif entity.entity_type == ipEntityType.etBorderPlot:
34 entityTypeString = "ipEntityType.etBorderPlot"
35 elif entity.entity_type == ipEntityType.etGraphic:
36 entityTypeString = "ipEntityType.etGraphic"
37 elif entity.entity_type == ipEntityType.etInsert:
38 entityTypeString = "ipEntityType.etInsert"
39 elif entity.entity_type == ipEntityType.etOther:
40 entityTypeString = "ipEntityType.etOther"
41 elif entity.entity_type == ipEntityType.etBezier:
42 entityTypeString = "ipEntityType.etBezier"
43 elif entity.entity_type == ipEntityType.etRubber:
44 entityTypeString = "ipEntityType.etRubber"
45
46 # display the entity type in the output toolbox
47 impact.gui.output_toolbox.add("Entity Type: " + entityTypeString)