Reading and Modifying Asset File Paths in the 3ds Max File

By Christopher Diggins - 24 Aug, 2009

Some people found the following information in the MAXScript reference for 2010:

 NEW in 3ds Max 2010: The 3ds Max scene file now provides Asset Metadata in a separate stream which can be accessed and modified by external applications. The Asset data is generated and managed by the AssetManager and AssetUser objects.

What left several people scratching their head and wondering was "how exactly can an external application" access and modify this data?! While the 3ds Max file format is not released to the public, we do publicize the fact that it uses the Microsoft OLE structured storage format. This means that you can browse, and even edit, certain properties of a 3ds Max file by using the IStorage and IPropertyStorage interfaces.

This is especially useful if you want to modify asset file paths in a 3ds Max file, without opening the file. This can be accomplished with MAXScript using the functions: getMAXFileAssetMetadata and setMAXFileAssetMetadata. The MAXScript documentation has several pages that discuss the asset file streams in MAX files, but unfortunately doesn't say anything more about how an external application can access these streams.

Unfortunately reading and writing of structured storage files is far from trivial, and out of the scope of what we can cover in the 3ds Max SDK documentation.That said, I can at least provide some tips and pointers that can help you get started if you are determined to edit max files outside of 3ds Max.

First off it is useful to know that the actual C++ implementation of the MAXScript functions for modifying asset file data is released with the 3ds Max SDK and can be found in the file "maxsdk\samples\maxscript\mxsagni\avg_dlx.cpp"  at around line 7600. Search for "get_max_file_asset_metadata_cf" and "set_max_file_asset_metadata_cf". Also in the SDK is a file in "maxsdk\samples\utitlies\maxfind\ShowPropDlg.cpp" that has an algorithm for opening a Max file using the IPropertySetStorage COM interface.

If you are really motivated, this might be enough to get you started but the documentation is extremely sparse and it is hard to follow. OLE programming in C++ is not for the faint-hearted. I strongly suggest looking at the structured storage documentation on MSDN for some help (http://msdn.microsoft.com/en-us/library/aa380365(VS.85).aspx).

I did find a C++ project on CodeProject.com while researching this problem which may also prove to be useful: An ATL and MFC wrapper for structured storage http://www.codeproject.com/KB/atl/structuredstorage.aspx .

Because I really hate programming OLE in C++, I also did some research on structured file format reading and writing in C#. Again on CodeProject.cp, I found two project which were helpful:

  1. An MS word file viewer - http://www.codeproject.com/KB/cs/getwordtext.aspx
  2. An HTML file reader - http://www.codeproject.com/KB/cs/htmlcb.aspx

After all of this I found that rolling my own C# reader isn't too hard if you have the Microsoft Visual Studio SDK installed. With it is a .NET assembly "Microsoft.VisualStudio.OLE.Interop.dll". This assembly isn't documented at all, but using the Object Browser and the MSDN reference I mentioned above I was able to roll a quick and dirty MAX file reader in a couple of hours.

Apart from adding a reference to the dll, the only tricky things that I had to do were:

  1. Define my own constants
  2. Use "dllimport" to import the API StgOpenStg.

I hope that you find this information at least helpful enough to get you started down the path of reading and writing 3ds Max files.

 

Published In
Tags
2 Comments
To post a comment please login or register
christopher-diggins | 8 years ago
There are no short-term plans to release more documentation on the format. The scene serialization mechanism isn't designed for disection at this point.
instinct-vfx | 8 years ago
Are there any plans on releasing more documentation on the format ? As far as i can tell this is a good start. However there is no use of sub-storages if i saw that right, but the complete scene is a stream so that is pretty damn tough to disect. Regards, Thorsten