Example of FindDocumentByKey

Example of FindDocumentByKey
 1# This example finds a document in the active database with a specific key
 2
 3ot = impact.gui.output_toolbox
 4ot.clear()
 5
 6db = impact.active_database
 7
 8settings = db.settings.document_settings
 9
10if settings.supports_document_key:
11
12    # Display a message in the output toolbox
13    ot.add("Document storage supports document keys")
14
15    # The key of the document to find
16    document_key = 82
17
18    # Find the document
19    document = db.find_document_by_key(document_key)
20
21    # Check the document was found
22    if document is not None:
23
24        # Display a message in the output toolbox
25        ot.add("Found the document")
26
27        # Display the name of the document in the output toolbox
28        ot.add("Name: " + str(document.name))
29        ot.add("Size: " + str(document.size))
30        ot.add("File: " + str(document.file_name))
31
32        file_location = "c:\\Documents\\"
33        if document.copy_to(file_location + document.file_name):
34            ot.add("Successfully copied document to " + str(file_location))
35
36        else:
37            ot.add("Unable to copy document")
38
39    else:
40
41        # Display a message in the output toolbox
42        ot.add("Unable to find the document with key '" + str(document_key) + "'")
43
44else:
45
46    # Display a message in the output toolbox
47    ot.add("Document storage does not support document keys")