Problem manipulating UV coords with maxscript

Hey everyone,
I've been working on script which moves UVW map coordinates by specific Y offset. The goal is, that for each object matching criteria (e.g. $*a*) will move all faces of UV by -2 on Y axis.

This is what I tried :

_objs = $Sphere*
_yOffset = -2
 
for _o in _objs where superClassOf _o == GeometryClass do (
   PolyOp.SetFaceSelection _o #none --deselect all faces
   ConvertToPoly _o
   _unwrap = Unwrap_UVW()
   AddModifier _o _unwrap
   _unwrap.SelectFaces #{1..(PolyOp.GetNumFaces _o)} --select all faces
   _unwrap.MoveSelected [0, _yOffset, 0] --move by offset
   CollapseStack _o
 
)

But there are some problems:
When executed, the script will only work if the object(s) is selected.
If the object(s) is(are) not selected the Unwrap modifier is added but the faces are either not selected or the UV coords are not moved.

Is there something I'm doing wrong?

Thanks.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Swordslayer's picture

 

Unwrap only works if the object it is applied to is the currently selected object and the unwrap modifier is the active modifier in the stack. For what you want to a better suited modifier is UVWXform which has no such limitations:

offsetMod = UVW_Xform V_Offset:_yOffset
 
for obj in _objs where canConvertTo obj Editable_Poly do
(
    convertToPoly obj
    polyOp.setFaceSelection obj #none
 
    addModifier obj offsetMod
    collapseStack obj 
)
zwrtron's picture

Thank you, this works

Thank you, this works perfectly.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.