Pseudo Attributes Criteria Search using STK

Ansys Staff
Ansys Staff Member, Employee Posts: 27
Ansys Employee Name Dropper First Comment Photogenic
edited June 28 in Materials

Can you run a criteria search through a database/table using pseudo attributes with Granta MI Python Scripting Toolkit 2.3 ?

For example finding all records within a given table that have been modified in the last 24 hours.


  • Doug Addy
    Doug Addy Member, Employee Posts: 20
    5 Answers 10 Comments First Anniversary Name Dropper
    Answer ✓

    This is possible but the approach is slightly different than searching on Attributes. In a future version we intend to make this more discoverable.

    The approach is to create a SearchCriterion object directly, this can then be passed to table.search_for_records_where as normal.

    import granta as mpy
    from datetime import datetime, timedelta
    s = mpy.Session('mi-server', autologon=True)
    db = s.dbs[0]
    table = db.get_table('TableName')
    now ="%Y-%m-%dT%H:%M:%S")
    early = ("%Y-%m-%dT%H:%M:%S")
    ref = mpy.PseudoAttributeDefinition('modifiedDate')
    val = (early, now)
    sc = mpy.SearchCriterion(ref, 'BETWEEN', value=val)
    recs = table.search_for_records_where([sc])

    There are a few things to note here:

    1. Performing this search on a database will return multiple copies of each record, so I suggest you perform the search on a specific table.
    2. You must pass the search value as a tuple of strings, there is a known issue with passing datetime.datetime objects.
    3. The docstring and type hint for SearchCriterion does not list PseudoAttributeDefinition as a valid type. It is.

    The documentation does not make clear exactly which Pseudoattributes can be searched on, for the moment the list is below for reference. Only the Pseudoattributes listed below the search criterion can be searched with that criterion, and only those criteria support searches on Pseudoattributes.


    • modifiedDate
    • createdDate


    • lastModifier
    • creator
    • name


    • recordColor
    • recordType


    • recordColor
    • recordType
    • versionState