Add this anonymous class to the code:
private static Comparator<IMendixIdentifier> MXIDCOMP = (final IMendixIdentifier i1,
final IMendixIdentifier i2) -> (int) (i1.toLong() - i2.toLong());
The in the code add the sort like below:
//Check if defined reference set could be found
if(!refset.equals(null)){
List<IMendixIdentifier> objs = refset.getValue(getContext());
objs.sort(MXIDCOMP);
To sort the list based in the identifiers (ID’s) then the rest of the code should handle the export in this order.
Be aware this I have not tested this code yet, but it might provide you with some direction.