List Attribute Values

This simple utility lists the different values found for the selected attribute. It also shows how many occurrences of each value exist. The results respect the display set so it can be used in combination with filters to analyse how attributes are being used within your module.

pragma runLim,0

DB db = null
DBE dbeResults = null
DBE dbeAttrs = null

string dummy[] = { }
Skip skipAttributes = createString

Module m = current Module

/**
	getAttributes
**/
void getAttributes()
{
	AttrDef ad = null
	string attr = ""
	int index = 0

	for ad in m do
	{
		if (!ad.object) continue

		put(skipAttributes, ad.name, ad.name)
	}

	for attr in skipAttributes do
	{
		insert(dbeAttrs, index, attr, iconNone)
		index++
	}

	set(dbeAttrs, 0, true)
}

/**
	doList
**/
void doList(DB db)
{
	Buffer resBuf = create

	string attr = get(dbeAttrs)

	Module m = current
	Object o = null
	int count = 0

	Skip attrValues = createString
	string s = ""

	for o in m do
	{
		s = o.attr""

		if (find(attrValues, s, count))
		{
			delete(attrValues, s)
			put(attrValues, s, count + 1)
		}
		else
		{
			put(attrValues, s, 1)
		}
	}

	for count in attrValues do
	{
		resBuf += "\"" (string key attrValues)  "\" (" count ")\n"
	}

	delete(attrValues)
	attrValues = null

	set(dbeResults, tempStringOf(resBuf))

	delete(resBuf)
	resBuf = null
}

/**
	buildDialog
**/
void buildDialog()
{
	db = create(current Module, "List Attribute Values")

	label(db, "This utility lists all the different values found for the given attribute.\n")
	dbeAttrs = listView(db, 0, 190, 15, dummy)

	dbeResults = text(db, "Results", "", 60, 150, false)

	apply(db,"OK", doList)

	realize(db)

	insertColumn(dbeAttrs, 0, "", 160, iconNone)
	getAttributes()

	show(db)
}

/**
	listAttributeValues
**/
void listAttributeValues()
{
	m = current Module

	buildDialog()
}

listAttributeValues()