Masking a tree with item rules

Hi All,

I’m running into an issue with a apparently simple component I created. This is how it works:

The component let’s you input multiple masks and will output the masked tree for each of the masks with added to the path, the path of the applied mask.

However the issue I’m facing is that the items are not being masked. Now I understand why, but have no clue on how to mask/filter a branch on it’s items using the regular notation. The mask does have an item rule, but I don’t know how to apply it.

The code I have now is as follows:

    //New output tree and masking error message
    string message = "";
    DataTree<object> masked = new DataTree<object>();

    //Loop through mask tree
    foreach(GH_Path mask_path in M.Paths){
      //Loop through masks in branch
      foreach(string mask_string in M.Branch(mask_path)){
        GH_TreeRules mask = GH_TreeRules.FromString(mask_string, ref message);
        Print("Has item rule? " + mask.HasItemRule.ToString());
        Print("Has path rule? " + mask.HasPathRules.ToString());
        //Loop through input data tree to mask
        foreach(GH_Path p in T.Paths){
            //Generate new path based on existing path plus mask path
            GH_Path new_path = new GH_Path(p);
            foreach(int i in mask_path.Indices){
              new_path = new_path.AppendElement(i);
            //So here I now add the entire branch, but I need to filter the branch on item level
            masked.AddRange(T.Branch(p), new_path);
    msg = message;
    tree = masked;

Should I be using any IGH_Rule derivative? And how would I apply this?
Any help would be great!