Page 1 of 2

Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 5:50 pm
by yearn2animate
Hi all,

I have some effect frame by frame images I've brought into ASP11. I am wondering if there is a script available that will place your switch layers one after the other at certain time increments. The desired effect would lay all the files in order one by one on the timeline and I could tweak it once its on the timeline. Since it is an environmental effect, I have quite a few frames drawn and would love a way to speed up the process before adjusting the final timing.


Is there a script that does this available? If not, is there someone who can help me put it together and possibly break down the steps on how it works? I would love to get into the scripting, and can modify code sometimes to my needs, but I am very much a novice who would like to know more. Thanks for looking, hope there is a easier solution than laying each layer one by one!

Kris

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 6:03 pm
by Greenlaw
I'm guessing you don't want to import as an image sequence because you need to re-time your frames. But go ahead and import the sequence as an Image Sequence layer and then...

1. ...right-click on the Image Sequence layer and select Convert To Switch Layer...

Image

2. The result...

Image

Hope this helps.

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 6:04 pm
by slowtiger
Scripts > Images > Import Image Sequence does exactly that.

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 6:08 pm
by Greenlaw
Note that you'll need to keyframe every frame to switch. This isn't too awful to do if you use shortcuts or the Switch Selection window, and if the sequence isn't too long.

Depending on how long the sequence is and how often will be re-editing it, you might consider making this into a Smart Bone action so you can flip through frames non-linearly using a Bone Dial.

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 6:31 pm
by hayasidist
I think what's wanted is the auto key-framing which, by pure coincidence I did a while back. The following is designed to run inside my test harness, so will need to be modified, but as the OP said they'd like to do that:

Code: Select all

function HS_SequenceStills:Run(moho, view)

	HS_Test_harness:tracePrint (thisUUT, self:Name(), self:Version())
	

	moho.document:PrepUndo(moho.layer)
	moho.document:SetDirty()

	local step = 2
	local layer = moho.layer
	local d, i, j, k, m, n, p, s, v, w

	local sw_layer = moho:LayerAsSwitch(layer)
	if not sw_layer then
		HS_Test_harness:tracePrint (thisUUT, layer:Name(), "not a switch layer")
		return
	end

	local ct = sw_layer:CountLayers()
	local frame = moho.frame

	for i = 0, ct-1 do
--		layer = sw_layer:Layer(i)
		sw_layer:SetValue(frame, sw_layer:Layer(i):Name())
		frame = frame + step
	end
	HS_Test_harness:tracePrint (thisUUT, "done", ct, "layers")


end
You'll need to take out the "test harness" calls and put this function into an "empty" script. This: http://mohoscripting.com/new_script.php will help you set up an "empty" script -- to get strated, you'll need a button/menu with nothing else.

When / if you get stuck, just shout!

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 7:17 pm
by yearn2animate
Thanks for the quick replies all!

Still learning the ins and outs of the software, so thanks for the heads up on Image sequencer. The sequence I have is just steam rising from a coffee cup, and it was done on ones so re-timing isn't really necessary... (but we will see.)

Hayasidist, thanks for sharing your code. I am pretty good with teaching myself most things, but programming isn't my strongest suit. I will see what I can do your script and reach out if I find it too perplexing. Thanks again!


This community is great, I appreciate all the help.


Kris

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 7:22 pm
by SimplSam
This came up a little while ago (as discussed here: Distribute layers to frames)

If you have your Content Layers in a Switch you can use my Switch 2 FBF script: ss_switch2fbf

To Use: Ensure the target layers are grouped into a Switch layer as uniquely named sub-layers. Select the Switch layer, and run the tool.

You can optionally set:
  • FBF Interval: - The Frame by Frame interval. (default: 1)
  • Start with: - The translation sort order: Top Layer for Top to Bottom (top => 1st frame), Bottom Layer for Bottom to Top (bot => 1st frame). (default: Top Layer)
I think it essentially does the same as hayasidist's scriptlet, but is a fleshed out tool.

Image

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 7:33 pm
by Greenlaw
slowtiger wrote: Sun Jul 04, 2021 6:04 pm Scripts > Images > Import Image Sequence does exactly that.
Interesting...this script doesn't exist for Moho 12.5 or 13.5.1, not by default anyway.

Ok, I just checked, and it needs to be added to the Scripts menu. The script is called js_image_sequence.lua and it's located in the Custom Content folder under Extra Files/Optional Scripts/Menu/Image.

From what I recall, it's fussy about using a specific naming format, which is why I don't use it. The Convert To Switch layer accepts most common file naming conventions.

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 7:34 pm
by Greenlaw
Oh, that's pretty cool simplSam. Will check it out.

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 7:52 pm
by Greenlaw
Greenlaw wrote: Sun Jul 04, 2021 7:33 pm From what I recall, it's fussy about using a specific naming format, which is why I don't use it. The Convert To Switch layer accepts most common file naming conventions.
I looked at the script and according comments in the header, it seems that some of the issues I ran into in the past may have been addressed...

LIMITATIONS:
-must have some valid extension
-must have valid numbering
-don't use numbers in names in the last 10 chars...
DONE:
-support all padding
-support extensions other than 4 char (ex : .ai )
-ImportEPS(path)
TODO:
-visibility off after last frame
-menu to choose frame step etc...
-insert at current time
-any request?


I haven't tried it, so just an FYI for anybody who wants to install it.

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 8:07 pm
by yearn2animate
SimplSam, This is what I pictured in my head. Thanks for sharing, will be using this in the future.

Import Image Sequence worked well enough, though. Had Sam not shared it would of been my need-it-now solution. I look forward to looking over both Sam and Hayasidist's codes to start my scripting journey...


Kris

Re: Script for automating Switch layers consecutively?

Posted: Sun Jul 04, 2021 11:34 pm
by synthsin75
Greenlaw wrote: Sun Jul 04, 2021 7:33 pm Interesting...this script doesn't exist for Moho 12.5 or 13.5.1, not by default anyway.

Ok, I just checked, and it needs to be added to the Scripts menu. The script is called js_image_sequence.lua and it's located in the Custom Content folder under Extra Files/Optional Scripts/Menu/Image.
Since v12 we now have image sequence under the standard File>Import options.

Re: Script for automating Switch layers consecutively?

Posted: Mon Jul 05, 2021 2:34 am
by SimplSam
Just realised that 13.5 does not handle Imported GIF Image Sequences correctly - and the resultant layer only appears to have a single frame.

Whereas importing the same sequence of GIF's to Moho 12, or a sequence of PNG's to Moho 12/13.5 animate as expected.

Reported to LM Support.

Re: Script for automating Switch layers consecutively?

Posted: Mon Jul 05, 2021 6:12 pm
by Greenlaw
synthsin75 wrote: Sun Jul 04, 2021 11:34 pm Since v12 we now have image sequence under the standard File>Import options.
Yes, I know but it imports it as a single Sequence Layer, not individual layers for every frame inside a Switch Layer, which is what I thought the OP wanted. I was just pointing out that an Image Sequence layer can be converted to separate image layers using the Convert To Switch Layer command. But it sounds like all he needed was the standard image Sequence layer after all.

slowtiger suggested using the legacy (ASP 11) script that imports separate image layers directly, which is no longer included in the (Moho 12.5/13.5.1) Script menu by default. But that's probably because with the Convert To Switch layer command, it's really not necessary anymore.

Re: Script for automating Switch layers consecutively?

Posted: Mon Jul 05, 2021 8:49 pm
by yearn2animate
In this case, the regular image sequencer would suffice, but SimplSam's solution was what I was looking for in a scripting option.