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