LayerInsertd example

LayerInsertd 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. Relative coordinates and double 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 angle, scale etc. for the
44        # layer insert
45        scale = 2
46        angle = 0
47        mirror_x = 0
48        mirror_y = 0
49
50        # set the active layer back to the original layer
51        ad.active_layer = original_layer
52
53        # update the local variable for the active block
54        ab = ad.active_layer.active_block
55
56        # create the layer insert
57        layer_insert = ab.layer_insertd(new_layer, 500, 500, scale, angle, mirror_x, mirror_y)
58
59        # Display an appropriate message in the output toolbox
60        if layer_insert is not None:
61            ot.add("Successfully created a layer insert")
62        else:
63            ot.add("Failed to create a layer insert")
64
65    # View the extents of the active window
66    impact.gui.active_window.view_extents()