Instance To Duplicate (JScript)

Post Reply
User avatar
bulentgercek
Posts: 2
Joined: 09 Nov 2012, 10:50
Skype: bulentgercek

Instance To Duplicate (JScript)

Post by bulentgercek » 09 Nov 2012, 12:14

Hi ppl,

I want to share my "instance to duplicate" JScript that we are using in our company. Hope it will help someone.

Usage Example :
1) Select "test_Instance" named object (or "test_Instance1", "test_Instance2" it will work with multiple objects)
2) Run the script.
3) It will duplicates the "test" named object and will do "Match all Transform" to the selected instances. After that it will delete instances.

Salutes.

Code: Select all


/**
 * Lighthouse VFX <lhvfx.com> Instance To Dublicate v1.0
 * 
 * @Author Bulent Gercek <bulentgercek@gmail.com>
 */
function instanceChanger()
{
	LogMessage("Lighthouse VFX / Instance To Dublicate v1.0 | Author : Bulent Gercek <bulentgercek@gmail.com>");

	var countStart;
	var objMemory = selectionToMemory();
	
	if (objMemory.length < 1) 
		LogMessage("Warning : Please select one ore more object from scene and try again.");

	for (count=0; count<objMemory.length; count++) {
		
		objNameInfo = nameSplitter(objMemory[count]);
		
		if (objNameInfo) {
			SelectObj("B:" + objNameInfo, null, true);
			Duplicate(Application.selection(0), null, 2, 1, 1, 0, 0, 1, 0, 1, null, null, null, null, null, null, null, null, null, null, 0);
			MatchTransform(Application.selection(0), objNameInfo[0] + "_Instance" + objNameInfo[1], siSRT, null);
			DeleteObj(objNameInfo[0] + "_Instance" + objNameInfo[1]);
			SetValue(Application.selection(0) + ".Name", objNameInfo[0] + "_Instance" + objNameInfo[1], null);
		}
	}
	LogMessage("...");
}

function selectionToMemory()
{
	var objSel = Application.selection;
	var objNameArray = new Array();
	
	for (i=0; i<objSel.count; i++) {
		objNameArray[i] = objSel(i).Name;
	}
	return objNameArray;
}

function nameSplitter(objName)
{
	infoArray = new Array();
	objNameSplitterArray = objName.split("_Instance");
	
	if (objNameSplitterArray.length > 1) {
		infoArray[0] = objNameSplitterArray[0];
		infoArray[1] = objNameSplitterArray[1];
		
		if (objNameSplitterArray[1] != "") infoArray[2] = false; else infoArray[2] = true;
		return infoArray;
	} else {
		LogMessage("Warning : Object '" + objName + "' is not a instance object.");
		return false;
	}
}

/* Run */
instanceChanger();
Attachments
lhvfx_instanceToDuplicate.zip
(1.92 KiB) Downloaded 197 times
Bulent Gercek
Senior CG Technical Director at Lighthouse Visual Effects
www.lhvfx.com

User avatar
ActionArt
Posts: 853
Joined: 25 Nov 2010, 18:23
Location: Canada

Re: Instance To Duplicate (JScript)

Post by ActionArt » 11 Nov 2012, 16:14

Thanks! That could be handy.

User avatar
bulentgercek
Posts: 2
Joined: 09 Nov 2012, 10:50
Skype: bulentgercek

Re: Instance To Duplicate (JScript)

Post by bulentgercek » 11 Nov 2012, 18:37

You're welcome.
Bulent Gercek
Senior CG Technical Director at Lighthouse Visual Effects
www.lhvfx.com

User avatar
ActionArt
Posts: 853
Joined: 25 Nov 2010, 18:23
Location: Canada

Re: Instance To Duplicate (JScript)

Post by ActionArt » 11 Nov 2012, 19:09

BTW, very nice Johnnie Walker sample on you site, I like it.

User avatar
druitre
Posts: 471
Joined: 25 Jun 2009, 23:35

Re: Instance To Duplicate (JScript)

Post by druitre » 12 Nov 2012, 20:58

Ah, nice. Thank you.

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests