cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Regex support for model tree searches

Regex support for model tree searches

Not sure if this has been suggested before - I was unable to find it.

Are there any plans to add regular expression support to the search function in the model tree? Search results can get fairly clunky in larger models, but this would allow for more refined searches.

I have attached an example for a way I would like to use this. I'm looking for all references to column 8 of "Material_Table". Without regex, and because I don't have a specific row to look for, it would seem my only options are to search for Material_Table and sift through a few thousand results, or search for "8" which would be even worse.

1654094478157.png

 

2 Comments
JordanLJohnson
Autodesk

This seems like a fine idea. In the meantime, you can actually write some FlexScript that will help. The following script finds all text with at least one regex match. It prints the node and line number to the console. It doesn't find all matches within a node, though. But it should narrow down your search considerably:

treenode root = model();
int searchNames = 1;
int searchText = 1;

Array toSearch = [root];
while (toSearch.length) {
    treenode target = toSearch.pop();
    
    toSearch.append(target.subnodes.toArray());
    treenode attr = target.find(">1");
    while (attr) {
        toSearch.push(attr);
        attr = attr.next;
    }
    
    if (searchNames) {
        int index = target.name.search(/MaterialTable\[\d\]\[8\]/g);
        if (index >= 1) {
            print(target);
            continue;
        }
    }
    
    if (target.dataType == DATATYPE_STRING && searchText) {
        int index = target.value.search(/MaterialTable\[\d\]\[8\]/g);
        if (index >= 1) {
            int line = 1;
            for (int i = 1; i <= index; i++) {
                if (target.value.charAt(i) == "\n") {
                    line++;
                }
            }
            print(target, ", line ", line);
        }
    }
}

RegexSearchDemo.fsm

thomas_smithWKC4J
Enthusiast
Very interesting solution. Thank you for sharing.

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea