Example of FindItemsByQueryWithMax2¶
Example of FindItemsByQueryWithMax2¶
1# This example finds database items using a specified query and displays the
2# references of any items found in the output toolbox. The number of items found is capped at 2.
3
4# Create a local variable for the output toolbox
5ot = impact.gui.output_toolbox
6
7# Clear the output toolbox
8ot.clear()
9
10# Create a local variable for the active database
11db = impact.active_database
12
13# Create a local variable for the name of the query
14query_name = "Contains a"
15
16# Get the query to find items by
17query = db.find_master_tool_setting(query_name, ipMasterSettingType.mstDBQuery)
18
19# Check the query exists
20if query is None:
21
22 # Add a message to the output toolbox
23 ot.add("Unable to find query '" + str(query_name) + "'")
24
25else:
26
27 # Find the database items using the specified query, but limit to 2 items
28 items = db.find_items_by_query_with_max2(query, 2)
29
30 # Wrap variant return items with Impact.py wrapper
31 if items is not None:
32 items = [IDatabaseItem(item) for item in items]
33
34 # check that some items were returned
35 if items:
36
37 # iterate all the items
38 for i in range(0, len(items) - 1 + 1):
39
40 # Create a local variable for the database item
41 db_item = items[i]
42
43 # display the reference of the database item in the output toolbox
44 ot.add(db_item.reference)
45
46 else:
47
48 # Add a message to the output toolbox
49 ot.add("No items found using query '" + str(query_name) + "'")