LK_Render

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Lukas
Posts: 1319
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

LK_Render

Post by Lukas »

(Edited topic subject and first post to solution)

Download link: Image


Original post:

Does anyone start their command line renders through a lua script from inside Moho?

I've made a script so everything is always rendered the same and at the correct location etc. and when I paste the created command in MacOS Terminal or Windows Command Prompt it renders as a background process just fine. So the command seems ok.

But if I let the lua script run it with os.execute() on MacOS it will keep Moho occupied until the render is done, so you can't work on another file during the rendering. And on Windows it won't render at all. But if I copy paste the exact same command in Command Prompt it renders fine. (Both on MacOS and Windows manually pasting the command renders in the background, even if Moho is already open)

Is there a way to start a command line render as a background process trough os.execute() in a Lua mohoscript?

Code: Select all

[...]
local mohopath
local render = moho.document:Path()
if FO_Utilities:getOS(moho) == "win" then
	-- ****************
	-- *** Windows: ***
	-- ****************
	mohopath = "C:/Program Files/Moho/Moho.exe"
	mohopath = "\""..string.gsub(mohopath, "/", "\\").."\""
	render = "\""..string.gsub(render, "/", "\\").."\""
	self.output = "\""..string.gsub(self.output, "/", "\\").."\""
else
	-- **************
	-- *** MacOS: ***
	-- **************
	mohopath = "/Applications/Moho.app/Contents/MacOS/Moho"
	mohopath = string.gsub(mohopath, " ", "\\ ")
	render = string.gsub(render, " ", "\\ ")
	self.output = string.gsub(self.output, " ", "\\ ")
end
[...]
local command = mohopath.." -r "..render.." -o "..self.output.." -f "..self.format.." -start "..self.start.." -end "..self.stop.." -halfsize "..halfsize.." -multithread "..multiThread
os.execute(command)
Last edited by Lukas on Fri Sep 15, 2023 12:52 pm, edited 1 time in total.
User avatar
hayasidist
Posts: 3700
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Start background commandline render from Lua script?

Post by hayasidist »

This from stackoverflow:

https://stackoverflow.com/questions/103 ... ute-return

os.execute('command&')

Not tried it, so can't vouch for it working...
User avatar
Lukas
Posts: 1319
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Start background commandline render from Lua script?

Post by Lukas »

hayasidist wrote: Thu Sep 16, 2021 9:07 pm This from stackoverflow:

https://stackoverflow.com/questions/103 ... ute-return

os.execute('command&')

Not tried it, so can't vouch for it working...
os.execute('command&') didn't work, but a comment at the same page suggested io.popen("command") and that runs it in the background on MacOS! Will test Windows tomorrow. Thank you, this is really going to help in production!
User avatar
SimplSam
Posts: 1174
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Start background commandline render from Lua script?

Post by SimplSam »

I don't quite use that workflow - but do use a Stream Deck keyboard to drive batch renders, which is huge time/lifesaver when repeatedly rendering content for given projects.

Image

Another approach is to use a simple queuing system - where the to-be-rendered Moho project details would be saved to an onfile render queue, and then those queue items would get picked up by a batch render processor - which could also be running on another workstation/server.
Moho 14.2 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
Lukas
Posts: 1319
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Start background commandline render from Lua script?

Post by Lukas »

SimplSam wrote: Fri Sep 17, 2021 3:13 am I don't quite use that workflow - but do use a Stream Deck keyboard to drive batch renders, which is huge time/lifesaver when repeatedly rendering content for given projects.

Image
How exactly do you use it with Moho? It looks nice.
SimplSam wrote: Fri Sep 17, 2021 3:13 amAnother approach is to use a simple queuing system - where the to-be-rendered Moho project details would be saved to an onfile render queue, and then those queue items would get picked up by a batch render processor - which could also be running on another workstation/server.
Yeah, we do use a custom render queue system at the studio. Recently there's more remote working because of covid and freelancers that work from home because they live far away, and they are now also able to sent their shots to the queue which is great. The queue checks if files are synced before it renders and even changes image paths etc if necessary.

