Updating Documents (Python)¶
Updating Documents (Python)¶
1ot = impact.gui.output_toolbox
2db = impact.active_database
3
4ot.clear()
5cust = db.customers.find_by_code("ACME CORP")
6
7if not cust.isNone():
8 docs = cust.documents
9
10 if docs.isNone():
11 ot.add("No customer document support in the database")
12 else:
13 ot.add("customer document support is enabled in this database")
14 doc = None
15 try:
16 doc = docs.item("Acme Corporation Specifications.docx")
17 except Exception as exc:
18 pass
19 impact.gui.output_toolbox.add(f"Failed to create object via docs.item(): {exc}")
20
21 if not doc.isNone():
22 ot.add("Document: '" + doc.name + "', impact.creator: " + doc.added_by.login_id + ", Size: " + doc.size + " bytes, version: " + doc.version.as_string)
23 latestDoc = doc.latest_version
24 ot.add("Latest document: '" + latestDoc.name + "', impact.creator: " + latestDoc.added_by.login_id + ", Size: " + latestDoc.size + " bytes, version: " + latestDoc.version.as_string)
25
26 db.errors.clear()
27 if latestDoc.checkout():
28
29 ot.add("Successfully checked out document")
30 activeDoc = latestDoc.active_checkout
31
32 source = r"C:\\Documents\\Acme Corporation Specifications v2.docx"
33
34 if activeDoc.update_from(source):
35 ot.add("Successfully updated document from '" + source + "'")
36
37 if activeDoc.checkin(ipDocumentVersion.dvMajor, "Some checkin comments"):
38 ot.add("Successfully checked in document")
39 else:
40 ot.add("Unable to checkin document")
41
42 else:
43 ot.add("Unable to update document from '" + source + "'")
44
45 else:
46 ot.add("Unable to checkout document")
47
48 if db.errors.count > 0:
49 impact.gui.output_toolbox.add(str(db.errors.last.description))
50
51 else:
52 ot.add("Unable to locate document")
53
54else:
55 ot.add("Unable to locate a customer")