Solved UVCOMMAND_RELAX does not use the RELAXUV_EDGESEL_POINTER

Hello,

I would like to use UV Relaxing and in particular pass the current edge selection via RELAXUV_EDGESEL_POINTER to create UV seams on the selected edges.

Basically the script does the UV Relaxing and I can see this clearly in the UV Editor Window, it doesn't report any errors and the res of SendModelingCommand() also returns True. Also I check via print(edge_selection.GetCount()) if my selection is passed at all and the count always matches the current edge selection. However, the relaxing does not use the edge selection as it would work in UV Manager via the UV Relaxing tab.

I also found an older thread from 2016 mentioning that RELAXUV_EDGESEL_POINTER expects a string reference to a selection tag, although the SDK clearly indicates that a c4d.BaseSelect is expected, of course I tried that too, but that also remains unsuccessful.

from typing import Optional
import c4d

doc: c4d.documents.BaseDocument  # The active document
op: Optional[c4d.BaseObject]  # The active object, None if unselected

def main() -> None:
    Unwrap(op)

def Unwrap(obj: c4d.BaseObject):
    if not isinstance(obj, c4d.PolygonObject):
        return None
    
    edge_selection = get_selected_edges(obj)
    print(edge_selection.GetCount())
    # Set up the settings for the UV unwrapping.
    settings = c4d.BaseContainer()
    settings[c4d.RELAXUV_KEEP_BORDER] = False
    settings[c4d.RELAXUV_KEEP_NEIGHBORS] = False
    settings[c4d.RELAXUV_KEEP_POINTSEL] = False
    settings[c4d.RELAXUV_CUT_EDGESEL] = True
    settings[c4d.RELAXUV_EDGESEL_POINTER] = edge_selection
    settings[c4d.RELAXUV_MAX_ITERATIONS] = 0
    settings[c4d.RELAXUV_MODE] = 0

    # Execute the UV unwrapping command.
    res = c4d.utils.SendModelingCommand(command=1053624,
                                        list=[obj],
                                        mode=c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                                        bc=settings,
                                        doc=doc)
    print(res)
    c4d.EventAdd()



def get_selected_edges(obj):
    if not isinstance(obj, c4d.PolygonObject):
        return None

    neighbor = c4d.utils.Neighbor()
    neighbor.Init(obj)

    return obj.GetSelectedEdges(neighbor, c4d.EDGESELECTIONTYPE_SELECTION)

"""
def state():
    # Defines the state of the command in a menu. Similar to CommandData.GetState.
    return c4d.CMD_ENABLED
"""

if __name__ == '__main__':
    main()

Hello @vwgamedev,

Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!

Getting Started

Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:

About your First Question

The numeric value 1053624 is not the value of the symbol c4d.UVCOMMAND_RELAX but c4d.MCOMMAND_AUTOMATICUV. So, your script is not relaxing but unwrapping, making all the settings you define meaningless. This is the exact reason for why you should use symbols and not integer values.

Cheers,
Ferdinand

MAXON SDK Specialist
developers.maxon.net

@ferdinand
Thank you for the hint and the superfast response! I was not aware that these symbols dissolve into these numbers, which of course makes it much easier to work with them now. I was able to solve it with CallUVCommand:

    settings = c4d.BaseContainer()
    settings[c4d.RELAXUV_KEEP_BORDER] = False
    settings[c4d.RELAXUV_KEEP_NEIGHBORS] = False
    settings[c4d.RELAXUV_KEEP_POINTSEL] = False
    settings[c4d.RELAXUV_CUT_EDGESEL] = True
    settings[c4d.RELAXUV_EDGESEL_POINTER] = edge_sellection
    settings[c4d.RELAXUV_MAX_ITERATIONS] = 1
    settings[c4d.RELAXUV_MODE] = c4d.RELAXUV_MODE_ABF
    ret = c4d.modules.bodypaint.CallUVCommand(handle.GetPoints(),
                                              handle.GetPointCount(),
                                              handle.GetPolys(),
                                              handle.GetPolyCount(),
                                              uvw,
                                              handle.GetPolySel(),
                                              handle.GetUVPointSel(),
                                              obj,
                                              handle.GetMode(),
                                              c4d.UVCOMMAND_RELAX,
                                              settings)