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?

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).

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)

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.

Follow Us On:

The CGSociety

The CGSociety is the most respected and accessible global organization for creative digital artists. The CGS supports artists at every level by offering a range of services to connect, inform, educate and promote digital artists worldwide. More about us on TheArtSociety.com