Notifications
Clear all

[Closed] Find Directory Path for animation/FBX exporter

I need the ability to save/load animations on to a selected rig from a sub-directory of an open file and export an FBX to a separate directory based on the file open file.

I need help identifing the directory paths or these operations. Also, any existing scripts that do something similar would be helpful as well.
Thanks
B

19 Replies

maxfilename and maxfilpath cna be sued to get local directories.

here’s a version of what I use

(
	fbxFileName= substitutestring maxfilename ".max" ".fbx"
	subFolder= maxfilepath + "/subfolderName/"
	fbxFilePath= subFolder+fbxFileName
	
	assets= #(<nodes to export...>)
	
	
	fn exportFBX assets fbxFilePath=(
		select assets
		exportFile filePath #noPrompt selectedOnly:True  using:FBXEXP
	)
)

you might also want to look at the command [FBXExporterSetParam]( http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help//index.html?query=FBXExporterSetParam)  to set each of your FBX preferences

When you say import animations, are speaking of .xaf files? If so then look at
LoadSaveAnimation


	
	filePath= maxfilePath+"/animtionSubFolder/animationName.xaf"
	nodeList= #( <nodes to animate...> )

	fn loadXaf filePath = 
	(
		nodes= nodeList
		LoadSaveAnimation.loadAnimation filePath nodes relative:false
		this.setFrameRange 0
	),

Thanks you for you’re help. I’m trying the FBX exporter, and nothing is being exported. The Listener says “exportFBX()” after evaluating the script. Please let me know if I am doing something wrong. Below is the code that I am using to test the script. I would like to export an FBX of the root node to the “Anims” folder. Also, instead of a list, I plan to use something like “select $root…*” to allow for rig variations.

(
	fbxFileName= substitutestring maxfilename ".max" ".fbx"
	subFolder= maxfilepath + "Anims"
	fbxFilePath= subFolder+fbxFileName
	
	assets= #(Root)
	
	fn exportFBX assets fbxFilePath=(
		select assets
		exportFile filePath #noPrompt selectedOnly:True  using:FBXEXP
	)
)

Yes, when i was saying load/save animations I was referring to .xaf files. I havent tried the code yet, but will be shortly.

Thanks again for the help

the problem is here


assets= #(Root)

assets needs to be an array of objects.
all scene objects need to be prefixed with a “$” in mxs.

if you have an object called “Root” in your scene:


assets= #($Root)

if you have a bunch of characters to export that use a naming conventions
like $john_root , $paul_root, $george_root, $ringo_root etc; then use “*” wildcard:


assets= #($*_root)

this is also the case for the nodeList variable in the xaf script.

doh, thanks, sorry for over looking $ in the test script.

I’s simplified my scene to test the exporter. I have a single box in the scene named “root” and want to export it to a sub-folder named “test”.

Below is the script that I am using, it appears to find the location, but does not export a file. In the Listener is says “exportFBX()”, but does not export a file.

Any thoughts?

(
	fbxFileName= substitutestring maxfilename ".max" ".fbx"
	subFolder= maxfilepath + "test"
	fbxFilePath= subFolder+fbxFileName
	
	assets= #($root)
	
	fn exportFBX assets fbxFilePath=(
		select assets
		exportFile filePath #noPrompt selectedOnly:True  using:FBXEXP
	)
)

ah, I should have read more carefully.

the script I provided is a function definition, It wont do anything until you actually call the function.

when the listener says “exportFBX()”
It is telling you that it 3DS Max now has a function defined in RAM called via “exportFBX()”

to actually call the function, type “exportFBX “( plus its arguments ) in either the listener or the editor and evaluate.

here is commented code.


(

--define the variables 
	fbxFileName= substitutestring maxfilename ".max" ".fbx"
	subFolder= maxfilepath + "test"
	fbxFilePath= subFolder+fbxFileName
	assets= #($root)
	
--define the function
	fn exportFBX assets fbxFilePath=(
		select assets
		exportFile filePath #noPrompt selectedOnly:True  using:FBXEXP
	)


--actually execute the function, passing the arguments to it
	exportFBX assets fbxFilePath

)

You seem rather new to MXS, I suggest spending some time watching Max Script 101

particularly Vdeio 2.3: Function Definitions

Awesome! Thank you so much for you’re help. I made some minor tweaks, but this approach works so much better then my previous attempts.

And Yes, I am very new to scripting, and an Animator but need to a little working in Maxscript from time to time. I checked the link, the series looks great. If you have any other ref for someone starting out, I’d love to review it.

Thanks again!

(

--define the variables 
	fbxFileName= substitutestring maxfilename ".max" ".fbx"
	subFolder= maxfilepath + "/test/"
	fbxFilePath= subFolder + fbxFileName
	assets= #($root)
	
--define the function
	fn exportFBX assets fbxFilePath=(
		select assets
		exportFile fbxFilePath #noPrompt selectedOnly:True  using:FBXEXP
	)


--actually execute the function, passing the arguments to it
	exportFBX assets fbxFilePath

)

I have another question. I’m making a slight modification to path to add a button for an alternate fixed export directory.

I’ve made the changes below, after running the script the result comes back as true, but nothing is being exported.

Also, for this instance of the exporter the prompt needs to appear before exporting. How do I re-enable it?

(

--define the variables 
	fbxFileName= substitutestring maxfilename ".max" ".fbx"
	dir= "c:\\ExporterTest\anims"
	fbxFilePath= dir + fbxFileName
	
	makeDir  dir

	select $root...*
	
--define the function
	fn exportFBX assets fbxFilePath=(
		exportFile fbxFilePath #noPrompt selectedOnly:True  using:FBXEXP
	)


--actually execute the function, passing the arguments to it
	exportFBX assets fbxFilePath

)
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Try this

(
	fn setNewFbx newdir: filename: =
	(	
		filename = if filename != unsupplied then toLower maxfilename else toLower filename
		if filename == "" then return null else
		(
			substitutestring filename ".max" ".fbx"
			if doesDirectoryExist newdir then pathConfig.appendPath newdir filename else null
		)
	)
	fn exportFBX fbxFilePath = (exportFile fbxFilePath #noPrompt selectedOnly:on using:FBXEXP)
	-- u can use this if you want some different file
	-- setNewFbx newdir:@"c:\ExporterTest\anims" filename:@"C:\Temp\Somefile.max"
	-- but in your case
	if (fbxFile = setNewFbx newdir:@"c:\ExporterTest\anims") != null do
	(
		makeDir (getFilenamePath fbxFile)
		select $root...* ; exportFBX fbxFile
	)
)

the problem is a missing slash in the variable ‘dir’

if you execute each line one at a time in the listener, it is obvious:

	
         fbxFileName= substitutestring maxfilename ".max" ".fbx"
	"myFile.fbx"
	dir= "c:\\ExporterTest\anims"
	"c:\ExporterTest\anims"
	fbxFilePath= dir + fbxFileName
	"c:\ExporterTest\animsmyFile.fbx"


FYI When dealing with file paths, I avoid dealing with extra “\” escape sequences
either 1.) by using forward slashes

Dir= "c:/ExporterTest/anims/"

or 2.) using string literals via the ‘@’ prefix

Dir= @"c:\ExporterTest\anims\"
2 Replies
(@gazybara)
Joined: 11 months ago

Posts: 0

That’s way I suggest to use

pathConfig.appendPath <path1> <path2>
(@gazybara)
Joined: 11 months ago

Posts: 0

And another one will be

fn combinePaths strA strB = (pathConfig.resolvePathSymbols (pathConfig.appendPath strA strB))

most of pathConfig methods (including appendPath) automatically resolve path symbols…

also i recommend to use


 (dotnetclass "System.IO.Path").ChangeExtension 
 

instead of


 substitutestring 
 
Page 1 / 2