ScriptSpot

Forum topic · General Scripting

Problem manipulating UV coords with maxscript

By zwrtron · 2020-09-07

Description

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 (2)

Swordslayer · 2020-09-17

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 · 2020-09-18

Thank you, this works perfectly.