View Full Version : UVW Xform modifier, how to acces 'Apply to Entire Object'?

02 February 2009, 08:18 PM

I'm trying to do a simple script for randomizing the mapping of the selected objects. To do so, the script adds a UVW_Xform modifier to the selected objects and applies a random value to the modifier u and v offsets.
The problem is that I need to enable "Apply to Entire Object" so the modifier changes the whole object mapping, ignoring any possible sub-object selections, but I can't find any property to change this. Is there some way to enable this option in MAXScript?


02 February 2009, 08:38 PM
odd how these things are not exposed...

Two options..

A. Max library file
1. Save a 3ds Max file (say, 'uvwxform.max') with the modifier in each of the two states applied to an object/objects.
2. When you need a UVW XForm modifier, merge the object from the library 'uvwxform.max'
3. Grab the modifier from the object
4. Apply to the object of interest.

Which is only really practical if you only need to create new ones, not adjust existing ones (though replaceInstances might help there).

B. ScaryCode

fn setApplyToEntireObject unwxformmod state = (
-- windows codes
local WM_COMMAND = 0x111 -- Windows Message: Command
local BN_CLICKED = 0 -- clicky the button notification
local BM_SETCHECK = 241 -- checkbutton toggle message ID

-- change to modify panel, open the modifier
if (GetCommandPanelTaskMode() != #modify) do (
SetCommandPanelTaskMode #modify
if (modPanel.getCurrentObject() != unwxformmod) do (
modpanel.setCurrentObject unwxformmod

-- get all the children of the desktop (in case command panel is floating)
local desktopHWND = windows.getDesktopHWND()
-- get its children
local desktopChildren = windows.getChildrenHWND desktopHWND
-- let's find that Apply to Entire Object checkbox
local ateo_checkbox
for child in desktopChildren do ( if (child[5] == "Apply to Entire Object") do ( ateo_checkbox = child ) )

-- not found? uh oh
if (ateo_checkbox == undefined) do ( return undefined )

-- otherwise, let's proceed
local ateo_checkbox_hwnd = ateo_checkbox[1]
local ateo_checkbox_parent = UIAccessor.getParentWindow ateo_checkbox_hwnd
local ateo_checkbox_id = UIAccessor.GetWindowResourceID ateo_checkbox_hwnd
windows.sendMessage ateo_checkbox_hwnd BM_SETCHECK (if (state) then ( 1 ) else ( 0 )) 0
windows.sendMessage ateo_checkbox_parent WM_COMMAND ((bit.shift BN_CLICKED 16) + ateo_checkbox_id) ateo_checkbox_hwnd

-- done


-- <undefined|OK>setApplyToEntireObject uvw_xform_modifier <boolean>
-- e.g.
setApplyToEntireObject $.modifiers[1] true
setApplyToEntireObject $.modifiers[1] false

02 February 2009, 09:46 PM
I will have to go with the ScaryCode™ as I'll have to modify the UVW_XForm modifier values in case the object has one already applied, though I'll give some thought also to your first method using replaceInstances because chances are that I'll need to dig the modifier stack to get the UVW_XForm, and I have no idea how to do it modifiing your sample code :)
(Wich I tested and works like a charm BTW)

Thanks a bunch :thumbsup:

02 February 2009, 12:34 AM
cool - glad it works :)

As for getting the modifier - no need to change the function supplied at all; it's meant to be as abstract as possible so that you can call it on any UVW XForm modifier.

All you have to do is, for example, this:

for o in (getCurrentSelection()) do (
for theMod in o.modifiers do (
if (classOf theMod == uvw_xform) then (
setApplyToEntireObject theMod true

Which basically...
1. Loops over the selection, getting each object
2. Loops over the object's modifiers, getting each modifier
3. Checks whether that modifier is a uvw_xform class modifier
4. Calls the earlier function, feeding it the aforementioned modifier as the modifier for it to adjust.


02 February 2009, 10:27 AM
Duh, of curse. I just need to pass the modifier to the function ...

This is just what I needed, thanks for your time :)

CGTalk Moderation
02 February 2009, 10:28 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.