Copying Documents (Python)¶
Copying 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")
23
24 # copy the document to a fully qualified name
25 dest = r"C:\\Documents\\AcmeSpec.docx"
26
27 if doc.copy_to(dest):
28 ot.add("Successfully copied document to '" + dest + "'")
29 else:
30 ot.add("Unable to copy the document to '" + dest + "'")
31
32 # copy the document into a folder
33 dest = "C:\\Documents\\"
34
35 if doc.copy_to(dest):
36 ot.add("Successfully copied document to '" + dest + doc.name + "'")
37 else:
38 ot.add("Unable to copy the document to '" + dest + doc.name + "'")
39
40 else:
41 ot.add("Unable to locate document")
42
43else:
44 ot.add("Unable to locate a customer")