Using Drag2 to reposition entities¶
Using Drag2 to reposition entities¶
1# This example shows how to use the Drag2 function to reposition the selected entities
2
3# First of all clear the output toolbox
4ot = impact.gui.output_toolbox
5ot.clear()
6
7if not impact.active_drawing.isNone():
8
9 # Create the parameter list for the Drag2 Function
10 params = impact.creator.drag_params()
11 params.leave_original = True
12 params.scale = 1
13 params.rotate = 0
14 params.mirror_x = False
15 params.mirror_y = False
16 params.help_message = "Please select the point to drag to"
17 params.pick_up_point = impact.creator.vector(3, 9)
18
19 # Call the Drag2 Function with the parameter list we have just created
20 if impact.gui.drag2(params):
21
22 # Output the DropPoint that was generated by the function
23 ot.add(params.drop_point.x)
24 ot.add(params.drop_point.y)
25
26 # Get the new entities that were created from the Drag2 Function
27 entities = params.new_entities
28
29 # Iterate the entities and display the type of each entity in the Output Toolbox
30 for entity in entities:
31
32 # Set the string to display if possible
33 entity_type_string = "unknown entity type"
34 if entity.entity_type == ipEntityType.etLine:
35 entity_type_string = "ipEntityType.etLine"
36 elif entity.entity_type == ipEntityType.etArc:
37 entity_type_string = "ipEntityType.etArc"
38 elif entity.entity_type == ipEntityType.etText:
39 entity_type_string = "ipEntityType.etText"
40 elif entity.entity_type == ipEntityType.etDimension:
41 entity_type_string = "ipEntityType.etDimension"
42 elif entity.entity_type == ipEntityType.etBorderPlot:
43 entity_type_string = "ipEntityType.etBorderPlot"
44 elif entity.entity_type == ipEntityType.etGraphic:
45 entity_type_string = "ipEntityType.etGraphic"
46 elif entity.entity_type == ipEntityType.etInsert:
47 entity_type_string = "ipEntityType.etInsert"
48 elif entity.entity_type == ipEntityType.etOther:
49 entity_type_string = "ipEntityType.etOther"
50 elif entity.entity_type == ipEntityType.etBezier:
51 entity_type_string = "ipEntityType.etBezier"
52 elif entity.entity_type == ipEntityType.etRubber:
53 entity_type_string = "ipEntityType.etRubber"
54
55 # Display the entity type in the output toolbox
56 ot.add("Entity Type: " + str(entity_type_string))
57 else:
58 ot.add("The Drag2 method failed (perhaps no entities were selected)")
59else:
60 ot.add("You must have an open drawing")