Simple Update (Python)

Simple Update (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            # We don't actually need to specify the Action because the project has
32            # been modified the Action is automatically set to ipReleaseAction.raUpdate
33            dbItem.release_action.action = ipReleaseAction.raUpdate
34
35            if dbItem.close_and_release():
36                impact.gui.output_toolbox.add("Successfully closed and released the project")
37            else:
38                impact.gui.output_toolbox.add("Error: Unable to release the project")
39
40        else:
41            impact.gui.output_toolbox.add("Error: Unable to save the project")
42
43    else:
44        impact.gui.output_toolbox.add("Error: Unable to save as the project")
45
46else:
47    impact.gui.output_toolbox.add("Error: Unable to create new project")