But, I'm actually building this local render button because I find it also very useful to just be able to render exactly what I need right now without relying on a server. Especially close to a deadline. So our moho-render-script now asks if you want to render locally or sent it to the queue.

We recently switched from .png sequences to .jpg sequences because its faster and smaller (unless we need the alpha channel of course), but I'm noticing quite ugly jpg artifacts... So I'm considering switching back to png. What format do you guys prefer for image sequences?
User avatar
Lukas
Posts: 1319
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Start background commandline render from Lua script?

Post by Lukas »

Lukas wrote: Thu Sep 16, 2021 10:29 pmos.execute('command&') didn't work, but a comment at the same page suggested io.popen("command") and that runs it in the background on MacOS! Will test Windows tomorrow.
Hmm, both os.execute(command.."&") and io.popen(command) don't seem to work on Windows. Even though copy pasting that exact command to the Command Prompt renders it fine... 😞
User avatar
hayasidist
Posts: 3700
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Start background commandline render from Lua script?

Post by hayasidist »

I have no idea if you can get powershell to run by using os.execute, but looking at the windows online documentation I found that powershell has an invoke command that is designed to be synchronous: https://docs.microsoft.com/en-us/powers ... nt-actions

If that helps in any way ...

[edit: the initial post above was wrong: Invoke is sync; start is async. updated]
Last edited by hayasidist on Sat Sep 18, 2021 10:27 am, edited 1 time in total.
User avatar
SimplSam
Posts: 1174
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Start background commandline render from Lua script?

Post by SimplSam »

After about a million tests the following appears to work (with a tiny blip of a DOS screen popup).

Code: Select all

os.execute(' "start "any title" "C:\\Program Files\\Lost Marble\\Moho 13.5\\Moho.exe" -r "w:\\zombies.moho" -f PNG -o "R:\\\\_out\\\\zombies\\\\" " ')
- I have spaced out some of the quotes so you can see them more clearly.
- "any title" can be anything - even empty "", but must be there.

p.s. AE's LUA Console was an absolute life-saver for this (i.e. Running/Rerunning LUA commands from within the Moho GUI): https://mohoscripts.com/script/ae_lua_console
Moho 14.2 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
Lukas
Posts: 1319
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Start background commandline render from Lua script?

Post by Lukas »

SimplSam wrote: Fri Sep 17, 2021 2:23 pm After about a million tests the following appears to work (with a tiny blip of a DOS screen popup).

Code: Select all

os.execute(' "start "any title" "C:\\Program Files\\Lost Marble\\Moho 13.5\\Moho.exe" -r "w:\\zombies.moho" -f PNG -o "R:\\\\_out\\\\zombies\\\\" " ')
- I have spaced out some of the quotes so you can see them more clearly.
- "any title" can be anything - even empty "", but must be there.

p.s. AE's LUA Console was an absolute life-saver for this (i.e. Running/Rerunning LUA commands from within the Moho GUI): https://mohoscripts.com/script/ae_lua_console
AH! It works! 🥳 Thanks so much. I need to clean up the script a bit, but it's rendering on both MacOS and Windows now. I'll also try to rip out our studio specific code and upload the script if anyone's interested.
User avatar
hayasidist
Posts: 3700
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Start background commandline render from Lua script?

Post by hayasidist »

Lukas wrote: Fri Sep 17, 2021 3:41 pm ... I'll also try to rip out our studio specific code and upload the script if anyone's interested.
yes please -- just the ability to get something to run asynchronously could be very valuable
User avatar
hayasidist
Posts: 3700
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Start background commandline render from Lua script?

Post by hayasidist »

SimplSam wrote: Fri Sep 17, 2021 2:23 pm After about a million tests the following appears to work (with a tiny blip of a DOS screen popup).

Code: Select all

os.execute(' "start "any title" "C:\\Program Files\\Lost Marble\\Moho 13.5\\Moho.exe" -r "w:\\zombies.moho" -f PNG -o "R:\\\\_out\\\\zombies\\\\" " ')
...
there's a "/b" switch that might stop the popup: https://docs.microsoft.com/en-us/window ... ands/start
Stan
Posts: 202
Joined: Sun Apr 19, 2009 3:22 pm

Re: Start background commandline render from Lua script?

