Image
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "AE_ReplacePSD"

-- **************************************************
-- General information about this script
-- **************************************************

AE_ReplacePSD = {}

function AE_ReplacePSD:Name()
	return 'Replace PSD layer source file'
end

function AE_ReplacePSD:Version()
	return '1.1'
end

function AE_ReplacePSD:UILabel()
	return 'Replace PSD layer source file'
end

function AE_ReplacePSD:Creator()
	return 'Alexandra Evseeva'
end

function AE_ReplacePSD:Description()
	return 'Replace Image Layer\'s PSD layer source with the same layer from another PSD, keeping Moho layer\'s size'
end

-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************

function AE_ReplacePSD:IsRelevant(moho)
	return true
end

function AE_ReplacePSD:IsEnabled(moho)
	return true
end



-- **************************************************
-- The guts of this script
-- **************************************************

function AE_ReplacePSD:Run(moho)

	moho.document:PrepUndo(moho.layer)
	moho.document:SetDirty()
	
	local imageLayer = moho:LayerAsImage(moho.layer)
	if not imageLayer then 
		return LM.GUI.Alert(ALERT_WARNING, "Selected layer is not an image layer")
	end
	if not imageLayer:IsPSDImage() then
		return LM.GUI.Alert(ALERT_WARNING, "Selected layer has not a PSD source")	
	end
	
	local oldLayerOrderID = imageLayer:PSDLayerOrderID()
	local oldHeight = imageLayer:Height()
	local oldWidth = imageLayer:Width()
	
	local newFile = LM.GUI.OpenFile("Select replacement file")
	if not newFile then return end
	
	local newFileExt = string.sub(newFile, -3)
	if  newFileExt == "psd" or newFileExt == "PSD" then
		local newFileSignature = newFile .. "*" .. oldLayerOrderID .. "*"
		imageLayer:SetSourceImage(newFileSignature)
	else 
		imageLayer:SetSourceImage(newFile)
	end
	
	local newWidth = imageLayer:Width()
	local scaleAspect = oldWidth/newWidth

	for k=0, imageLayer.fScale:CountKeys()-1 do
		local oldScale = imageLayer.fScale:GetValueByID(k)
		local newScale = oldScale * scaleAspect	
		imageLayer.fScale:SetValueByID(k, newScale)
	end
	
end





Replace PSD
Listed

Script type: Button/Menu

Uploaded: Sep 15 2020, 10:52

Replace lost PSD layer (by order) keeping image size

Installation Options:

This script, and all other scripts on this site are distributed as free software under the GNU General Public License 3.0 or later.
Downloads count: 835