Using IDocumentCreator for Unsaved Projects¶
Using IDocumentCreator for Unsaved Projects¶
1ot = impact.gui.output_toolbox
2db = impact.active_database
3
4ot.clear()
5
6# create a new project
7drawing = db.create_item(ipDrawingType.dtProject, None)
8
9if not drawing.isNone():
10 ot.add("Successfully created new project")
11
12 docs = db.documents
13
14 doc_creator = drawing.document_creator
15
16 if doc_creator is None:
17 ot.add("No project document support in the database")
18 else:
19 ot.add("Project document support is enabled in this database")
20
21 auto_relationship = doc_creator.auto_relationship
22
23 if not auto_relationship.isNone():
24
25 # Optional: change the default relationships that will be created
26 auto_relationship.document_latest_version = False
27
28 # Add a local document and assign properties
29 doc1 = doc_creator.add_local_file(r"C:\\Documents\\ExampleDocument1.docx")
30
31 if not doc1.isNone():
32 ot.add("Successfully added document " + str(doc1.local_file_path))
33
34 doc1.name = "My First Document"
35 doc1.description = "A description of my document"
36 doc1.tags.add("TagOne")
37 doc1.tags.add("TagTwo")
38
39 # Optional: for this doc the default relationship should always be to the latest version
40 doc1.auto_relationship = ipDocumentCreatorAutoRelationship.dcarLatestVersion
41
42 # Set a comment for the add history item
43 doc_creator.comments = "Adding documents for unsaved project from COM script"
44
45 # Save the project (which will also add the documents)
46 folder = db.projects.find("COMTests")
47
48 drawing.customer = db.customers.find_by_code("ACME CORP")
49
50 if drawing.save_as("", "Documents when saving", "", folder, True):
51 ot.add("Successfully saved project")
52
53 db_item = drawing.database_item
54
55 if db_item.documents.count > 0:
56 ot.add("Project documents added: " + str(db_item.documents.count))
57
58 for doc in db_item.documents:
59 ot.add(" Project document " + str(doc.name))
60
61 db_item.close_and_release()
62
63 else:
64 ot.add("No project documents added")
65
66 else:
67 ot.add("Failed to save project - no project documents added")
68
69