Saving Projects (Python)¶
Saving Projects (Python)¶
1drawing = impact.active_drawing
2database = impact.active_database
3
4if not drawing.isNone():
5
6 # This script only works for projects, but it could easily be adapted
7 # by simply ensuring that the IFolder was valid for the drawing.drawing_type
8 if drawing.drawing_type == ipDrawingType.dtProject:
9 dbItem = drawing.database_item
10
11 if dbItem.isNone():
12 folder = None
13 try:
14 folder = database.projects.find("COMTests")
15 except Exception as exc:
16 pass
17 impact.gui.output_toolbox.add(f"Failed to create object via database.projects.find(): {exc}")
18
19 drawing.customer = database.customers.find_by_code("(DEFAULT)")
20
21 # Save the new project, we don't supply a Code we want it automatically
22 # generated, plus not supplying a description will use the existing one
23 saved = drawing.save_as("", "DB Save Test 1", "", folder, False)
24
25 else:
26
27 saved = drawing.save()
28
29 if saved:
30 impact.gui.output_toolbox.add("Successfully saved '" + drawing.full_name + "'")
31 else:
32 impact.gui.output_toolbox.add("Unable to save " + drawing.full_name)
33
34 else:
35 impact.gui.output_toolbox.add("Current drawing is not a project")