Help with merge script...easy fix I'm sure...lost

What I want to do it type "box" or "cone", specify a directory and search through max scene files in the directory for items named "box" or "cone". Then merge those items into the current scene.

This is what I got so far, but I'm getting a --No "map" function for undefined on line 30 "append objToMergeArr n"

rollout merRoll "Merge"

(
edittext prefix_txt "Item:" fieldWidth:150 labelOnTop:false
on prefix_txt entered txt do
(
if txt != "*cone*" then
searchForString = #("*cone*")
if txt != "*box*" then
searchForString = #("*box*")

)
label lab1 " "style_sunkenedge:true width:265 height:40 pos:[0,60]
label lab2 "Search for and merge in items from max scene files" pos:[12,35]
label lab3 "Author: Scott Parris" pos:[80,65]
label lab4 "Date: 6/13/14" pos:[94,80]
button but1 "Browse" pos:[200,2]
on but1 pressed do
(
maxFilesDir = getSavePath caption:"Select the directory" initialDir:"C:/Users/3D/Desktop"
maxFilesArr = getFiles (maxFilesDir + "\\*.max")
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
)
)
)
)

AttachmentSize
merge_ui_4.ms1.19 KB

Comments

Comment viewing options

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

Thank you so much!!!

Thank you so much!!! Everything works great.

I'm new to Maxscript so I was piecing this together looking at other scripts. I didn't really understand why it wasn't working.

Thank you again.

miauu's picture

.

Glad to help. :)

miauu's picture

.

The problem is that the searchForString variable is not defiend as local for the script.

rollout merRoll "Merge"
 
(
	local searchForString = undefined
	edittext prefix_txt "Item:" fieldWidth:150 labelOnTop:false
	on prefix_txt entered txt do
	(
		if txt != "*cone*" then
		searchForString = #("*cone*")
		if txt != "*box*" then
		searchForString = #("*box*")
 
	)	
		label lab1 " "style_sunkenedge:true width:265 height:40 pos:[0,60]
		label lab2 "Search for and merge in items from max scene files" pos:[12,35]
		label lab3 "Author: Scott Parris" pos:[80,65]
		label lab4 "Date: 6/13/14" pos:[94,80]
		button but1 "Browse" pos:[200,2]
		on but1 pressed do
	(
		maxFilesDir = getSavePath caption:"Select the directory" initialDir:"C:/Users/3D/Desktop"
		maxFilesArr = getFiles (maxFilesDir + "\\*.max")
		if searchForString != undefined then
		(
			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
				)
			)
		)
		else
			messagebox "searchForString variable is undefined" title:""
	)
)
 
createdialog merRoll width:265 height:105 fgcolor:black

What is the logic behind this part of the code:

on prefix_txt entered txt do
	(
		if txt != "*cone*" then
		searchForString = #("*cone*")
		if txt != "*box*" then
		searchForString = #("*box*")
 
	)	

Even if you type CONE in the edit text field the script will load only boxes.
I think that you have to use something like this:

on prefix_txt entered txt do
	(
		if matchPattern txt pattern:"*cone*" then
			searchForString = #("*cone*")
		else
		(
			if matchPattern txt pattern:"*box*" then
				searchForString = #("*box*")
		)
	)

Comment viewing options

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