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.

UsdExporter error

UsdExporter error

mburgoyneYW5NV
Explorer Explorer
807 Views
5 Replies
Message 1 of 6

UsdExporter error

mburgoyneYW5NV
Explorer
Explorer

 

filePath =  (maxfilepath + trimRight (maxFileName) ".max" + "\\" + "final.usdz")
opt = USDExporter.CreateOptions()
opt.reset()
opt.FileFormat = #usdz
opt.Lights=false 
opt.Cameras=false
ExportFile filePath #noPrompt exportOptions:opt selectedOnly:true

 

This gives me an error unless I export the file manually first.

 

UsdExporter error : #binary or #ascii are not valid file formats for the ".usdz" extension, consider using #usdz instead.

 

I think it has something to do with the file needing the .usdz extension before it can export a usdz. Anyone have any ideas on how to get around this?

0 Likes
Accepted solutions (1)
808 Views
5 Replies
Replies (5)
Message 2 of 6

mburgoyneYW5NV
Explorer
Explorer
from pymxs import runtime as mxs

myfile = “filePath”

opts = mxs.USDExporter.CreateOptions()

opts.FileFormat = “#usdz”

mxs.USDExporter.exportFile( myfile, exportOptions=opts)

Using python gives the same response.

0 Likes
Message 3 of 6

eric.brosseau
Autodesk
Autodesk
Accepted solution

Hello @mburgoyneYW5NV ,

The USD exporter has its specifics and to prevent any lost options, it is preferable to stick to it.

 

The maxscript version of your snippet would look like this:

filePath =  (maxfilepath + trimRight (maxFileName) ".max" + "\\" + "final.usdz")
opt = USDExporter.CreateOptions()
opt.FileFormat = #usdz
opt.Lights=false
opt.Cameras=false
USDExporter.ExportFile filePath exportOptions:opt contentSource=#selected

 

as for the Python version, the maxscript enum value '#usdz' must be translated from a Python string to a maxscript enum:

from pymxs import runtime as mxs
myfile = mxs.maxfilepath + mxs.trimRight (mxs.maxFileName, ".max") + "\\final.usdz"
opts = mxs.USDExporter.CreateOptions()
opts.FileFormat = mxs.Name("usdz")
mxs.USDExporter.exportFile( myfile, exportOptions=opts, contentSource=mxs.Name("selected"))

 

Hope it helps,

Eric Brosseau
Senior Software Developer, 3ds Max, Autodesk
0 Likes
Message 4 of 6

julien.deboise
Autodesk
Autodesk

To add a bit to what Eric said, 

 

There are two ways to export to USD.

 

Via the generic file export maxscript function "ExportFile" and via "UsdExporter.ExportFile". The generic MXS export function cannot receive options as arguments. In your snippet, you are instanciating an option object, but you are not actually passing it to ExportFile, it will just get ingored :

ExportFile filePath #noPrompt exportOptions:opt selectedOnly:true

ExportFile works with global options, which are specified in UsdExporter.UIOptions (so if you edit that via script, you will get the expected results). This is also why if you go through the UI, further calls to ExportFile will "work" - UI Options are saved into that .UIOptions object. Note that this is how most exporters in max work, i.e. you specify options via some global object and then call ExportFile ...

 

Because is this error prone, and frankly very annoying because you always have to worry about the state of that global option object, we also created a dedicated export function, which I would encourage you to use : 

 

USDExporter.ExportFile 

 

This one can receive as argument an options object, so you don't have to worry about the current state of UsdExporter.UIOptions . In his answer, Eric shows how to use it. 

 

 

 

0 Likes
Message 5 of 6

mburgoyneYW5NV
Explorer
Explorer
USDExporter.ExportFile (maxfilepath + trimRight (maxFileName) ".max" + "\\" + "final.usdz") exportOptions:opt nodeList:selection

How odd as this is where I started. The issue that I ran into was that it would always bring up the dialog so I couldn't get an export without a user clicking on the dialog. Using ExportFile allowed me to use #noprompt though. Your code seems to work fine though I'm unable to see how my USDExporter.ExportFile code was different and didn't work.

 

Anyway thanks for the help seems to work now.

0 Likes
Message 6 of 6

julien.deboise
Autodesk
Autodesk

Hmm, not sure what happened exactly, but if the dialog was popping up, then it was the generic function being called for sure, UsdExport.ExportFile does not open the window in any case.

 

Glad it is working now!

0 Likes