Example of FindDocumentByKey (Python)

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