Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    UVCOMMAND question?

    Cinema 4D SDK
    python r19
    2
    4
    949
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • .
      .del
      last edited by .del

      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.

      1 Reply Last reply Reply Quote 0
      • .
        .del
        last edited by

        ...just realized it's not the layout that makes it work, I need to have the UV Polygons tool activated. I'm going to see if I can activate that tool via python.

        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by m_adam

          Hi @del first of all welcome in the plugincafe community!

          As you figured it out, to have GetActiveUVSet to work you have to open at least one time a TextureView and in your case set the document mode to Muvpolygons.

          Both can be done with.

          c4d.CallCommand(170103) # New Texture View...
                  
          #Enter UV Polygon mode
          doc.SetMode(c4d.Muvpolygons)
          

          Note it's also possible to edit UV directly from UV tag. While you can't use Bodypaint command, it may be an option for you since you only do translation work. For more information please read this thread: https://developers.maxon.net/forum/topic/10915/14369_using-uvcommand-with-multiple-objects/2

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

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 1
          • .
            .del
            last edited by

            Thank you for the guidance. I'll dig into that info.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post