Back to all posts

Script example: Find unique values of an attribute in any layer

This script example demonstrates how to find the unique values of any attribute in a model layer or background layer. In this example, unique conduit height (GEOM1) and unique conduit cross-section shapes (XSection) are found and printed.

This script is provided as-is, please see the disclaimer below for more information.

Download script

# get unique parameter
def unique(links, parameter):
  lt = []
  for link in links:
    val = link[parameter] # pull in all the attribute values
    if not val in lt:
      lt.append(val)      # create a list of the unique values
  return lt

conduits = pcpy.Map.Layer["Conduits"].get_entities() # get Conduits entities
print unique(conduits, 'XSection') # print unique cross-section shapes
print unique(conduits, 'GEOM1')    # print unique conduit heights

Disclaimer

All scripts are provided as-is, and no warranty is made as to the script's accuracy, completeness, or suitability for any particular purpose. This script may contain errors and require correction or modification by the modeler before its use.

The modeler is obligated to review the script code in its entirety and determine its suitability for its intended usage.

This script may also be updated from time to time to fix issues or provide enhanced functionality. If you have suggestions for improvement, please create a support ticket to let us know.