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

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cuatcside's picture

-

-

miauu's picture

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-"
gazarika's picture

Thanks that was exactly what

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

woven's picture

Thank you!

Just what I needed! :)

cuatcside's picture

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.

Anubis's picture

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

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.