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