Retrieving the 3DSMax File Thumbnail with DotNet

Oct 5, 2008 by     12 Comments    Posted under: 3dsMax, DotNet, Maxscript, Technical Research

Firstly, a small disclaimer – If you are unsure about any of the information contained on this page, Please do not try to implement it.

Before Max opted for DotNet integration, You could use the Windows ActiveX thumbnail component to view the 3dsMax file thumbnail. I have always found this small image to be very useful. However, when looking for a method to retrieve this via DotNet, I found it much more difficult. There is very little written about this, and I was getting nowhere until and I was fortunate enough to have Cuney Tozdas of Splutterfish point me towards two C++ files in the SDK examples. Please note that I am not a programmer, so apologies if there are any inaccuracies in my text.

How Max Stores it

The notes in the SDK pointed me towards the notion of IPropertyStorage and Structured Storage. Basically, the summary info of a Max file is set using this method. So not only is the Thumbnail stored in this part of the file, there are options to store many other pieces of information pertaining to the maxfile. You can see this by picking File>Summary Info in 3dsMax. The bad news is that novices like myself are not going to get near the level of programming needed to access this part of a file without some C++ knowledge.

Fortunately, help is at hand because it just so happened that while researching IPropertyStorage I stumbled across something on from Microsoft. MS Office files also use the same method as 3dsMax to store information in office files, using OLE Structured Storage, and Microsoft have provided a class for dealing with the lower level stuff for you called DSOFile.

DsoFile is a COM class and can be freely downloaded from this link

http://support.microsoft.com/kb/224351

And the tricky bit….

Com classes need to be registered, which means that you have to use regsrv32 in order to do this. If you use the installer from the Microsoft website it will perform this step for you. However, should you ever move the dll or are interested here are the steps for performing this manually. If anyone knows about building setup projects in Visual Studio to automate this i’d be grateful if they could let me know, as i would much prefer to give an installer for this and save everyone the trouble.

  1. Once your Window’s operating system has loaded completely, click on Start and then click on Run.
  2. Input in the Run field a command that tells your computer to register the DLL file. You will need to input specific information including the path and the file name. The following is a template for the command: regsvr32 “FileName.dll”
    It is important to note that path is the actually location or directory of where the file is located.

  1. Once the command is input into the Run field correctly, press Enter.
  2. Once the DLL has been registered, you should receive a confirmation in the form of a pop up box.

This message will list your newly registered DLL file and confirm that is was successfully registered into the registry.

Once registered, you will now be able to use this class in Visual Studio. I’m not going to go into how to use DSOfile for this, as you can figure this out from the source provided from microsoft. When you add a reference to a COM class in Visual Studio, it creates an interop class that allows the .net framework and the COM class to talk to each other. So as well as registering the DSOfile dll, you will need to load the InterOp class as an assembly in any MaxScript code to use it.

The MaxFileInfo Class

I have written a basic dotnet class with a few properties and an overloaded method to retrieve the Max Thumbnail. Note that when instantiated, the MaxFileInfo class creates a MaxFileinfo dotnetobject. This means that once created, it will automatically reference the information properties. However, the Thumbnail access is fast so it is generated on demand. In my HitchHiker utility at the top It propagates the control almost immediately.

to create a MaxFileInfo object, you provide a string path variable

MaxFileInfo “<Maxfile path and filename>”

I have provided two options – calling Thumbnail on the file will return a DotNet image, useful if you are building a dotNet rollout in max, or by specifying Thumbnail True will copy this to the clipboard and allow you to use getclipboardBitmap() to put onto a MXS button. I have included a small example of the two methods in the download.

Still to do…

This class will only currently work in 32 bit versions of Max and Windows. Someone very kindly recompiled DSOFile for the X64 platform for me and i am working around a couple of issues at the moment, so I will hope to release a working version for the X64 platform very soon. I am slightly behind on this because my Laptop runs 32bit vista and my work machine XPx64, so i don’t get an awful lot of time to test in this environment. I will be upgrading my laptop shortly in order to develop this further, as without 64bit compatibility it is about as much use as a chocolate teapot. Indeed, i wish it was more straightforward.

I will be the first to say that this implementation is far from perfect. There are a couple of other references that need to be addressed depending on the platform you are running. On XP, I sometimes had to provide the stdole.dll also, as well as visualbasic.compatibility.dll as this is used by the class to convert the picture thumbnail to a dotnet image.

If you have any questions or need help with this class, feel free to email me (pete at lonerobot dot com) or PM me via CGTalk. If you want to use this in any scripts, you are freely welcome to do so, although I’d appreciate a mention!

I have also looked into extending this class with a few GDI+ methods, embedding the file information into the image before it returns it with some layout control, as well as a crude resampling routine to resize the thumbnail to something larger.

Included in the download is a very basic utility written in Visual Studio that allows you to browse files via a treeview. It has drag and drop functionality too. Its just provided as is, in the hope it would be useful to someone.

The other thing to add to this class library would be the comprehensive ability to specify the summary properties of a maxfile via dotnet. If you think this would be of particular use to you, please let me know, and I might be able to find the time to write it for you.

download

12 Comments + Add Comment

  • avatar

    Hello fajar, just collect the thumbnails into an array and create an imagelist from the contents. You can then specify the image of the listviewitem from the index of the imagelist. Simples!

  • avatar

    Mr.Lone Robot: how can I use it in dotNet listview as image ? Would be very happy if you could gi ‘me an idea how use it ! not as btn image but as image only.

    Thanks

    Best regard

    Fajar

  • avatar

    Yup, source is easily viewable – not much to look at but took a bit of research to get there. Feel free to extract it – dsofile does all the tricky stuff 😉

  • avatar

    @Tarek : You can find the 64 bits dso file here : http://www.keysolutions.com/blogs/kenyee.nsf/d6plinks/KKYE-79KRU6

  • avatar

    @LoneRobot : You save my day !!

    @Guenter : LoneRobot did not obfuscate the MaxFileInfo.dll, so you can use Reflector and get the source, check : http://www.red-gate.com/products/reflector/.

  • avatar

    sure, I’ll dig it out and post it in the next few days.

  • avatar

    Any chance of getting the source code for MaxFileInfo.dll ? – I would like to port this to Java.

    Thanks and keep up the great work,

    guenter

  • avatar

    Dear mr Pete,

    I saw an article about your nice project in wich you use dsofile http://lonerobot.net/?p=151
    and i am writing a small utility related to DSOFILE on vb6, and i am facing problem with my WIN7 64 bits(it’s not working), i read that you got a dsofile from someone that works for win 64 bits, i would like to know if it’s possible that you provide me the dsofile 64 bits to see if it works on my PC.

    I hope that you will help me fix this problem by providing me the 64 bits dsofile

    Thanks in advance and best regards

  • avatar

    Hi Leonardo,

    Are you running max on the 32 bit platform? The old activex explorer control used to preview maxfiles but not actually extract the thumbnail like my assembly does. Doing the same outside DotNet is outside my knowledge, I’m afraid. You could look for articles on COM Structured Storage and see what you find. Sorry I cant be of more help.

  • avatar

    i would like to access a max file thunbnails using COM an not NET because for now i work with activex.
    I woube really great if you can point me on the right direction. Thanx in advance!!!
    And compliments for your articles, very useful!!

  • avatar

    yes Can I have dso for 64bit!!

  • avatar

    Do you have the 64bit DSOfile DLL available ? I have the DSO v2.1 32bit from MS, but cant find a 64bit version 2.1 anywhere ?

    (And dont have the C++ knowledge & capability to recompile myself)
    Thanks

Got anything to say? Go ahead and leave a comment!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>