Saving an image as a document

Saving an image as a document
 1# this example saves an existing image in the active drawing into the document
 2# database. It creates a customer or project document depending on whether the
 3# image is embedded or linked.
 4
 5ot = impact.gui.output_toolbox
 6
 7ot.clear()
 8
 9if not impact.active_drawing.isNone():
10    db_item = impact.active_drawing.database_item
11
12    images = impact.active_drawing.graphic_images
13
14    if not db_item.isNone():
15        if images.count >= 1:
16            image = images.item(1)
17
18            if image.document.isNone():
19                if image.embedded:
20                    docs = db_item.documents
21
22                    doc = docs.add_embedded_graphic(image, "Logo", ipFileFormat.ffJPG, "Document for embedded image")
23
24                    if doc is None:
25                        ot.add("Unable to save embedded image as document")
26
27                    else:
28                        ot.add("Successfully saved embedded image as " + str(doc.name))
29
30                else:
31                    docs = db_item.customer.documents
32
33                    doc = docs.add_graphic(image, "Document for image " + image.file_name)
34
35                    if doc is None:
36                        ot.add("Unable to save image as document")
37
38                    else:
39                        ot.add("Successfully saved image as " + str(doc.name))
40
41            else:
42                ot.add("The image is already a document")
43
44        else:
45            ot.add("The active drawing does not have any graphic images")
46
47    else:
48        ot.add("The active drawing has not been saved into the database")
49
50else:
51    ot.add("There is no active drawing")
52