LDraw.org Discussion Forums

Full Version: Applescript droplet to generate png previews using LDView
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

The following saved as an application from the AppleScript Editor generates png previews:

property ldview : "/Applications/LDView/LDView.app/Contents/MacOS/LDView"

on run
    set root to choose folder with prompt "Please select folder."
end run

on open root
    if folder of (info for root without size) is true then
    end if
end open

on generatepreview(root)
    set suffix to "\\( -iname \"*.ldr\" -o -iname \"*.mpd\" -o -iname \"*.dat\" \\)"
    set root to (POSIX path of root) as string
    set root to quoted form of ((characters 1 through -2 of root) as string)
    set ldrs to do shell script "find " & root & " -type f " & suffix
    repeat with ldr in paragraphs of ldrs
            set dirname to do shell script "dirname " & quoted form of ldr
            set png to ((characters 1 through -5 of ldr) as string) & ".png"
            do shell script "cd " & dirname & "; " & ldview & " " & quoted form of ldr & " -SaveSnapshot " & quoted form of png
        end try
    end repeat
end generatepreview

It assumes that LDview is in the application folder. Modify the "ldview" property otherwise.