Batchrender multiple groups

Batchrender multiple groups

Primabad
Participant Participant
1,127 Views
5 Replies
Message 1 of 6

Batchrender multiple groups

Primabad
Participant
Participant

I have a file with a lot of different groups in it. Basically I want to individually render out each group. To do this manually would cost a lot of time so I would love to have a script that would hide all groups and then one by one unhide them, render the view and again hide the group. I hope this makes sense. 

To do this I found a script online that more or less does exactly this. The problem is, is that it doesn't work with groups but with individual objects. It doesn't care about the groups and just hides and unhides every individual object in each group and renders them. 

I tried to change the script to select all the group heads and hide/unhide but this does nothing to the children inside the group. How can I have Max select the group including it's children so that it hides/unhides the entire group?

 

This is the original script: 

 

(
	--select all objects you want to render separately and execute the script
 
	local	outputPath = "C:\Users\YourName\Desktop" --change this path to where your renderings should be placed
	local fileExt = ".png" --change this to any image file type
 
	renderSceneDialog.close() --close render scene dialog to make changes have an effect
 
	for s in selection do s.isHidden = true --hide all selected objects
 
	for s in selection do --loop through selection
	(
		s.isHidden = false --unhide object
		rendSaveFile = true --make sure image is saved to disk
		rendOutputFileName = outputPath + "\\" + s.name + fileExt --create filename
		max quick render --render using the settings from the render scene dialog
		s.isHidden = true --hide object again
	)--end for
)

 Any help would be greatly appreciated. 

0 Likes
Accepted solutions (1)
1,128 Views
5 Replies
Replies (5)
Message 2 of 6

miauuuu
Collaborator
Collaborator

Those functions was published by denisT  a long time ago:

function FindTopMostGroupHead obj = if isgroupMember obj do
		(
			while obj != undefined and (not isGroupHead obj or isGroupMember obj) do
				(obj = obj.parent)
			obj
		)
--	get all geometry members of a group
	fn GetGeometryGroupMembers node = if isgrouphead node do
	(
		for node in (join #() node) where iskindof node geometryclass and canconvertto node editable_mesh collect node 
	)
	
	fn isGroupHeadMember head node act:off = 
	(
		while isvalidnode node and isgroupmember node and not (act = (node.parent == head)) do node = node.parent
		act
	)
	fn getAllGroupMembers head = if isgrouphead head do
	(
		for node in (join #() head) where isGroupHeadMember head node collect node
	)
	select (getAllGroupMembers $g2)

 

In the last row instead of selecting the group members just unhide them.

 

https://miauu-maxscript.com/
0 Likes
Message 3 of 6

Primabad
Participant
Participant

So far this doesn't seem to work. I get an error that says isGroupHead requires a node. I haven't been able to solve this.

 

Does anyone know how to fix this or has another idea to select an entire group including the groupmembers?

0 Likes
Message 4 of 6

miauuuu
Collaborator
Collaborator

 

(

	--select all objects you want to render separately and execute the script
 
	local outputPath = "D:\\" --change this path to where your renderings should be placed
	local fileExt = ".png" --change this to any image file type
 
	renderSceneDialog.close() --close render scene dialog to make changes have an effect
 
	function FindTopMostGroupHead obj = 
	(		
		if isGroupMember obj then
		(
			while obj != undefined and (not isGroupHead obj or isGroupMember obj) do
				(obj = obj.parent)			
		)
		else
		(
			obj
		)
		obj
	)
	
	function IsGroupHeadMember head node act:off = 
	(
		while isvalidnode node and isgroupmember node and not (act = (node.parent == head)) do node = node.parent
		act
	)
	function GetAllGroupMembers head = if isgrouphead head do
	(
		for node in (join #() head) where IsGroupHeadMember head node collect node
	)

	selObjsArr = selection as array
	if selObjsArr.count != 0 then
	(
		grpsArr = #()
		for o in selObjsArr where isGroupHead o do
		(
			appendIfUnique grpsArr (FindTopMostGroupHead o)
		)
		
		if grpsArr.count != 0 then
		(
			hide selObjsArr
			for grpHead in grpsArr do
			(
				allGrpMemebrsArr = GetAllGroupMembers grpHead
				unhide allGrpMemebrsArr			
				rendSaveFile = true
				rendOutputFileName = outputPath + "\\" + grpHead.name + fileExt
				max quick render 
				hide allGrpMemebrsArr
			)
			unhide selObjsArr
		)
		else
			messagebox "No Groups found." title:""	
	)
	else
		messagebox "Please, select some objects." title:"Empty Selection."

)

Or:

(

	--select all objects you want to render separately and execute the script
 
	local outputPath = "D:\\" --change this path to where your renderings should be placed
	local fileExt = ".png" --change this to any image file type
 
	renderSceneDialog.close() --close render scene dialog to make changes have an effect
 	
	function IsGroupHeadMember head node act:off = 
	(
		while isvalidnode node and isgroupmember node and not (act = (node.parent == head)) do node = node.parent
		act
	)
	function GetAllGroupMembers head = if isgrouphead head do
	(
		for node in (join #() head) where IsGroupHeadMember head node collect node
	)

	selObjsArr = selection as array
	if selObjsArr.count != 0 then
	(
		grpsArr = #()
		for o in selObjsArr where isGroupHead o and o.parent == undefined do
		(
			appendIfUnique grpsArr o
		)
		if grpsArr.count != 0 then
		(
			hide selObjsArr
			for grpHead in grpsArr do
			(
				allGrpMemebrsArr = GetAllGroupMembers grpHead
				unhide allGrpMemebrsArr			
				rendSaveFile = true
				rendOutputFileName = outputPath + "\\" + grpHead.name + fileExt
				max quick render 
				hide allGrpMemebrsArr
			)
			unhide selObjsArr
		)
		else
			messagebox "No Groups found." title:""	
	)
	else
		messagebox "Please, select some objects." title:"Empty Selection."

)

 

https://miauu-maxscript.com/
0 Likes
Message 5 of 6

miauuuu
Collaborator
Collaborator
Accepted solution

Or this:

(

	--select all objects you want to render separately and execute the script
 
	local outputPath = "D:\\" --change this path to where your renderings should be placed
	local fileExt = ".png" --change this to any image file type
 
	renderSceneDialog.close() --close render scene dialog to make changes have an effect
 	
	function IsGroupHeadMember head node act:off = 
	(
		while isvalidnode node and isgroupmember node and not (act = (node.parent == head)) do node = node.parent
		act
	)
	function GetAllGroupMembers head = if isgrouphead head do
	(
		for node in (join #() head) where IsGroupHeadMember head node collect node
	)

	selObjsArr = selection as array
	if selObjsArr.count != 0 then
	(
		grpsArr = #()
		for o in selObjsArr where isGroupHead o and o.parent == undefined do
		(
			appendIfUnique grpsArr o
		)
		if grpsArr.count != 0 then
		(
			hide selObjsArr
			for grpHead in grpsArr do
			(
				allGrpMemebrsArr = GetAllGroupMembers grpHead
				unhide allGrpMemebrsArr			
				rendSaveFile = true
				rendOutputFileName = outputPath + "\\" + grpHead.name + fileExt
				max quick render 
				hide allGrpMemebrsArr
			)
			unhide selObjsArr
		)
		else
			messagebox "No Groups found." title:""	
	)
	else
		messagebox "Please, select some objects." title:"Empty Selection."

)
https://miauu-maxscript.com/
0 Likes
Message 6 of 6

Primabad
Participant
Participant

Thanks for these scripts. I used the last one you posted and it worked like a charm. Greatly appreciated. 

0 Likes