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

ScriptName = "AM_Merge_Vectors"

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

AM_Merge_Vectors = {}

function AM_Merge_Vectors:Name()
	return 'Merge Vector Layers'
end

function AM_Merge_Vectors:Version()
	return '1.0'
end

function AM_Merge_Vectors:UILabel()
	return 'Merge Vector Layers'
end

function AM_Merge_Vectors:Creator()
	return 'Aleksei Maletin'
end

function AM_Merge_Vectors:Description()
	return ''
end


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

function AM_Merge_Vectors:IsRelevant(moho)
	if moho:LayerAsVector(moho.layer) then
		return true
	else
		return false
	end
end

function AM_Merge_Vectors:IsEnabled(moho)
	local vectorlayer = moho:LayerAsVector(moho.layer)
	local secondarySelection = self:findSecondarySelection(moho)
	if #secondarySelection >=1 and vectorlayer then
		return true
	else
		return false
	end
end

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

function AM_Merge_Vectors:Run(moho)
	moho.document:SetDirty()
	moho.document:PrepUndo(nil)
	
	-- Your code here:
	local selection = {}
	local layer = moho.layer
	table.insert(selection, layer)

	local secondarySelection = self:findSecondarySelection(moho)

	for i = #secondarySelection, 1, -1 do
		local vecLayer = secondarySelection[i]
		local mesh = vecLayer:Mesh()
		moho:SetSelLayer(vecLayer, false, true)
		mesh:SelectAll()
		moho:Copy()
		moho:SetSelLayer(selection[1], false, true)
		moho:Paste()
		moho:DeleteLayer(vecLayer)

	end
	
end

function AM_Merge_Vectors:findSecondarySelection(moho) -- возвращает первый попавшийся слой побочного выделения, если есть

    local primarySelection = moho.layer
	local secondarySelection = {}

	local count = 0

    repeat

		local layer = moho.document:LayerByAbsoluteID(count)

		if layer then

			local selectedLayer = moho.document:GetSelectedLayer(count)

			if selectedLayer then

				if selectedLayer ~= primarySelection then

					local layerAsVector = moho:LayerAsVector(selectedLayer)

					if layerAsVector then

                    	table.insert(secondarySelection, layerAsVector)

					end

				end

			end
			
		end

		count = count + 1

	until not layer

	local invertedTable = {}

    for i = #secondarySelection, 1, -1 do
        table.insert(invertedTable, secondarySelection[i])
    end

    return invertedTable

end

Icon
Merge vector layers
Listed

Script type: Button/Menu

Uploaded: Jan 30 2024, 13:09

Merges selected vector layers
Doesn't compensate for transformations. Just replaces Ctrl+C - Ctrl+V for selected points and removes secondary selected layers.
Shapes may also not transfer correctly.

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