Save layer as image

Save layer as image
 1# This example shows how to save all the layers of a drawing as images
 2
 3ot = impact.gui.output_toolbox
 4
 5ot.clear()
 6
 7# create an IImageFormatParams object, then set the properties
 8ImageFormat = impact.creator.image_format_params()
 9ImageFormat.width = 256  # pixels
10ImageFormat.height = 256  # pixels
11ImageFormat.resolution = 72
12ImageFormat.compression_factor = 50
13ImageFormat.colour_depth = ipImageColourFormat.ic24Bit
14ImageFormat.compression = ipCompressionFormat.cfDefault
15
16# create an ISaveImageParams object and define the properties
17# (the border size is in your current distance impact.units)
18ImageParams = impact.creator.save_image_params()
19ImageParams.image_format_params = ImageFormat
20ImageParams.file_format = ipFileFormat.ffPNG
21ImageParams.left_border_size = 20
22ImageParams.right_border_size = 20
23ImageParams.top_border_size = 20
24ImageParams.bottom_border_size = 20
25
26counter = 1
27
28start = Timer
29
30for layer in impact.active_drawing.layers:
31    ImageParams.file_path = r"d:\\Images\\Layer" + str(counter) + ".png"
32
33    if layer.save_layer_as_image(ImageParams):
34        ot.add("Image " + ImageParams.file_path + " for layer '" + layer.full_name + "' saved successfully")
35    else:
36        ot.add("Failed to Save Image " + ImageParams.file_path + " for layer '" + layer.full_name + "'")
37
38    counter = counter + 1
39
40ms = int((Timer - start) * 1000)
41
42ot.add("Generated images in " + str(ms) + "ms")
43