Using UVCOMMAND with Multiple Objects

On 14/08/2018 at 09:24, xxxxxxxx wrote:

Hello,
I'm trying to move UVs using UVCOMMAND for a UDIM setup with multiple selected objects. In my current script, the transforms only happen to the last object in the list. I've tried other flags for the Active UV set and selecting the UV Polygons before UVCOMMAND is called. Nothing is working. Could someone please tell me what I am doing incorrectly? Here's my code.

def moveUVs(obj,index) :
    # Retrieves active UVSet
    handle = bodypaint.GetActiveUVSet(doc, c4d.GETACTIVEUVSET_ALL)
    if not handle:
        print "No active UVSet!"
        return
    
    settings = c4d.BaseContainer()
    settings[c4d.UVCOMMAND_TRANSFORM_MOVE_X] = index
    settings[c4d.UVCOMMAND_TRANSFORM_MOVE_Y] = 0
    settings[c4d.UVCOMMAND_TRANSFORM_SCALE_X] = 1
    settings[c4d.UVCOMMAND_TRANSFORM_SCALE_Y] = 1
    settings[c4d.UVCOMMAND_TRANSFORM_ANGLE] = utils.DegToRad(0)
  
    # Retrieves UVW list
    uvw = handle.GetUVW()
    if uvw is None:
        return
    
    # Calls UVCOMMAND_TRANSFORM to change UVW list
    ret = bodypaint.CallUVCommand(handle.GetPoints(), handle.GetPointCount(), handle.GetPolys(), handle.GetPolyCount(), uvw,
                                  handle.GetPolySel(), handle.GetUVPointSel(), handle.GetBaseObject(), handle.GetMode(), c4d.UVCOMMAND_TRANSFORM, settings)
    if not ret:
        print "CallUVCommand() failed!"
        return
    
    print "CallUVCommand() successfully called"
  
    # Sets the transformedUVW from Texture View 
    if handle.SetUVWFromTextureView(uvw, True, True, True) :
        print "UVW from Texture View successfully set"
    else:
        print "UVW from Texture View failed to be set!"
    
    # Releases active UVSet
    bodypaint.FreeActiveUVSet(handle)
  
def main() :
    objs = doc.GetActiveObjects(0)
    doc.StartUndo()
    for idx, obj in enumerate(objs) :
        moveUVs(obj,idx)
        c4d.EventAdd()
    doc.EndUndo()
  
if __name__=='__main__':
    main()

Thank you!

On 16/08/2018 at 01:44, xxxxxxxx wrote:

Hi, blastFrame!

As you already figured it out, UVCommand only works for the current displayed UV. And since bodypaint can only display one UV Set, you can't modify multiple objects at the same time.
But you can directly access data in the tag, and move the point.

Here a quick sample

import c4d
  
def moveUVs(obj, idx) :
    tag = obj.GetTag(c4d.Tuvw)
    if not tag:
        return
    
    for polyIndex in xrange(obj.GetPolygonCount()) :
        uvwdict = tag.GetSlow(polyIndex)
        move = c4d.Vector(1*idx, 0, 0)
        a = uvwdict["a"] + move
        b = uvwdict["b"] + move
        c = uvwdict["c"] + move
        d = uvwdict["d"] + move
        tag.SetSlow(polyIndex, a, b, c, d)
  
def main() :
    objs = doc.GetActiveObjects(0)
    doc.StartUndo()
    for idx, obj in enumerate(objs) :
        moveUVs(obj,idx)
        c4d.EventAdd
    doc.EndUndo()
  
if __name__=='__main__':
    main()

If you have any question, please let me know!
Cheers,
Maxime. 🙂

On 21/08/2018 at 16:25, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Hi, blastFrame!

As you already figured it out, UVCommand only works for the current displayed UV. And since bodypaint can only display one UV Set, you can't modify multiple objects at the same time.
But you can directly access data in the tag, and move the point.

Here a quick sample

import c4d
 
def moveUVs(obj, idx) :
    tag = obj.GetTag(c4d.Tuvw)
    if not tag:
        return
    
    for polyIndex in xrange(obj.GetPolygonCount()) :
        uvwdict = tag.GetSlow(polyIndex)
        move = c4d.Vector(1*idx, 0, 0)
        a = uvwdict["a"] + move
        b = uvwdict["b"] + move
        c = uvwdict["c"] + move
        d = uvwdict["d"] + move
        tag.SetSlow(polyIndex, a, b, c, d)
 
def main() :
    objs = doc.GetActiveObjects(0)
    doc.StartUndo()
    for idx, obj in enumerate(objs) :
        moveUVs(obj,idx)
        c4d.EventAdd
    doc.EndUndo()
 
if __name__=='__main__':
    main()

If you have any question, please let me know!
Cheers,
Maxime. 🙂

This was very helpful. Thank you, Maxime!