Automating 3Ds Max export to Unreal Datasmith using Python

Unreal has quite a handy plugin for 3Ds Max that is able to export to Unreal Datasmith.

Advantages of using Datasmith over FBX or Alembic:

  1. Geometry is exported as a hierarchy, rather than just a single actor. If you have 100 distinct components, you have each component as a single actor, rather than 100 material slots named “Element 0” to “Element 99”. This opens a door for further post-processing, such as automatically assigning materials based on actor name
  2. Animation is exported as Level Sequence.

Disadvantages:

  1. The exporter AFAIK does not support deformations in alembic cache. Only transformations are exported into a level sequence. This stands to reason since Geometry cache is still experimental in Unreal (as of 4.26.1).
  2. Some animations might not translate 1:1. We have experienced some “jaggedness” when exporting to Unreal. Be sure that the animation looks alright with “Realtime” turned on in the Max, before sending it in Unreal.
  3. 3Ds Max — from programmer's standpoint, Max has awful documentation about Python API and API itself is not great. 2020 version still comes with Python 2, but this should be fixed already with the 2021 version.

You can open the script editor in 3Ds Max by going through menu: “Scripting -> Script editor”. Go ahead and open “Script listener” too, so you can see interactive results. Evaluate a line by highlighting text in the script editor and hit “shift-enter”.

You can use the following command to run max in “headless” mode and quit max after the export was finished:

Source: https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/3DSMax/files/GUID-BCB04DEC-7967-4091-B980-638CFDFE47EC-htm.html

Sadly, there is no way to pass arguments from max to the python script. You can however create a file, run the script and then read the file in the script. You can also create a new text file, where you can write logs or results of your operation. The beauty is that you can do just about anything once you are in a python environment.

If you are interested in the source code of the Datasmith plugin for Max, you can find it in Unreal Engine repository, at path “Source/Programs/Enterprise/Datasmith”.