Post by Stan »

Lukas wrote: Fri Sep 17, 2021 3:41 pm if anyone's interested.
You'll be surprised how many people find it useful! :D
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
SimplSam
Posts: 1174
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Start background commandline render from Lua script?

Post by SimplSam »

hayasidist wrote: Fri Sep 17, 2021 3:57 pm there's a "/b" switch that might stop the popup: https://docs.microsoft.com/en-us/window ... ands/start
Unfortunately not. Apparently on Windows os.execute and io.popen encapsulate the supplied command string with cmd /c at the C program level, so I think there is no getting away from the popup window. Just need to try and make it as short as possible.
Moho 14.2 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
hayasidist
Posts: 3700
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Start background commandline render from Lua script?

Post by hayasidist »

SimplSam wrote: Sat Sep 18, 2021 4:57 am Unfortunately not. Apparently on Windows os.execute and io.popen encapsulate the supplied command string with cmd /c at the C program level, so I think there is no getting away from the popup window. Just need to try and make it as short as possible.
ah well! thanks for looking and for the research.
User avatar
SimplSam
Posts: 1174
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Start background commandline render from Lua script?

Post by SimplSam »

Lukas wrote: Fri Sep 17, 2021 8:06 am
SimplSam wrote: Fri Sep 17, 2021 3:13 am ... but do use a Stream Deck keyboard to drive batch renders ...
How exactly do you use it with Moho? It looks nice.
I have multiple (and expanding) uses:

1. Launching/Switching Windows apps (via taskbar shortcuts). Pressing the SD Key either launches the app or switches to it (same as clicking the taskbar link)
2. Send Keys (simple): Send a key combo - like [Shift left-arrow] (goto frame 0) -or- Simply replace a mouse / keyboard click -or- Send any of the wacky key combos to show/hide panels and run Buttons/Tools etc.
3. Send Keys (sequence - simple use): like [Ctrl-C .. Ctrl-V] to duplicate with a single key press. Or [tool button shortcut .. Enter] to run a popup Tool with default/current settings accepted
4. Send Keys (sequence - complex use): I use a lot when developing scripts to save the script then reload & optionally run in Moho. (see Multi-Action Sequence below). Or perform a Moho PNG render, Comp in Resolve and then View the output with VLC
5. Send Keys (super macro): Use macro script to drive any sequence of keyboard/mouse actions. Dynamically Read/Write variables from/to files. Also lets you Repeat key/sequence sends whilst SD key held or latched until SD key pressed again or for a defined number of repeats.
6. Start any program executable or Launch URLs in browser - like Lost Marble !!
7. Toggle keys (send different keys for state 1 and 2) - with associated icons. i.e. Mute / Unmute system audio. Or toggle/send seperate key sequences.
8. You can have mini-status displays. Ancillary things like Clock/Time. CPU usage. Or custom.
9. It also has the ability to move mouse cursor to specific locations and press/send clicks etc. You could even draw & create shapes with this. (Window & target locations need to be predictable for this to work well)

I now have 2 devices. A 15 button and 32 button version - used in combination with profile and folder switching.

Some favourite features:
- Custom button/status icons + text for each button - which can be dependent on file content, app or hardware status. + tactile feedback (real buttons)
- Can automatically detect the current focussed Windows app and switch to a profile specific to that app - so you get the keys relevant to that app
- Really easy to use / customize
- Using folders - you can dedicate a button setup to a particular project
- When using multiple devices, you can use one SD to switch profiles on another
- Lots of plugins for integration with third party apps and tools (particularly for audio/video, streaming/streamers, and home/office automation)
- Super macro is super powerful. I have yet to really exploit it.
- Programmable via SDK. With lots of dev community activity & support

There are also mobile app versions if you want to try without the hardware - Apple looks OK (4.8 *), but Android has mixed reviews mainly due to operational reliability (2.4 *). Used to be be free - but now $3/mo (30 day free trial)

Multi-action sequence:
Image
Switch to VisualStudioCode (make sure its the active app). Pause. Save. Pause. Switch to Moho. Pause. Reload scripts. ... in some sequences I also then run the updated tool script
Moho 14.2 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
Post Reply