Skip to main content
added gif in place of screenshot
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59

You can return the layer list instead of converting to a string and then adapt your syntax a little by using the array_contains function on the output in the expression.

@qgsfunction(args='auto', group='Custom')
def my_filter(layer_group, feature, parent):
    root = QgsProject.instance().layerTreeRoot()
    my_group = root.findGroup(layer_group)
    layer_list = [layer.name() for layer in my_group.children() if layer.isVisible()]
    
    # return the list of layers
    return layer_list

Expression

array_contains(my_filter('my group'), "FIELD_1")

enter image description here

I used Select by Expression to demonstrate the result, rather than rule-based symbology, but the principle remains the same.enter image description here

You can return the layer list instead of converting to a string and then adapt your syntax a little by using the array_contains function on the output in the expression.

@qgsfunction(args='auto', group='Custom')
def my_filter(layer_group, feature, parent):
    root = QgsProject.instance().layerTreeRoot()
    my_group = root.findGroup(layer_group)
    layer_list = [layer.name() for layer in my_group.children() if layer.isVisible()]
    
    # return the list of layers
    return layer_list

Expression

array_contains(my_filter('my group'), "FIELD_1")

enter image description here

I used Select by Expression to demonstrate the result, rather than rule-based symbology, but the principle remains the same.

You can return the layer list instead of converting to a string and then adapt your syntax a little by using the array_contains function on the output in the expression.

@qgsfunction(args='auto', group='Custom')
def my_filter(layer_group, feature, parent):
    root = QgsProject.instance().layerTreeRoot()
    my_group = root.findGroup(layer_group)
    layer_list = [layer.name() for layer in my_group.children() if layer.isVisible()]
    
    # return the list of layers
    return layer_list

Expression

array_contains(my_filter('my group'), "FIELD_1")

enter image description here

Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59

You can return the layer list instead of converting to a string and then adapt your syntax a little by using the array_contains function on the output in the expression.

@qgsfunction(args='auto', group='Custom')
def my_filter(layer_group, feature, parent):
    root = QgsProject.instance().layerTreeRoot()
    my_group = root.findGroup(layer_group)
    layer_list = [layer.name() for layer in my_group.children() if layer.isVisible()]
    
    # return the list of layers
    return layer_list

Expression

array_contains(my_filter('my group'), "FIELD_1")

enter image description here

I used Select by Expression to demonstrate the result, rather than rule-based symbology, but the principle remains the same.