check for duplicate render elements and delete

Is it possible to check for duplicate render elements by Element name and ObjectID and delete duplicates. I have done endless Google searches and cant seem to find anything referring to deleting duplicate render elements. I'm also fairly new to maxscript so I am struggling to know where to even start.

Obviously I would tend to name elements uniquely but have recently come across duplications when merging elements in from other scenes. It's not the end of the world, but you end up with multiple renders of the same ObjectID which I guess uses unnecessary RAM at render time.

Example:

Matte (ObjectID = 50) Duplicated because of same name and ID
Matte (ObjectID = 50) Duplicated because of same name and ID
Matte (ObjectID = 30) Not Duplicated as ObjectID is different

(Delete all duplicates, leaving one iteration of the element in the list)

Any help would be much appreciated.

Comments

Comment viewing options

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

Anubis, That's brilliant!

Anubis,

That's brilliant! Thanks a lot for that, very much appreciated!!!

Anubis's picture

u'r welcome ;)

I not tested the code,
so I glad to know that it works

my recent MAXScripts RSS (archive here)

Anubis's picture

maybe this will do the job?

reNames = #(); reIDs = #(); reElms = #()
rem = MaxOps.GetCurRenderElementMgr()
 
for n = (rem.NumRenderElements()-1) to 0 by -1 do
(
	elm = rem.GetRenderElement n
	index = findItem reNames elm.elementName
	if index == 0 then
	(
		append reNames elm.elementName
		append reIDs elm.mtlID
		append reElms elm
	)
	else
	(
		if reIDs[index] == elm.mtlID do
			rem.RemoveRenderElement elm
	)
)

my recent MAXScripts RSS (archive here)

andrewfox's picture

Can I attempt this on any

Can I attempt this on any other platform? The syntax will be different of course. But code can be the same I hope.

ce89's picture

Yeah go for it. Not sure

Yeah go for it. Not sure exactly what you mean by other platform, but if it helps get nearer the answer then thanks for the help.

br0t's picture

Hi, you can use rem =

Hi, you can use

rem = MaxOps.GetCurRenderElementMgr()

to get access to the render elements, have a look at

showInterface rem

or "Interface: RenderElementMgr" in the MXS documentation for commands are available and how they work.

Cheers

Never get low & slow & out of ideas

ce89's picture

br0t, thanks for the reply.

br0t, thanks for the reply. I've looked through the max docs and roughly understand which methods are needed.

In psudo code I would need something like below: (also to note i'm sat on a train at the minute with very little reference, but something along these line, although I know its a million miles away from correct syntax etc)

dupNames = #()
allNames = #()
re = MaxOps.getCurRenderElementMgr()
fileName = re.GetRenderElementFilename
if (fileName == allNames.filename && gBufferID == gBufferID)
then append dupNames fileName
delete dupNames fileName

-- basically if any duplicated element name is found in the array of all element names, hold this in a dupsNames array and then delete all duplicates.

Sorry for the bad example but like I say I have nothing to hand apart from my phone. There maybe a better way to tackle this without the need to store duplicates before deletion. I kind of know what elements I need, I just cant string them together.

It would really appreciate any help to get to a workable script.

Thanks again.

Comment viewing options

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