Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Exporting Multiple Selected Object Groups

Exporting Multiple Selected Object Groups

john.baumchen
Participant Participant
728 Views
4 Replies
Message 1 of 5

Exporting Multiple Selected Object Groups

john.baumchen
Participant
Participant

Hello all,

I've got a Max file with many object groups with textures.  I'd like to select some or all and export them to .obj with their textures with a scale of 1.0, and maintain them as individual groups with their individual group names.  I'm not very profeicient at Max scripting and was wondering if anyone else has addressed this and would be willing to share the script for it.  I've located something that will do it from frames, but am unable to decipher the code.  I'm working in 3dsMax 2019.

 

Thanks and cheers.

0 Likes
729 Views
4 Replies
Replies (4)
Message 2 of 5

denisT.MaxDoctor
Advisor
Advisor

do you want to export each group to a separate file?

0 Likes
Message 3 of 5

john.baumchen
Participant
Participant

Yes

0 Likes
Message 4 of 5

denisT.MaxDoctor
Advisor
Advisor

 

 

/*********** SAMPLE SCENE **********/
delete objects
gc()

with redraw on
(
	t0 = for k=0 to 8 collect
	(
		t = teapot name:(uniquename #red_teapot_) radius:19 pos:[4,0,0] rotation:(eulerangles 0 0 (k*40)) wirecolor:red
	)
	gr0 = group t0 name:#red_group
	move gr0 [-50,0,0]

	t1 = for k=0 to 9 collect
	(
		t = teapot name:(uniquename #green_teapot_) radius:15 pos:[10,0,0] rotation:(eulerangles 0 0 (k*36)) wirecolor:green
	)
	gr1 = group t1 name:#green_group
	move gr1 [50,0,0]

	t2 = for k=0 to 8 collect
	(
		t = teapot name:(uniquename #orange_teapot_) radius:20 pos:[-6,0,0] rotation:(eulerangles 0 0 (k*40)) wirecolor:orange
	)
	gr2 = group t2 name:#orange_group
	move gr2 [0,50,0]
	
	t3 = for k=0 to 9 collect
	(
		t = teapot name:(uniquename #blue_teapot_) radius:13 pos:[-16,0,0] rotation:(eulerangles 0 0 (k*36)) wirecolor:blue
	)
	gr3 = group t3 name:#blue_group
	move gr3 [0,-50,0]
)

/*********************** METHODS **********************/
fn collectGroupHeads = 
(
	for obj in objects where isGroupHead obj collect obj
)
fn collectHeadGroup head = if isGroupHead head do 
(
	join #() head
)
fn exportSetup =
(
	file = objExp.getIniName()
	if doesFileExist file then
	(
		setINISetting file #Material #UseMaterial "1"
		setINISetting file #Geometry #ObjScale "1.000"
		
		true 
	)
	else false
)
fn exportHeadGroup head dir: = if isGroupHead head do
(
	if dir == unsupplied do dir = getdir #temp
	makeDir dir all:on -- just in case the path doesn't exist
		
	cursel = selection as array
	nodes = collectHeadGroup head
	select nodes
	filename = pathConfig.appendPath dir (head.name + ".OBJ")
	res = exportFile filename #noPrompt selectedOnly:on using:ObjExp
	
	if cursel.count == 0 then clearselection() else select cursel
	
	if res do filename 
)

fn exportHeadGroups dir: setup:on =
(
	if dir == unsupplied do dir = getSavePath()
	if dir != undefined do
	(
		heads = collectGroupHeads()
		exported = #()
		if heads.count > 0 do with redraw off, undo off
		(
			if setup do exportSetup()
			
			exported = for head in heads collect
			(
				expfile = exportHeadGroup head dir:dir
				if expfile != undefined then #(head, expfile) else dontcollect
			)
		)
		exported
	)
)

/************ RUN BELOW TO DO THE EXPORT ****************

res = exportHeadGroups()

********************************************************/

 

 

 

feel free to ask questions if you encounter a problem or want more details...

Message 5 of 5

john.baumchen
Participant
Participant

denisT,

Thank you for taking the time to help me with this, I'd have spent weeks first learing another language, then trying and most probably failing to accomplish the task. Just want you to know how much I appreciate your help.

 

Cheers.

0 Likes