Add new layer to layercomp from script

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
JeroenKoffeman
Posts: 32
Joined: Tue Mar 24, 2015 3:04 pm

Add new layer to layercomp from script

Post by JeroenKoffeman »

Dear forum members.

I am trying to update layercomps through script. This is the only documentation I found:
http://aslua.com/index.php?show=class&name=LayerComp

Can lua script check the name of the layercomp of a layer?

The start of my code:

Code: Select all

function LayerScript(moho)

count = moho.document:CountLayerComps()
print(count)

for i = 0, count - 1 do
			local comp = moho.layerComp(i)

print(comp:Name())

end

end
Right now it doesn't find moho.layerComp. How do I acces the class LayerComp?

Thanks in advance,
Jeroen
JeroenKoffeman
Posts: 32
Joined: Tue Mar 24, 2015 3:04 pm

Re: Add new layer to layercomp from script

Post by JeroenKoffeman »

Solved it!

Code: Select all

function LayerScript(moho)



--Add layer to the same layercomp as the parent layer----------------
---------------------------------------------------------------------
layer = moho.layer

local myID = moho.document:LayerID(layer) 

local myParent = layer:Parent()

if not(myParent == nil)then


comp = moho.document:GetLayerComp(myID)
count = moho.document:CountLayerComps()


for i = 0, count - 1 do
			local comp = moho.document:GetLayerComp(i) --Search through all layercomps. If the parent layer is inside, add this layer to it.

if(comp:ContainsLayer(myParent))then			
			
if not(comp:ContainsLayer(layer))then	
print("Layer added to Layercomp: ", comp:Name())
comp:AddLayer(layer)
end
end
end
end


--END of Add layer to the same layercomp as the parent layer----------------
---------------------------------------------------------------------

end
Post Reply