LayerInsertA example¶
LayerInsertA example¶
1# This example creates a new layer and some geometry in the new layer,
2# an insert of the new layer is inserted into the first layer in the
3# active drawing. Absolute coordinates and vector parameters are used.
4
5# Create a local variable for the output toolbox
6ot = impact.gui.output_toolbox
7
8# Clear the output toolbox
9ot.clear()
10
11# Create a local variable for the active drawing
12ad = impact.active_drawing
13
14# check there is an active drawing
15if ad.isNone():
16
17 # display a message in the output toolbox
18 ot.add("Unable to continue: there is no active drawing")
19
20else:
21
22 # create a local variable for the current active layer
23 original_layer = ad.active_layer
24
25 # create a new block from the selected entities in the active block
26 new_layer = ad.layers.add("New Layer", "ONE_UP", original_layer)
27
28 # check the layer was created succesfully
29 if not new_layer.isNone():
30
31 # create a local variable for the active block
32 ab = ad.active_layer.active_block
33
34 # move to the origin of the active block
35 ab.move_ad(0, 0)
36
37 # draw some geometry
38 ab.lined(100, 0)
39 ab.lined(0, 100)
40 ab.lined(-100, 0)
41 ab.lined(0, -100)
42
43 # create some local variables for the position, angle, scale etc. for the
44 # layer insert
45 position = impact.creator.vector(500,500)
46 scale = 2
47 angle = 0
48 mirror_x = 0
49 mirror_y = 0
50
51 # set the active layer back to the original layer
52 ad.active_layer = original_layer
53
54 # update the local variable for the active block
55 ab = ad.active_layer.active_block
56
57 # create the layer insert
58 layer_insert = ab.layer_insert_a(new_layer, position, scale, angle, mirror_x, mirror_y)
59
60 # Display an appropriate message in the output toolbox
61 if layer_insert is not None:
62 ot.add("Successfully created a layer insert")
63 else:
64 ot.add("Failed to create a layer insert")
65
66 # View the extents of the active window
67 impact.gui.active_window.view_extents()