ScriptSpot

Forum topic · General Scripting

Error when running script from Toolbar. Evaluates without error.

By ook222 · 2019-02-04

Description

Hi,

Fairly new to Maxscript. Made a quick export to FBX script which after some fiddling seems to work, but only when I evaluate it. If I run it from the toolbar button I made it throws an error. "Unable to convert: undefined to type: FileName"

Not sure why it would behave differently in these cases.

Here's the script:


SelectedObjects = selection as array
clearSelection()
max modify mode

actionMan.executeAction 0 "40087"  -- Edit: Hold

for obj in SelectedObjects do
(
	select obj
	obj.pos = [0,0,0]
    ObjectName = obj.name
    ExportPath = (maxFilePath + "\\" + ObjectName)
	exportFile ExportPath #noPrompt selectedOnly:true using:FBXEXP
)

actionMan.executeAction 0 "40088"  -- Edit: Fetch

Here's the error: "Unable to convert: undefined to type: FileName"


-- Error occurred in anonymous codeblock; filename: C:\Users\my.name\AppData\Local\Autodesk\3dsMax\2019 - 64bit\ENU\usermacros\DragAndDrop-Macro1.mcr; position: 287; line: 15
-- MAXScript MacroScript Error Exception:
-- Unable to convert: undefined to type: FileName
-- MAXScript callstack:
--	thread data: threadID:11268
--	------------------------------------------------------
--	[stack level: 0]
--	In obj loop; filename: C:\Users\my.name\AppData\Local\Autodesk\3dsMax\2019 - 64bit\ENU\usermacros\DragAndDrop-Macro1.mcr; position: 265; line: 13
--	member of: codeblock macroScript: DragAndDrop_Macro1
--		Parameters:
--			obj: $PolyMesh:Cliff_02 @ [0.000000,0.000000,0.000000]
--		Locals:
--			obj: $PolyMesh:Cliff_02 @ [0.000000,0.000000,0.000000]
--			fbx_file: undefined
--		Externals:
--			owner: <CodeBlock:DragAndDrop_Macro1>
--			DragAndDrop_Macro1: <CodeBlock:DragAndDrop_Macro1>
--	------------------------------------------------------
--	[stack level: 1]
--	called from codeblock macroScript: DragAndDrop_Macro1; filename: C:\Users\my.name\AppData\Local\Autodesk\3dsMax\2019 - 64bit\ENU\usermacros\DragAndDrop-Macro1.mcr; position: 288; line: 15
--		Locals:
--			theObjs: #($PolyMesh:Cliff_02 @ [0.000000,0.000000,0.000000], $PolyMesh:Cliff_003 @ [-1337.410889,0.000000,0.000000], $PolyMesh:Cliff_004 @ [1358.051270,0.000000,0.000000], $PolyMesh:Cliff_01 @ [-2605.799805,0.000000,0.000000])
--		Externals:
--	------------------------------------------------------
--	[stack level: 2]
--	called from top-level
Comments (2)

Filename

wobi · 2019-03-07

Try this:


if maxFilePath != "" and selection.count > 0 then
(
	local selected_objs = selection as array
	
	-- set redraw off so we dont need to see the objects jumping around
	with redraw off
	(
		-- loop through selected objects
		for obj in selected_objs do
		(
			-- save object position
			local original_pos = obj.pos
			
			-- set object to origin
			obj.pos = [0, 0, 0]

			-- select obj for export
			select obj
			
			-- build the export filename
			local export_path = maxFilePath + "\\" + obj.name + ".fbx"
			
			-- export
			exportFile export_path #noPrompt selectedOnly:true using:FBXEXP
			
			-- set object back to original position
			obj.pos = original_pos
		)
	)
)
else
(
	print "The scene has to be saved to have a filepath and objects need to be selected!"
)

.

miauu · 2019-02-16

This code is added as macroscript?