Creating Documents

Creating Documents
 1ot = impact.gui.output_toolbox
 2db = impact.active_database
 3
 4
 5def describe_doc(doc, method):
 6    if not doc.isNone():
 7        ot.add("Document '" + doc.name + "' successfully created with " + str(method))
 8        ot.add("Description: " + str(doc.description))
 9        ot.add("Checkin-Comment: " + str(doc.comment))
10        ot.add("Added: " + str(doc.added_date_time) + " by " + str(doc.added_by.login_id))
11        ot.add("Version: " + str(doc.version.version_as_string))
12        ot.add("Size: " + str(doc.size) + " bytes")
13    else:
14        ot.add("Unable to create new document with " + str(method))
15
16
17ot.clear()
18
19docs = db.documents
20
21if docs.isNone():
22    ot.add("No document support in the database")
23elif db.settings.other_documents:
24    ot.add("Other document support is enabled in this database")
25    ot.add("Major and minor versions support: " + str(db.settings.document_settings.supports_major_and_minor_versions))
26    ot.add(str(docs.total_count) + " documents currently in the database")
27
28    # using deprecated Add
29    doc = docs.add(r"C:\Documents\ExampleDocument1.docx", "My First Document")
30
31    describe_doc(doc, "Add")
32
33    # using Add2 without values
34    doc2 = docs.add2(r"C:\Documents\ExampleDocument2.docx", None, ipDocumentVersion.dvMajor, "My Second Document")
35
36    describe_doc(doc2, "Add2 (no values)")
37
38    # using Add2 with values
39    # first determine document type and columns for file
40    doc_type = db.settings.document_settings.mime_types.find_type_for_extension(r"C:\Documents\ExampleDocument3.docx")
41
42    ot.add("Document Type: " + str(doc_type.key))
43
44    # create some values and populate using ipDocumentKnownColumn values
45    columns = doc_type.columns
46    values = doc_type.create_column_values()
47
48    values.save(columns.known_item(ipDocumentKnownColumn.dkcName).name, "ExampleDocument3")
49    values.save(columns.known_item(ipDocumentKnownColumn.dkcDescription).name, "Some description")
50
51    # to assign a group must use the group ID
52    group = db.settings.document_settings.groups.item("GroupA")
53
54    if not group.isNone():
55        values.save(columns.known_item(ipDocumentKnownColumn.dkcGroup).name, group.id)
56
57    doc3 = docs.add2(r"C:\Documents\ExampleDocument3.docx", values, ipDocumentVersion.dvMinor, "My Third Document")
58
59    describe_doc(doc3, "Add2 (with values)")
60
61    # must reload IDocuments
62    docs2 = db.documents
63    ot.add(str(docs2.total_count) + " documents currently in the database")
64
65else:
66    ot.add("No other document support in the database")