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();