Recursed entities

Recursed entities
 1# this example displays the type of each entity in the active layer 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 root block
11    ab = impact.active_drawing.active_layer.root_block
12
13    # create a local variable for the entities in the active block
14    entities = ab.recursed_entities
15
16    # iterate the entities and display the type of each entity in the output
17    # toolbox
18    for recursed 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 recursed.entity.entity_type == ipEntityType.etLine:
25            entity_type_string = "ipEntityType.etLine"
26        elif recursed.entity.entity_type == ipEntityType.etArc:
27            entity_type_string = "ipEntityType.etArc"
28        elif recursed.entity.entity_type == ipEntityType.etText:
29            entity_type_string = "ipEntityType.etText"
30        elif recursed.entity.entity_type == ipEntityType.etDimension:
31            entity_type_string = "ipEntityType.etDimension"
32        elif recursed.entity.entity_type == ipEntityType.etBorderPlot:
33            entity_type_string = "ipEntityType.etBorderPlot"
34        elif recursed.entity.entity_type == ipEntityType.etGraphic:
35            entity_type_string = "ipEntityType.etGraphic"
36        elif recursed.entity.entity_type == ipEntityType.etInsert:
37            entity_type_string = "ipEntityType.etInsert"
38        elif recursed.entity.entity_type == ipEntityType.etOther:
39            entity_type_string = "ipEntityType.etOther"
40        elif recursed.entity.entity_type == ipEntityType.etBezier:
41            entity_type_string = "ipEntityType.etBezier"
42        elif recursed.entity.entity_type == ipEntityType.etRubber:
43            entity_type_string = "ipEntityType.etRubber"
44
45
46        # get the centre of the entity
47        centre = recursed.entity.extents.centre
48
49        # transform the coordinate from block coordinates to world coordinates
50        centre.transform(recursed.matrix())
51
52        # use the convertor object for formatting the result nicely
53        conv = impact.system.convertor
54
55        # create indentations for the level of the recursion
56        indentation = ""
57        for i in range(0, recursed.level  + 1):
58            indentation =str(indentation) + "   "
59
60        # display the entity information in the output toolbox
61        impact.gui.output_toolbox.add(indentation + entity_type_string + " at (" + str(conv.length_as_string(centre.x)) + ", " + str(conv.length_as_string(centre.y)) + ")")