ScriptSpot

Forum topic · General Scripting

First attempt to automate grab vieport - create still image with all the cameras in the scene

By cuatcside · 2011-10-11

Description

This is my first attempt to write a script that goes through all the cameras in the scene (free and target) and do a grab viewport-create still image.But I am getting errors. I would appreciate any help on this why I am getting errors and what I am doing wrong.
Thanks.

function grabview01 label folder:"d:/" =
(
for c in cameras do
local fname=folder+label+c.name
viewport.setcamera c
img=gw.getViewportDib()
img.filename=fname+".jpg"
save img
)
grabview01 "cam-"

Comments (6)

cuatcside · 2011-10-11

-

function grabview01 label

miauu · 2011-10-11


function grabview01 label folder:"d:/" =
(
        -- select only the cameras(not the target and cameras)
	local allCameras= (for c in cameras where (isKindOf c camera) collect c)
	for c in allCameras do
	(
		local fname=folder+label+c.name
		viewport.setcamera c
		forceCompleteRedraw()
		img=gw.getViewportDib()
		img.filename=fname+".jpg"
		save img
	)
)
grabview01 "cam-"

one more question

cuatcside · 2011-10-11

Oh great. I really appreciate your help.
Now since my cameras in the scene all have different viewport background images only the first background image shows up in all the screen grabs. Is there anyway that can be updated as well?
Again Thanks for your help.

need spec case then

Anubis · 2011-10-11

You should handle somehow this "first" camera, to can process it with different settings (with bg-image in this case), so if you 'separate' it by name and for example it was named "MainCamera" then the function w'd become something like...

( -- fn start
	local allCameras = ...
	if isValidNode $MainCamera do (
		deleteItem allCameras (findItem allCameras $MainCamera)
	)
	
	local oldBGImg = backgroundImageFileName
	free backgroundImageFileName

	for c in allCameras do
	(
		local fname = ...
		...
		save img; free img
	)

	backgroundImageFileName = oldBGImg
	if isValidNode $MainCamera do
	(
		local fname = ...
		...
		save img; free img
	)
) -- fn end

Thank you!

woven · 2012-02-01

Just what I needed! :)

gazarika · 2016-03-14

Thanks that was exactly what I need but could you plz add a delay of 3 seconds between each camera save so it can complete the redraw and finish its anti aliasing