Merge Layers Script?
Moderators: Víctor Paredes, Belgarath, slowtiger
Merge Layers Script?
Has anyone written a Merge Layers Script to save constantly cutting/pasting and deleting layers?
Cheers
D.K
Cheers
D.K
http://www.creativetvandmedia.com
My store on Renderosity:
https://www.renderosity.com/mod/bcs/?uid=921315
My store on Renderosity:
https://www.renderosity.com/mod/bcs/?uid=921315
- synthsin75
- Posts: 10041
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Merge Layers Script?
Not that I know of. Would you just need all selected vector layers to be merged to one new layer? If so, that's pretty easy to whip up.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Re: Merge Layers Script?
The only real gotcha I can think of is: What do you do with Layer differences? i.e. Transforms, Properties, Anim Keyframes, References ... or are these just ignored?
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
Re: Merge Layers Script?
I was reading about A Evseeva's Reset Layer Origin. I haven't tried it yet but it sounds like it resets the origin position while preserving the visual position of the vectors, so I'm assuming it's resetting the origin and also offsetting the vector art with a transform.
I guess something like that would have to occur for each layer selected for the merge?
I guess something like that would have to occur for each layer selected for the merge?
D.R. Greenlaw
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
- synthsin75
- Posts: 10041
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Merge Layers Script?
EDIT: This version doesn't select the curves for you. Please use the second version below.
Real quick, just doing as described, e.g. cut, paste, and delete layers:
If you don't want it automatically deleting the layers, you can change Syn_MergeVectors.delete to false.
This doesn't handle any layer transforms, effects, parent transforms, animation, etc..
Real quick, just doing as described, e.g. cut, paste, and delete layers:
Code: Select all
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "Syn_MergeVectors"
-- **************************************************
-- General information about this script
-- **************************************************
Syn_MergeVectors = {}
function Syn_MergeVectors:Name()
return "Merge Vectors"
end
function Syn_MergeVectors:Version()
return "1.0"
end
function Syn_MergeVectors:Description()
return "Merge all selected vector layers"
end
function Syn_MergeVectors:Creator()
return "(c)2021 J.Wesley Fowler (synthsin75)"
end
function Syn_MergeVectors:UILabel()
return("SYN: Merge Vectors")
end
-- **************************************************
-- Recurring values
-- **************************************************
Syn_MergeVectors.delete = true --true to delete merged layers, otherwise false
-- **************************************************
-- The guts of this script
-- **************************************************
function Syn_MergeVectors:Run(moho)
moho.document:PrepUndo()
moho.document:SetDirty()
local layers = {}
local count = 0
repeat
local layer = moho.document:LayerByAbsoluteID(count)
if layer then
count = count + 1
if (layer:SecondarySelection() and layer:LayerType() == MOHO.LT_VECTOR) then
table.insert(layers, moho:LayerAsVector(layer))
end
end
until not layer
local merge = moho:CreateNewLayer(MOHO.LT_VECTOR, false)
merge:SetName("Merged "..count.." vector layers")
moho:SetSelLayer(merge)
for i,v in ipairs(layers) do
moho:Copy(v:Mesh())
moho:Paste()
end
if (not self.delete) then
moho:SetSelLayer(layers[#layers])
end
for i=#layers, 1, -1 do
if (self.delete) then
moho:DeleteLayer(layers[i])
else
layers[i]:SetSecondarySelection(true)
end
end
end
This doesn't handle any layer transforms, effects, parent transforms, animation, etc..
Last edited by synthsin75 on Wed Dec 27, 2023 8:48 pm, edited 1 time in total.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Re: Merge Layers Script?
Haven't tried it (yet) - but you appear to be merging down into a new Layer. I would have thought a preference might be to merge into an existing (last selected) target layer.
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
- synthsin75
- Posts: 10041
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Merge Layers Script?
If that works better for people, DK?, I can always do that instead. But if anyone wants to leave the merged layers unaltered and undeleted (non-destructive merge), making a new layer keeps that an option.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- synthsin75
- Posts: 10041
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Merge Layers Script?
Here's a version with just a destructive option:
If Syn_MergeVectors.destructive is set to true, it merges to the last selected layer, if false, it creates a new layer, so it's completely non-destructive.
Code: Select all
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "Syn_MergeVectors"
-- **************************************************
-- General information about this script
-- **************************************************
Syn_MergeVectors = {}
function Syn_MergeVectors:Name()
return "Merge Vectors"
end
function Syn_MergeVectors:Version()
return "1.1"
end
function Syn_MergeVectors:Description()
return "Merge all selected vector layers"
end
function Syn_MergeVectors:Creator()
return "(c)2021 J.Wesley Fowler (synthsin75)"
end
function Syn_MergeVectors:UILabel()
return("SYN: Merge Vectors")
end
-- **************************************************
-- Recurring values
-- **************************************************
Syn_MergeVectors.destructive = true --true to delete merged layers, otherwise false
-- **************************************************
-- The guts of this script
-- **************************************************
function Syn_MergeVectors:Run(moho)
moho.document:PrepUndo()
moho.document:SetDirty()
local layers = {}
local count = 0
repeat
local layer = moho.document:LayerByAbsoluteID(count)
if layer then
count = count + 1
if (layer:SecondarySelection() and layer:LayerType() == MOHO.LT_VECTOR) then
table.insert(layers, moho:LayerAsVector(layer))
end
end
until not layer
local merge
if (not self.destructive) then
merge = moho:CreateNewLayer(MOHO.LT_VECTOR, false)
merge:SetName("Merged "..count.." vector layers")
else
merge = moho.layer
end
moho:SetSelLayer(merge)
for i,v in ipairs(layers) do
if (v ~= merge) then
v:Mesh():SelectAll()
moho:Copy(v:Mesh())
moho:Paste()
end
end
if (not self.destructive) then
moho:SetSelLayer(layers[1])
end
for i=#layers, 1, -1 do
if (self.destructive and layers[i] ~= merge) then
moho:DeleteLayer(layers[i])
elseif (not self.destructive) then
layers[i]:SetSecondarySelection(true)
end
end
end
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Re: Merge Layers Script?
Wow...didn't think I would get this response....reason I asked is that I have been importing AI and SVG layers from other illustration softwares in order to assemble a single Moho layer and it gets rather slow going when you have to cut/paste elements onto one layer then go back and delete the unused layers. It struck me how easy it could be just to simple merge them, destructively of course. Wasn't really concerned about added elements such as references etc.
Thanks so much for this Wes and SimpleSam. I will give it a go.
Cheers
D.K
Thanks so much for this Wes and SimpleSam. I will give it a go.
Cheers
D.K
http://www.creativetvandmedia.com
My store on Renderosity:
https://www.renderosity.com/mod/bcs/?uid=921315
My store on Renderosity:
https://www.renderosity.com/mod/bcs/?uid=921315
Re: Merge Layers Script?
Wes...that works perfectly. Thanks so much. I put it in the menu scripts under Layer effects.
It doesn't sound like a huge time saving script but every little bit counts when you are under
the pump.
Cheers
D.K
It doesn't sound like a huge time saving script but every little bit counts when you are under
the pump.
Cheers
D.K
http://www.creativetvandmedia.com
My store on Renderosity:
https://www.renderosity.com/mod/bcs/?uid=921315
My store on Renderosity:
https://www.renderosity.com/mod/bcs/?uid=921315
- synthsin75
- Posts: 10041
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Merge Layers Script?
Glad to help, David. I'm sure the little bit of time it took me to write will save you a huge amount of time. That's time well spent, IMO.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/