Count and Find Items

Count and Find Items
 1# This script shows how to use CountItems and FindItems in the "BySQL" mode.
 2
 3ot = impact.gui.output_toolbox
 4ot.clear()
 5
 6SQL = "D_NAME like 'ACME'"
 7
 8CountOpts = impact.creator.count_items_options()
 9CountOpts.drawing_type = ipDrawingType.dtProject
10CountOpts.sql = SQL
11q_count = impact.active_database.count_items(CountOpts)
12ot.add("Count items: " + str(q_count))
13
14FindOpts = impact.creator.find_items_options()
15FindOpts.sql = SQL
16FindOpts.order_ascending = False
17FindOpts.order_by = "D_NAME"
18FindOpts.max_records = 10
19db_items = impact.active_database.find_items(FindOpts)
20
21if db_items.isNone():
22    ot.add("FindItems: nothing")
23else:
24    ot.add("FindItems: " + str(db_items.count))
25    for item in db_items:
26        ot.add("Project reference: " + str(item.reference))