Vector.unique problem

I'm probably doing something wrong but I'm having trouble with Vector.unique();.
This simple button does not strip the duplicates: Unique Test.dcf (1.7 KB)

The same button works fine if I replace the first two enumerator loops with:

for (var eItems = new Enumerator(srcTab.selected); !eItems.atEnd(); eItems.moveNext()) {
		vecTest.push_back = eItems.item();
	}

Please help. :slight_smile:

function OnClick(clickData)
{
	var vecTest = DOpus.NewVector();
	var srcTab = clickData.func.sourcetab;

	for (var eItems = new Enumerator(srcTab.selected); !eItems.atEnd(); eItems.moveNext()) {
		var thisItem = DOpus.FSUtil.GetItem(eItems.item());
		vecTest.push_back = thisItem.realpath;
	}
	for (var eItems = new Enumerator(srcTab.selected); !eItems.atEnd(); eItems.moveNext()) {
		var thisItem = DOpus.FSUtil.GetItem(eItems.item());
		vecTest.push_back = thisItem.realpath;
	}

	for (var eItems = new Enumerator(vecTest); !eItems.atEnd(); eItems.moveNext()) {
		DOpus.Output("Before = " + eItems.item());
	}

	vecTest.unique();

	for (var eItems = new Enumerator(vecTest); !eItems.atEnd(); eItems.moveNext()) {
		DOpus.Output("After = " + eItems.item());
	}
}

It works if you add strings instead of objects, e.g. String(thisItem.realpath).

Yes the issue is that what you're adding to the vector is not actually the same string multiple times, it's multiple different Path objects that happen to represent the same string. The unique function isn't seeing them as the same (because they're not) and so doesn't remove anything.

1 Like

Thanks all.