Searching on multiple Tabular Columns at once (i.e. search per-row)
Is it possible to search on tabular rows based on column values. I know we can specify a value for in_column
when creating attribute.search_criterion()
, which is a step in the right direction, but I want to be able to conditionally search on rows, for example, I want to check for rows where Column 1 has a value of "ABC", Column 2 has a value of "DEF", and Column 3 has a value of "GHI".
It's possible via Viewer, but is it possible via the STK?
Answers
-
This should be possible, the example code below will perform a search in the MI Training database for records where both of the following are true:
1. The columnOrder
in the attributeCharacterization of this material
is 1
2. The columnTechnique
in the attributeCharacterization of this material
is Light microscopyOn a stock installation of MI Training you should see one result - the record Titanium (Ti)
from GRANTA_MIScriptingToolkit import granta as mpy session = mpy.Session("http://your.mi.host/mi_servicelayer", autologon=True) database = session.get_db(db_key="MI_Training") table = database.get_table("Training Exercise for Import") attribute = table.attributes["Characterization of this material"] criterion_order = mpy.SearchCriterion(attribute=attribute, operator="EQUAL", value=1, column_name="Order") criterion_technique = mpy.SearchCriterion(attribute=attribute, operator="CONTAINS_ALL", value=["Light microscopy"], column_name="Technique") table.search_for_records_where([criterion_order, criterion_technique])
0 -
This isn't quite what I was looking for. I'm more looking for conditional searching per row.
For example:
If Record 1 has a tabular attribute that looks like this:
C1 C2 C3 C4 C5 A 1 7 3 5 B 2 8 4 6 And Record 2 has a tabular attribute that looks like this:
C1 C2 C3 C4 C5 A 2 8 4 6 B 1 7 3 5 I want to be able to do a search that returns me all records with a tabular attribute that have a row with a C1 value of A, that also have a C3 value of 8 and C5 value of 6, as well as another row with a C1 value of B, that has a C2 value of 1, and a C4 value of 3.
Doing that search in MI Viewer would return only Record 2, but if I did it via the STK, The search criterion would end up returning Record 1 as well, since the tabular attribute does have a C1 with A and B, a C2 with 1, a C3 with 8, a C4 with 3, and a C5 with 6, which would not be the intended behavior, since my criteria is row specific depending on the first criterion.
0