Script save in batch as jpg file

Script save in batch as jpg file

laura.soen
Contributor Contributor
1,140 Views
6 Replies
Message 1 of 7

Script save in batch as jpg file

laura.soen
Contributor
Contributor

Hello,

 

I have a scene with many objects (500+) all in a certain viewpoint.
I want to select all objects in the view they are and save them out individually as separate JPEG files.
It will take too long to go to Render>Save Selected as JPEG file for all of them. Does anyone have a script to save all my objects in separate JPEG files? 

Thank you!

0 Likes
Accepted solutions (1)
1,141 Views
6 Replies
Replies (6)
Message 2 of 7

denisT.MaxDoctor
Advisor
Advisor
fn renderViewNodes nodes:selection = 
(
	local render_path = getdir #temp + @"/scene_render/"
	makedir render_path all:on  
	
	sel_nodes = nodes as array
	vis_nodes = for node in objects where not node.ishidden collect node
	hide objects
	images = for node in sel_nodes collect
	(
		unhide node
		select node
		max tool zoomextents 

		filename = node.name + ".jpg"
		filepath = render_path + filename
		render outputfile:filepath vfb:off
		
		hide node
		
		filepath
	)
	
	unhide sel_nodes
	select sel_nodes
	max tool zoomextents
		
	hide objects
	unhide vis_nodes
	
	images
)
/*
renderViewNodes()
*/

 

you must make all the rendering settings yourself before the batch, as well as specify your path in the code if you need it...

the batch render script will render all selected nodes from the current active view.

 

Feel free to ask questions

 

 

0 Likes
Message 3 of 7

laura.soen
Contributor
Contributor
Hi thanks for the script, but when I try to run it, it does not do anything. I'm new at this, am I doing something wrong?
0 Likes
Message 4 of 7

denisT.MaxDoctor
Advisor
Advisor

1. create and select objects you want to render

2. set render settings

3. make the view you want to render from active

4. run the scripts...

5. run in the listener

renderViewNodes() 

 

after that in the "...\temp\scene_render\" you should see newly created *.jpg files - one per node 

0 Likes
Message 5 of 7

laura.soen
Contributor
Contributor

Hi, I did exactly as you said but the script does not do anything. There is no "temp\scene_render" created in my directory. Is it possible there has to be changed something at the script? I tried scripts before, and they all did work so I have no idea how I can fix this problem. Just to be clear, I added an image of how my scene looks like and how I want it to be rendered as a jpg file one by one. Capture.PNGCapture2.PNG

0 Likes
Message 6 of 7

denisT.MaxDoctor
Advisor
Advisor

run :

 

getdir #temp + @"/scene_render/"

 

this is the exact path where jpg images should be stored

in my machine it's:
"C:\Users\<my_machine_name>\AppData\Local\Autodesk\3dsMax\2020 - 64bit\ENU\temp/scene_render/" 

 
0 Likes
Message 7 of 7

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

run this code and follow common sense:

try(destroydialog RenderPicsRol) catch()
rollout RenderPicsRol "Render pics with denisT" width:191
(
	fn renderViewNodes nodes:selection dir: callback: = 
	(
		if dir == unsupplied do dir = getdir #temp + @"/scene_render/"
		if not doesDirectoryExist dir do
		(
			makedir dir all:on  
		)
		dir += @"\\"
		
		sel_nodes = nodes as array
		vis_nodes = for node in objects where not node.ishidden collect node
		hide objects
		
		index = 0
		images = for node in sel_nodes while not keyboard.escpressed collect
		(
			unhide node
			select node
			max tool zoomextents 

			filename = node.name + ".jpg"
			filepath = dir + filename
			render outputfile:filepath vfb:off
			
			index += 1
			if callback != unsupplied do
			(
				callback index filepath 
			)
			
			hide node
			
			filepath
		)
		
		unhide sel_nodes
		select sel_nodes
		max tool zoomextents
			
		hide objects
		unhide vis_nodes
		
		images
	)	

	radiobuttons nodes_rb "Nodes:" labels:#("All", "Selected") default:2 columns:2 align:#left offset:[0,4] offsets:#([50,-16],[15,-16])
	button render_pics_bt "Render Pics..." width:172 align:#center offset:[0,6]
	
	
	label emp 
	
	label info_line0_lb align:#left across:3
	label info_line1_lb align:#center 
	label info_line2_lb align:#right 
	
	fn callback index file = 
	(
		info_line0_lb.text = index as string
		info_line1_lb.text = filenamefrompath file
		windows.processPostedMessages()
	)
	on render_pics_bt pressed do
	(
		if (nodes = if nodes_rb.state == 1 then objects else selection as array).count > 0 do
		(
			dir = getSavePath()
			if dir != undefined do
			(
				info_line2_lb.text = nodes.count as string
				renderViewNodes nodes:nodes dir:dir callback:callback
			)
		)
	)
	
	on RenderPicsRol open do
	(
	)
)
createdialog RenderPicsRol

 

 

0 Likes