/*
Object and material duplicator.

By Phil Barrenger
philbarrenger@philbarrenger.com

Usage:
select the objects you want to copy and run the script.

Drag the text of the script from a script editor to a toolbar
to create a button that you can then map a key combination.

Any problems please let me know

*/


var osel = new ActiveXObject ( "XSI.Collection" ) ;
osel.addItems ( selection );

dupobjNmat (osel)


function dupobjNmat (osel)
	{
	for (var i = 0 ; i<osel.Count ; i++)
		{
		if (classname (osel(i)) == "X3DObject")
			{	
			var ocopy = Duplicate(osel(i), null ,"siSharedParent", 1, 1, 0, 2, 1, 0, 1,      1, 1, 1, 0, 0, 0, 0, 0, 0, null, 0);
		
			for (var oe = new Enumerator(ocopy(0).Materials) ; !oe.atEnd() ; oe.moveNext() )
				{
					var objmat = Duplicate( oe.item(), null, 2, 1, 1, 0, 2, 1, 0, 1, null, null, null, null, null, null, null, null, null, null, 0);
					objmat(0).Name = objmat(0).Name + "_" + ocopy(0).Name ;
					AssignMaterial( objmat(0) + "," + oe.item().Parent )
				}
			}
		}
	}


