Creating Site Documents (Python)

Creating Site Documents (Python)
 1ot = impact.gui.output_toolbox
 2db = impact.active_database
 3
 4ot.clear()
 5siteName = "PHEONIX"
 6site = None
 7try:
 8    site = db.sites.item(siteName)
 9except Exception as exc:
10    impact.gui.output_toolbox.add(f"Failed to create object via db.sites.item(): {exc}")
11
12if not site.isNone():
13    docs = site.documents
14
15    if docs.isNone():
16        ot.add("No site document support in the database")
17    else:
18        ot.add("Site document support is enabled in this database")
19        ot.add(str(docs.count) + " documents for site '" + site.full_name + "' currently in the database")
20        doc = None
21        try:
22            doc = docs.add(r"C:\\Documents\\ExampleDocument1.docx", "My First Document")
23        except Exception as exc:
24            pass
25        impact.gui.output_toolbox.add(f"Failed to create object via docs.add(): {exc}")
26
27        if not doc.isNone():
28            ot.add("Document '" + doc.name + "' successfully created")
29            ot.add("Added: " + str(doc.added_date_time) + " by " + doc.added_by.login_id)
30            ot.add("version: " + doc.version.version_as_string)
31            ot.add("Size: " + str(doc.size) + " bytes")
32
33        else:
34            ot.add("Unable to create new document")
35
36        # must reload IDocuments
37        docs = site.documents
38        ot.add(str(docs.count) + " documents for site '" + site.full_name + "' currently in the database")
39else:
40    ot.add("Unable to locate site " + siteName)