Load UVW channel map

1 vote
Date Updated: 

I've seen a lot of issues with scripting the saving and loading of UVW data via script. I ran into a problem like that myself and throught I'd share my solution. Basically the loading and saving of UVW maps is not exposed fully via script, only the dialog opens, so you need to fake inserting the file path and hit the load button.

This procedure is partly taken from other similar scripts (of saving out the UVW map channels) but none of them address the multi-loading of such maps. So - here is my method - you can change and paste this snippet into your own loops and scripts if you need to process many objects. In my case I saved out UVW maps and needed to load them into other, similar, objects - for many files.

Note - I've removed all sorts of error-checking (if the window is such and such then do such and such etc.).

The sample below was taken from a test file (attached) where I had two "Teapot" objects and a Turbosmooth on both (you'll notice that the insertion of the UVW_unwrap modifier on the second Teapot happens before the Turbosmooth). I applied an Unwrap_UVW modifier on the first, below the Turbosmooth, and manually saved the UVW map to a file. When I run the script it adds an Unwrap_UVW modifier to the second teapot, at the same level, and loads the saved file into it.


Here it is, enjoy:



fn checkDialog = (
    local hwnd = dialogMonitorOps.getWindowHandle()
    if (hwnd == 0) then (print false)
    else (
        WindowName = UIAccessor.GetWindowText hwnd
        if WindowName != undefined then
            if (findString WindowName "Load UVW") != undefined then
                cWindows = UIAccessor.GetChildWindows hwnd
                for t = 1 to cWindows.count do
                    cWindowsName = (UIAccessor.GetWindowClassName cWindows[t])
                    if cWindowsName == "ComboBoxEx32" then
                        entryField = cWindows[t]
                        UIAccessor.SetWindowText entryField "c:\\Temp\\teapot_uvw.uvw"
                        UIAccessor.PressButtonByName hwnd "&Open"
        print true

dialogMonitorOps.unRegisterNotification id:#test
dialogMonitorOps.enabled = true
dialogMonitorOps.interactive = false
dialogMonitorOps.registerNotification checkDialog id:#test

uvmod = Unwrap_UVW name:"Unwrap_UVW_fixed"
addmodifier $Teapot002 uvmod before:1
select $Teapot002
max modify mode
modPanel.setCurrentObject $Teapot002.modifiers[#Unwrap_UVW_fixed] node:$Teapot002

dialogMonitorOps.enabled = false

uvw_teapots.max256 KB