Wings 3D Development Forum

Full Version: Generate automatic screenshots from wings files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

When I am creating a new 3D model with Wings, I usually store many versions of the datafile during the work in progress, to be able to come back to any previous step and try some other path for the modelling process. The difficulty with such an approach is to know which of these numerous datafiles corresponds to a given modeling step (especially, if you come back to the model, a couple of days or weeks later). As there is no automatic preview for '.wings' files (at least on Windows, the OS that I am using), the only solution is to open one datafile after the other, trying to find the correct one.

To make this process much easier, I have created a Windows command script file (a.k.a batch file) that recursively explores a folder hierarchy, automatically, generates a screenshot for each WINGS datafile it encounters and stores it as a PNG or JPG image with the same base name and the same folder as the initial file. Afterwards, when browsing your folders with the standard file explorer, you've got a nice preview for each of your WINGS datafiles.

The following code block presents the content of the script file that you can copy/paste. You may also directly download the attached text file, but you have to rename it as '.cmd' or '.bat' instead of '.txt' (the forum machinery does not allow one to directly upload batch files, as they may be dangerous beasts) :

Code:
@echo off
rem |---------------------------------------------------------------------------
rem | folder = base folder where to start search for wings datafiles
rem | wings = full path for the Wings3D executable file on your computer
rem | iview = full path for the IrfanView executable file on your computer
rem | crop = crop parameters for screenshots = xoffset,yoffset,width,height
rem | type = image file format used for screenshots (usually 'jpg' or 'png')
rem |---------------------------------------------------------------------------

set folder=D:\Documents\Scene\Wings
set wings=C:\Media\Wings3D\Wings3D.exe
set iview=C:\Media\Irfanview\i_view64.exe
set crop=96,66,1312,912
set type=png

rem |---------------------------------------------------------------------------
rem | loop over all wings datafiles found in subfolders of provided base folder
rem | load each file in Wings3D and use IrfanView to perform screenshot and crop
rem | softly kill 'erl.exe' (and thus Wings3D) before loading next datafile
rem | note: 'ping' command is used to force a 12s delay before taking screenshot
rem |---------------------------------------------------------------------------

for /r "%folder%" %%f in (*.wings) do (
  "%wings%" "%%f"
  ping 127.0.0.1 -n 12 > nul
  "%iview%" /capture=3 /crop=(%crop%^) /convert="%%~dpnf.%type%"
  taskkill /f /im erl.exe > nul 2> nul
  echo %%~dpnf.%type%
)

The automatic screenshot process is based on IrfanView, a free image manipulation tool that offers convenient command line operations. So the first step, before trying to use the script, is to download and install IrfanView on your computer.

The usage of the script file is quite easy, but it needs some tuning to be adapted to your current configuration :
  • In the set folder=... line, put the full path to the folder hierarchy containing your '.wings' files
    (mine is "D:\Documents\Scene\Wings")
  • In the set wings=... line, put the full path to the Wings3D application on your current configuration
    (mine is "C:\Media\Wings3D\Wings3D.exe")
  • In the set iview=... line, put the full path to the IrfanView application on your current configuration
    (mine is "C:\Media\Irfanview\i_view64.exe")
  • In the set crop=... line, put the crop parameters that should be applied to the screenshot. By default, Irfanview captures the whole Wings3D window (without title bar and borders), so if you want to remove the menu, the toolbar, the palettes and the status line, you have to define the crop area in the standard "x,y,w,h" format (on my 1920x1080 laptop screen, I use 96,66,1312,912 as the crop area)
  • In the set type=... line, simply put the file extension you want for your screenshot images (I use 'png' files which usually offer better compression than 'jpg' as screenshots typically contain large areas with uniform colors)

Remark 1 : I use the "ping trick", a common workaround in Windows script file to generate a controlled delay between two script statements. Why is this needed ? As said, the script launches the Wings3D application on every '.wings' file it finds. So when the file is pretty complex, several seconds may be required to parse the data, built the data structures and display the 3D scene on screen. Here the 'ping' command generates a 12 seconds delay after launching Wings3D, before launching Irfanview to take the screenshot. So, even for complex scenes this should be enough to get a correct display on the screen. If you've got a very fast (or very slow) computer, you may adapt this delay on the ping statement (it's the number written after the -n option)

Remark 2 : By default, the screenshots are saved at your screen resolution (except the cropped parts, of course). If you only use screenshots for preview, you may scale down the images before saving them, to reduce disk footprint. This can be easily done, by adding /resize=(50p,50p^) between the /crop=... and the /convert=... options on the Irfanview command line arguments. 50p means rescale at 50%, 25p means rescale at 25%, and so on...

Remark 3 : If you have 'space' characters in your folder names and/or file names, the script correctly deals with them by automatically enclosing names in double quotes. So you don't have to add quotes when defining the content of the folder, wings or iview variables.

Of course, if you have many, many files, the whole process takes a long time due to the 12 seconds delay per file, but as the script is recursive, you simply have to launch the process on the base folder, go to sleep, and watch all your generated screenshots the next morning. Let me know if the script works well for you, or if you encounter some errors when using it.

EDIT: After posting the script, I realized that the initial version only performs a 2-level recursive search. This is sufficient for me, as all my wings files are organized in a 2-level hierarchy, but it may not be sufficient for your own folder hierarchy. So I slightly modified the script to perform a full recursive search, whatever the hierarchy depth starting from the base folder.
That's a nice trick.
Thanks for sharing with us.
Thanks Micheus ! I've just edited the post (and the attached script) to perform full recursive search on wings file. The first version only managed a 2-level folder hierarchy, while the new version is able to find all wings files, whatever the hierarchy depth.
Thank you for sharing your work. I find the idea very cool.