Creating Documents

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