Hi - I'm working on a Python script that applies a texture to a model and I'd like to move the UV around after it's applied. The script works if I set the c4d layout to my version of UV editing tools but if I'm in a modeling layout the script is unable to return the handle when calling bodypaint.GetActiveUVSet()
. Is there a way to to set the active UV without being in a UV editing layout?
Here are some relevant parts of the script -
def UVbag(model, settings):
doc.SetActiveObject(model)
# Retrieves active UVSet
handle = bodypaint.GetActiveUVSet(doc, c4d.GETACTIVEUVSET_ALL)
if not handle:
print "No active UVSet!"
return
# 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(), model, handle.GetMode(), c4d.UVCOMMAND_TRANSFORM, settings)
if not ret:
print "CallUVCommand() failed!"
return
# Sets the transformedUVW from Texture View
if handle.SetUVWFromTextureView(uvw, True, True, True):
pass
else:
print "UVW from Texture View failed to be set!"
# Releases active UVSet
bodypaint.FreeActiveUVSet(handle)
snippet from main part of script -
tags = newObj.GetTags()
#adjust UV map to match our png layouts
# Builds UVCOMMAND_TRANSFORM container for the command settings
settings = c4d.BaseContainer()
for tag in tags:
if tag.GetType() == 5673:
polys = newObj.GetPolygonS()
polys.DeselectAll()
if tag.GetName() in ["back"]:
tagSelection = tag.GetBaseSelect()
tagSelection.CopyTo(polys)
c4d.EventAdd()
settings[c4d.UVCOMMAND_TRANSFORM_MOVE_Y] = .25
settings[c4d.UVCOMMAND_TRANSFORM_SCALE_X] = 1
settings[c4d.UVCOMMAND_TRANSFORM_SCALE_Y] = -.5
UVbag(newObj, settings)#
if tag.GetName() == "Face 1":
tagSelection = tag.GetBaseSelect()
tagSelection.CopyTo(polys)
c4d.EventAdd()
settings[c4d.UVCOMMAND_TRANSFORM_MOVE_Y] = -.25
settings[c4d.UVCOMMAND_TRANSFORM_SCALE_X] = 1
settings[c4d.UVCOMMAND_TRANSFORM_SCALE_Y] = .5
UVbag(newObj, settings)
Any help or insight is appreciated.