Creating a graphic entity (Python)

Creating a graphic entity (Python)
 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
13fileName = "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( fileName, embed, None )
19
20# determine if the image was loaded successfully
21if not image.isNone():
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    graphicEntity = ab.graphic_ad( 0, 0, image.width, image.height, options )
38
39    if not graphicEntity.isNone():
40
41        impact.gui.output_toolbox.add("successfully created the graphic entity")
42
43    else:
44
45        impact.gui.output_toolbox.add("failed to create the graphic entity")
46
47    # view the extents of the active window
48    impact.gui.active_window.view_extents()
49else:
50
51    impact.gui.output_toolbox.add("failed to load " + fileName)