Community
PowerMill Forum
Welcome to Autodesk’s PowerMill Forums. Share your knowledge, ask questions, and explore popular PowerMill topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to separate Levels and Sets in a macro?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
iamcdn79
377 Views, 8 Replies

How to separate Levels and Sets in a macro?

I have this working macro that arranges levels and sets in alphabetical order but it's not doing it the way I would expect. 

 

I would like the levels in one alphabetical order and the sets in another alphabetical order below the levels but when running it arranges the levels and sets as one instead of separate

 

iamcdn79_0-1718650171721.png

 

 

 

 

 

// Orders Model and Level names Alphabetically
ENTITY LIST models = sort(folder('model'), 'name')
ORDERSESSION model $models[0].name FIRST
int i = 0
FOREACH mod IN models {
	IF $i+1 < size(models) {
	    string previousModel = $models[i].name
		string currentModel = $models[i+1].name
		ORDERSESSION model $currentModel AFTER $previousModel
		$i = $i + 1
	}	
}
// Orders entities within each Level
ENTITY LIST levels = sort(folder('level'), 'name')
ORDERSESSION level $levels[0].name FIRST
int j = 0
FOREACH lev IN levels {
	IF $j+1 < size(levels) {
	    string previousLevel = $levels[j].name
		string currentLevel = $levels[j+1].name
		ORDERSESSION level $currentLevel AFTER $previousLevel
		$j = $j + 1
	}	
}

// Orders entities within each Set
ENTITY LIST sets = sort(folder('set'), 'name')
FOREACH set IN sets {
	ENTITY LIST setEntities = $set.entities
	setEntities = sort(setEntities, 'name')
	int k = 0
	FOREACH set IN setEntities {
		IF $k+1 < size(setEntities) {
		    string previousEntity = $setEntities[k].name
			string currentEntity = $setEntities[k+1].name
			ORDERSESSION set $currentEntity AFTER $previousEntity
			$k = $k + 1
		}	
	}
}

 

 

 

 

 


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

8 REPLIES 8
Message 2 of 9
icse
in reply to: iamcdn79

can you try this:

// Orders Model and Level names Alphabetically
ENTITY LIST models = sort(folder('model'), 'name')
ORDERSESSION model $models[0].name FIRST
int i = 0
FOREACH mod IN models {
	IF $i+1 < size(models) {
	    string previousModel = $models[i].name
		string currentModel = $models[i+1].name
		ORDERSESSION model $currentModel AFTER $previousModel
		$i = $i + 1
	}	
}



// Orders entities within each Level
string list $levels = sort(extract(folder('level'),'Name'))
string list $sets = sort(extract(folder('set'),'Name'))

foreach $lvl in $levels {
	ordersession level ${lvl} last
}

foreach $set in $sets {
	ordersession set ${set} last
}

 

if its in the wrong order you can add the reverse function like this:

string list $levels = reverse(sort(extract(folder('level'),'Name')))
string list $sets = reverse(sort(extract(folder('set'),'Name')))
Message 3 of 9
iamcdn79
in reply to: icse

That didn't work as expected, I got the same result using both options

 

iamcdn79_0-1718707658382.png

 


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 4 of 9
icse
in reply to: iamcdn79

Thats strange...

 

How about to move the levels and sets into subfolders until we find a solution? 

Message 5 of 9
iamcdn79
in reply to: icse

I can just move them manually for now


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 6 of 9
icse
in reply to: iamcdn79

I cant test this atm but does this work?

 

 

 

string list $levels = sort(extract(filter(folder('level'),'this.Type == "level"'),'Name'))
string list $sets = sort(extract(filter(folder('level'),'this.Type == "set"'),'Name'))

foreach $lvl in $levels {
	ordersession level ${lvl} last
}

foreach $set in $sets {
	ordersession level ${set} last
}

 

 

shorter version but probably worse performance:

 

foreach $lvl in sort(extract(filter(folder('level'),'this.Type == "level"'),'Name')) {
	ordersession level ${lvl} last
}

foreach $set in sort(extract(filter(folder('level'),'this.Type == "set"'),'Name')) {
	ordersession level ${set} last
}

 

 

Message 7 of 9
iamcdn79
in reply to: icse

Both versions seem to work the same, haven't noticed a worse performance with the shorter version


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 8 of 9
iamcdn79
in reply to: icse

When running this code Powermill organizes the model names instantly but levels and sets very slowly, is this a Powermill limitation? Or is there something else in the code that can speed up the levels and sets?

 

//Orders Model and Level names Alphabetically
ENTITY LIST models = sort(folder('model'), 'name')
ORDERSESSION model $models[0].name FIRST
int i = 0
FOREACH mod IN models {
	IF $i+1 < size(models) {
	    string previousLevel = $models[i].name
		string currentLevel = $models[i+1].name
		ORDERSESSION model $currentLevel AFTER $previousLevel
		$i = $i + 1
	}	
}

// Extract level names and sort them
string list $levels = sort(extract(filter(folder('level'),'this.Type == "level"'),'Name'))

foreach $lvl in $levels {
	ordersession level ${lvl} last
}
// Extract set names without sorting
STRING LIST $sets = extract(filter(folder('level'),'this.Type == "set"'),'Name')

// Order the sets
foreach $set in $sets {
	ordersession level ${set} last
}

this was the same speed

// Extract level names and sort them
foreach $lvl in sort(extract(filter(folder('level'),'this.Type == "level"'),'Name')) {
	ordersession level ${lvl} last
 }

 

 


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 9 of 9
icse
in reply to: iamcdn79

Yes it seems like moving entities in Powermill is very time consuming.

 

You could write some more fancy algorithm that only moves necessary items. 

Mine just moves every item once even if its in right place.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report