ScriptSpot home

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

-

miauu

function grabview01 label


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-"
Reply to miauu
cuatcside

one more question

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.

Reply to cuatcside
Panayot Karabakalov

need spec case then

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
Reply to miauu
gazarika

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