ScriptSpot

Forum topic · General Scripting

Taking that next step - Mergeing files

By scottparris · 2013-07-28

Description

Hello

I created a tiny merge script that will merge in an object from a scene file. But I want to be able to search for multiple objects through multiple scenes.

example:

search a directory for any max scene files
search those scene files for any object with the words "sofa", "rug", "chair", etc...
and merge it into a current scene.

I need this to work inside of a texture baking script so I don't really want something with a UI or anything like "batchloader"

thanks

Comments (5)

scottparris · 2013-07-29

Awesome! It works exactly how I wanted it to.

Thank you again!

miauu · 2013-07-29

Glad to help. :)

.

miauu · 2013-07-29

Yes, only one character is missing and this ruin the script. :)
Replace this:


searchForString = ("*sofa*", "*rug*", "*chair*")

with this:


searchForString = #("*sofa*", "*rug*", "*chair*")

and try again.
I tested and it work. :)

scottparris · 2013-07-29

Thank you so much!!! This looks great but I'm getting an error and nothing as of yet will merge into the scene.

From the listener:

-- Error occurred in n loop; filename: ; position: 397; line: 14
-- Frame:
-- n: "LR_Sofa_001"
-- called in mf loop; filename: ; position: 402; line: 15
-- Frame:
-- objToMergeArr: #()
-- mf: "V:\Collections\- Collections\Living_rooms\Living_room_001.max"
-- called in anonymous codeblock; filename: ; position: 598; line: 21
-- Frame:
-- No "map" function for "*sofa*"

Ideas?

miauu · 2013-07-28

I don't have MAX to test it, but you will do it:



(
	maxFilesDir = getSavePath caption:"Select the directory" initialDir:"$scenes"
	maxFilesArr = getFiles (maxFilesDir + "\\*.max")
	searchForString = ("*sofa*", "*rug*", "*chair*")
	for mf in maxFilesArr do
	(
		objInFile = getMaxFileObjectNames mF
		objToMergeArr = #()
		for n in objInFile do
		(
			for str in searchForString where (matchpattern n pattern:str) do
			(
				append objToMergeArr n
			)
		)
		if objToMergeArr.count != 0 do
		(
			-- 	#AutoRenameDups	--	max2011+
				mergeMAXFile mF objToMergeArr /* #select  */#noRedraw #mergeDups #renameMtlDups #alwaysReparent quiet:true
		)
	)
)