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

ScriptName = "AE_ResetLayerOrigin"

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

AE_ResetLayerOrigin = {}

function AE_ResetLayerOrigin:Name()
	return "Reset Layer Origin"
end

function AE_ResetLayerOrigin:Version()
	return "1.0"
end

function AE_ResetLayerOrigin:UILabel()
	return "Reset Layer Origin"
end

function AE_ResetLayerOrigin:Creator()
	return "Alexandra Evseeva"
end

function AE_ResetLayerOrigin:Description()
	return "Set layer origin to zero value saving its global location"
end




-- **************************************************
-- Recurring values
-- **************************************************

-- AE_ResetLayerOrigin.value1 = false

-- **************************************************
-- Is Enabled
-- **************************************************

function AE_ResetLayerOrigin:IsEnabled(moho)
	return true
end


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

function AE_ResetLayerOrigin:Run(moho)

	moho.document:PrepUndo(moho.layer)
	moho.document:SetDirty()
	
	local mainLayer = moho.layer
	local oldOrigin = mainLayer:Origin()
	local oldOriginV3 = LM.Vector3:new_local()
	oldOriginV3:Set(oldOrigin.x, oldOrigin.y, 0)
	local currentPos = mainLayer.fTranslation:GetValue(moho.layerFrame)
	mainLayer.fTranslation:SetValue(moho.layerFrame, currentPos + oldOriginV3)
	if mainLayer:LayerType() == MOHO.LT_VECTOR then
		local mesh = moho:LayerAsVector(mainLayer):Mesh()
		for p = 0, mesh:CountPoints()-1 do
			local point = mesh:Point(p)
			local pointPos = point.fAnimPos:GetValue(moho.layerFrame)
			point.fAnimPos:SetValue(moho.layerFrame, pointPos - oldOrigin)
		end
	end
	if mainLayer:IsGroupType() then
		local group = moho:LayerAsGroup(mainLayer)
		for ch = 0, group:CountLayers()-1 do
			local childLayer = group:Layer(ch)
			local childPos = childLayer.fTranslation:GetValue(moho.layerFrame)
			childLayer.fTranslation:SetValue(moho.layerFrame, childPos - oldOriginV3)
		end
	end
	local zeroVec = LM.Vector2:new_local()
	mainLayer:SetOrigin(zeroVec)
	
end





Reset layer origin
Listed

Script type: Button/Menu

Uploaded: Sep 14 2021, 01:01

Script Version: 1.0

Sets layer origin to [0,0] without changing of visual layer position (transforming its vertices instead)

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: 1194