Updating Project values from IDatabaseItem¶
Updating Project values from IDatabaseItem¶
1# This script demonstrates updating project database values using an IDatabaseItem object
2# directly, rather than opening/updating an IDrawing. You can only update database values
3# in this way if no user has the IDatabaseItem checked out.
4
5
6# Updating values using the IDatabaseValues objects retrieved from an IDatabaseItem object
7# will automatically generate a new IDatabaseRevision with a comment showing all database
8# values that were updated. It will also update the modification date/time and user for the
9# IDatabaseItem.
10
11ad_type_binary = 1
12project_code_to_find = "P061932"
13customer_code_to_find = "H029"
14picture_file = "D:\andy.jpg"
15
16db = impact.active_database
17ot = impact.gui.output_toolbox
18
19# NOTE: This will only have an effect using n_server
20db.application_name = "WEBcnx"
21
22
23def read_binary_file(file_name):
24
25 # create stream object
26 # stream = CreateObject("ADODB.Stream")
27
28 # load the file data from disk to stream object
29 stream.open()
30 stream.type = ad_type_binary
31 stream.load_from_file(file_name)
32
33 # get binary data from the object
34 read_binary_file = stream.read
35
36def show_modification_and_revisions():
37
38 # need to ensure we refresh modification info from database
39 item.refresh()
40
41 ot.add(" Modified: " + str(item.modified_date_time))
42 ot.add(" Modified By: " + str(item.modified_by.full_name))
43 ot.add(" Revision Count: " + str(item.revisions.count))
44 for r in item.revisions:
45 ot.add(" Revision " + str(r.created_date_time))
46 ot.add(" Comments: " + str(r.comments))
47
48
49ot.clear()
50
51item = db.find_item_by_code(ipDrawingType.dtProject, project_code_to_find)
52
53if item is not None:
54 ot.add("Code: " + str(item.code))
55 ot.add("reference: " + str(item.reference))
56 ot.add("customer: " + str(item.customer.name))
57 ot.add("Modified: " + str(item.modified_date_time))
58 ot.add("Modified By: " + str(item.modified_by.full_name))
59 ot.add("")
60
61 ShowModificationAndRevisions()
62
63 ot.add("==== Updating customer ====")
64 item.change_customer(db.customers.find_by_code(customer_code_to_find), "Corporate Rename")
65 ShowModificationAndRevisions()
66
67 ot.add("==== Updating LAYERS/ONE_UP with no changes ====")
68 db_values = item.layers.item(1).values
69
70 # no REVISION should be created
71 db_values.do_update()
72 ShowModificationAndRevisions()
73
74 ot.add("==== Updating LAYERS/ONE_UP values ====")
75
76 db_values.save("LAYERS.L_CODE", "ABCD")
77 db_values.save("OU_INT", 10)
78 db_values.save("OU_REAL", 25.4)
79 db_values.save("OU_CUTAREA", "1000 sqmm")
80
81 # REVISION containing changes should be created
82 db_values.do_update()
83 ShowModificationAndRevisions()
84
85 ot.add("==== Updating DRAWINGS with no changes ====")
86 db_values = item.values
87
88 # no REVISION should be created
89 db_values.do_update()
90 ShowModificationAndRevisions()
91
92 ot.add("==== Updating DRAWINGS values ====")
93 db_values = item.values
94
95 db_values.save("D_INK1", 20)
96 db_values.save("D_ORDERNUM", "#CS564723")
97 db_values.save("D_NOTES", "A multi-line comment" + "\r\n" + "where only the first line should be included")
98 db_values.save("D_MYPIC", read_binary_file(picture_file))
99
100 # REVISION containing changes should be created - incl memo first line onlt and BLOB size
101 db_values.do_update()
102 ShowModificationAndRevisions()
103
104 ot.add("==== Updating D_MODDATE/D_MODTIME/D_MODBY ====")
105
106 # you can explicitly set these values and they won't be updated
107 db_values.save("D_MODDATE", "2010-01-31")
108 db_values.save("D_MODTIME", "11:10:30")
109 db_values.save("D_MODBY", 5)
110 db_values.do_update()
111 ShowModificationAndRevisions()
112
113else:
114 ot.add("Unable to locate project " + str(project_code_to_find))