Creating a graphic entity

Creating a graphic entity
 1# This example loads a jpeg image, since the image is a jpeg
 2# None is passed as the PostScriptImageOptions method parameter
 3# in the IGraphicImages.load_from_file() method. If the image was
 4# successfully loaded a graphic entity is then created using
 5# the image.
 6
 7# clear the output toolbox
 8impact.gui.output_toolbox.clear()
 9
10# define some local variables
11images = impact.active_drawing.graphic_images
12ab = impact.active_drawing.active_layer.active_block
13file_name = "d:\1.jpg"
14embed = 0
15
16# call the IGraphicImages.load_from_file() method to load the image
17# into the drawing
18image = images.load_from_file(file_name, embed, None)
19
20# determine if the image was loaded successfully
21if image is not None:
22
23    # create an IGraphicOptions object to pass to the
24    # IActiveBlock.graphic_ad() method
25    options = impact.creator.graphic_options()
26
27    # set the print face image
28    options.print_face.graphic_image = image
29    options.print_face.graphic_type = ipGraphicType.gtImage
30
31    options.origin_mode = ipOriginMode.omBottomLeft
32    options.graphic_fit = ipGraphicFit.gfAutomatic
33    options.graphic_fill = ipGraphicFill.gfUserDefined
34    options.visible_entities_only = 1
35
36    # create the graphic entity
37    graphic_entity = ab.graphic_ad(0, 0, image.width, image.height, options)
38
39    if graphic_entity is not None:
40        impact.gui.output_toolbox.add("successfully created the graphic entity")
41
42    else:
43        impact.gui.output_toolbox.add("failed to create the graphic entity")
44
45    # view the extents of the active window
46    impact.gui.active_window.view_extents()
47
48else:
49    impact.gui.output_toolbox.add("failed to load " + str(file_name))