/////////////////////////////////////////////////////////////////////////
//																			
// 直接复制 V1.01												
// 作者: Brennan Chapman													
//																			
// 创建合成副本,包括子合成.		
// 当然,如果某个合成重复使用,只会复制一次
// 其他的重复项也会指向该合成				 
//																			
////////////////////////////////////////////////////////////////////////

function duplicateStructure(comp) {
	// Duplicate the incoming comp
	var comp = comp.duplicate();
	
	// For each of the layers in the comp, check for subcomps
	for (var i=1; i<=comp.numLayers; i++) {

		var layer = comp.layer(i);
		//Check if layer has a source and that its type is a composition
		if (layer.source && layer.source.typeName == "Composition") {
		
			// Check if this comp has already been duplicated
			check = checkPreviousComps(layer.source.id);
			
			if (check == null) {
				// The subcomp hasn't been duplicated before
				
				// Store the original comp id to remember the correlation
				var sourceID = layer.source.id;
				// Replace the source of the layer, and recursively check in that subcomp for sub-subcomps
				layer.replaceSource(duplicateStructure(layer.source), false);	
				// Store the new comp id to remember the correlation
				var destID = layer.source.id;
				//Add the correlation to an array
				previousComps[sourceID] = destID;
			} else {
				// Replace the source with the already duplicated comp
				layer.replaceSource(check, false);
			}
		}
	}

	// For the recursion, return the duplicate comp
	return comp;
}

// Checks previous duplications to make sure a comp isn't duplicated twice
function checkPreviousComps(checkID) {
		if (previousComps[checkID]) {
				return getItemWithID(previousComps[checkID]);
		}
		return null;
}
	
// Returns the proect item with the specified ID
function getItemWithID(id) {
	for (x=1; x<=app.project.numItems; x++) {
		if (app.project.item(x).id == id) {
			return app.project.item(x);
		}
	}
	return null;
}

mainComp = app.project.activeItem;
if (mainComp && mainComp.typeName == "Composition") {
	app.beginUndoGroup("Duplicate Hierarchy");

	previousComps = [];

	// Go!
	duplicateStructure(mainComp);

	app.endUndoGroup();
} else if (!mainComp) {
	alert("请选择一个合成进行复制.");
} else {
	alert("ERROR: 没有选择合成.\n	请在项目面板重新选择.");
}

Leave a Reply

Your email address will not be published.

请下载到本地观看!因为pdf是用的阿里云盘预览,可能部分字体加载不了。

请安装油猴脚本,并下载月离的万事屋脚本

请在右上角三个点 - 下载管理 - 找到刚才的文件,选择允许下载。 或者换个浏览器
echo