I need a little script to delete last MatID(Mesh)

Hello, i spent a lot of time on making this stuff and first time i release it, but second i couldn't make it again,
to delete last MatID(mesh) by 1 click, can someone help me with this ?
IT's a simple script when you select a mesh and press button - it deletes last MaTID(mesh).

P.S.

And if it possible http://dfiles.ru/files/owsepv1vr to modifie this script(its .psk file importer) and add to it a possibility to insert special mesh(On the importing model), while importing the file, with position controlling rulers.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

Yep. I think that

Yep. I think that "apendIfUnique" cause the problem here

bga

barigazy's picture

You asked a script. Here we

You asked a script. Here we go

try(destroydialog ::testRoll) catch() 
rollout testRoll "Delete LastMTLID Faces"
(
	fn deleteLastMtlIDfaces obj =
	( 
		local arr = #()
		for f in 1 to obj.numfaces do appendIfUnique arr (getFaceMatID obj f)
		lastIDFaces = sort (for f = 1 to obj.numfaces where (getFaceMatID obj f) == (amax arr) collect f)
		for f = lastIDFaces.count to 1 by -1 do deleteFace obj lastIDFaces[f]
		update obj
	)
	button theButton "Do the JOB!" pos:[5,5] width:140 height:40
 
	on theButton pressed do 
	(
		if selection.count != 0 do 
		(
			for o in selection where iskindof o Editable_Mesh do deleteLastMtlIDfaces o
		)
	)
)
createDialog testRoll 150 50 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)		

bga

Anubis's picture

I see you already helps here

The term "last MatID" is very funny... I need to read your code to see that this is translates as "most higher MatID" :)

Anyway, is next (untested) function is more optimized?

fn delfaces obj = (
	local lastID = 0, currID, aFaces
	for f = 1 to obj.numFaces do
	if (currID = getFaceMatID obj f) > lastID do
		lastID = currID
	aFaces = for f = 1 to obj.numFaces where \
	(currID = getFaceMatID obj f) == lastID \
		collect f
	meshop.deleteFaces obj aFaces
)

my recent MAXScripts RSS (archive here)

barigazy's picture

try this one

fn deleteLastMtlIDfaces obj = if iskindof obj Editable_Mesh do
( 
	local arr = #()
	for f in 1 to obj.numfaces do appendIfUnique arr (getFaceMatID $ f)
	lastIDFaces = sort (for f = 1 to obj.numfaces where (getFaceMatID $ f) == (amax arr) collect f)
	for f = lastIDFaces.count to 1 by -1 do deleteFace obj lastIDFaces[f]
	update obj
)
--example 
deleteLastMtlIDfaces $

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.