Picking using GetEntity2¶
Picking using GetEntity2¶
1# Example of picking using GetEntity2, showing how to take account of any
2# transformations due to entities being in sub-blocks.
3
4# Ask the user to pick a line entity (recursing into sub-blocks)
5pick_info = impact.gui.picker.get_entity2("Pick a line", True)
6
7if pick_info.isNone():
8 impact.gui.output_toolbox.add("You didn't pick anything")
9else:
10 if pick_info.entity.entity_type != ipEntityType.etLine:
11 impact.gui.output_toolbox.add("You didn't pick a line")
12 else:
13 ot = impact.gui.output_toolbox
14 ot.clear()
15
16 ent = pick_info.entity
17 ot.add("The picked line is in block '" + ent.block.full_name + "'")
18
19 vec_start = impact.creator.vector(ent.start.x, ent.start.y)
20 vec_end = impact.creator.vector(ent.end.x, ent.end.y)
21
22 # If the project options are set to use world coordinates (ipCoordinateMode.cmWorld) then we don't need
23 # to do any transformations.
24 if impact.active_drawing.coordinate_system.mode == ipCoordinateMode.cmBlock:
25 ot.add("In block coordinates:")
26 ot.add("Line start: " + vec_start.to_string())
27 ot.add("Line end: " + vec_end.to_string())
28
29 # The Start and End points will be given in that block's coordinate impact.system,
30 # so we need to use the transformation matrix to convert them into values
31 # appropriate to the layer (in other words, world coordinates).
32 mat = pick_info.recursed_entity.matrix()
33 vec_start.transform(mat)
34 vec_end.transform(mat)
35
36 ot.add("In layer coordinates:")
37 ot.add("Line start: " + vec_start.to_string())
38 ot.add("Line end: " + vec_end.to_string())
39
40