Simple Discard (Python)¶
Simple Discard (Python)¶
1db = impact.active_database
2
3impact.gui.output_toolbox.clear()
4drawing = db.create_item(ipDrawingType.dtProject, "")
5
6if not drawing.isNone():
7
8 impact.gui.output_toolbox.add("Created new project")
9
10 drawing.customer = db.customers.find_by_code("(DEFAULT)")
11
12 impact.gui.output_toolbox.add("Finding folder r'\\COMTests'")
13 folder = None
14 try:
15 folder = db.projects.find("COMTests")
16 except Exception as exc:
17 pass
18 impact.gui.output_toolbox.add(f"Failed to create object via db.projects.find(): {exc}")
19
20 if drawing.save_as("", "COM Update Test", "", folder, True):
21
22 impact.gui.output_toolbox.add("Successfully saved project")
23 dbItem = drawing.database_item
24
25 # Modify and save the drawing
26 drawing.active_layer.active_block.moved(0, 0)
27 drawing.active_layer.active_block.line_ad(100, 100)
28
29 if drawing.save():
30
31 # Force a discard even if the project has been modified
32 dbItem.release_action.action = ipReleaseAction.raDiscard
33
34 if dbItem.close_and_release():
35 impact.gui.output_toolbox.add("Successfully closed and released the project")
36 else:
37 impact.gui.output_toolbox.add("Error: Unable to release the project")
38
39 else:
40 impact.gui.output_toolbox.add("Error: Unable to save the project")
41
42 else:
43 impact.gui.output_toolbox.add("Error: Unable to save as the project")
44
45else:
46 impact.gui.output_toolbox.add("Error: Unable to create new project")