Sorting a entity list

Sorting a entity list

jsweatherbie
Advocate Advocate
605 Views
2 Replies
Message 1 of 3

Sorting a entity list

jsweatherbie
Advocate
Advocate

Hey everyone I'm trying to get my macro to work and it's either not the results I need or errors lol.... 

 

I have an entity list that I'm looking to sort the tool.type 

 

This is what I have.....

***NOTE: Might have spelling errors but that's not my problem ***

//Tool folder
string $db = 'Tool\'
//Empty lists
string list $sortedTools = {}
Entity list $myTools = reverse(sort(folder($db),'$tool.type'))
foreach $tool.type IN $myTools {

//MACRO CONTINUES.... 
}

 

0 Likes
Accepted solutions (1)
606 Views
2 Replies
Replies (2)
Message 2 of 3

ondrej.mikulec
Advocate
Advocate

This is tricky. It looks like Powermill macros poorly handles (ENUM) types in function for lists. In you macro there are some mistakes, but even after I have corrected them, I was still unable to sort the tools by the 'Type'.

I'm not exactly sure what is your plan but still here is an alternative where the tools are sorted into folders according to its types and then sorted by names inside.

//Tool folder
string $db = 'Tool\'

FOREACH $tl IN folder($db) {
	IF NOT folder_exists('Tool\'+$tl.Type) {
		CREATE FOLDER "Tool" ${$string($tl.Type)}
	}
	EDIT FOLDER ${'Tool\'+$tl.Type} INSERT $tl LAST
}

FOREACH $fld IN get_folders('Tool') {
	FOREACH $tl IN sort(folder($fld),'Name') {
		EDIT FOLDER $fld ORDER ${$fld + "\" + $tl.Name} LAST
	}
}

 

0 Likes
Message 3 of 3

icse
Advisor
Advisor
Accepted solution

this should work:

 

entity list $tools = {}
string list $types = sort(apply(extract(folder('tool'),'Type'),'string(this)'))
int $removed = remove_duplicates($types)

foreach $type in $types {
	foreach $t in filter(folder('tool'),'this.Type =="' + $type + '"') {
		int $index = add_last($tools,entity('tool',$t.Name))
	}
}

string $msg = ''
foreach $t in $tools {
	$msg = $msg + $t.Name + "   " + $t.type + CRLF
	
}
message info $msg