• Categories
    • Overview
    • News & Information
    • Cinema 4D SDK Support
    • Cineware SDK Support
    • ZBrush 4D SDK Support
    • Bugs
    • General Talk
  • Unread
  • Recent
  • Tags
  • Users
  • Register
  • Login
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
  • Register
  • Login

problems with CAWeightMgr

Cinema 4D SDK
r19 python
3
5
968
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.
  • R
    ruckzuck
    last edited by May 25, 2019, 12:26 PM

    Hi,

    I'm struggling with c4d.modules.character.CAWeightMgr for quite some time now. Unfortunately I couldn't find any example how to access the weight manager using python.

    I tried to adapt the mini example in the C++ docs (https://developers.maxon.net/docs/cpp/2023_2/page_manual_caweigthmgr.html) but even this didn't work:

    CAWeightMgr::SetParameter(doc, ID_CA_WEIGHT_MGR_AUTOWEIGHT_MODE, ID_CA_WEIGHT_MGR_AUTOWEIGHT_MODE_VISIBLE);
    CAWeightMgr::SetParameter(doc, ID_CA_WEIGHT_MGR_AUTOWEIGHT_VISIBILITY_RATIO, 1.0); 
    CAWeightMgr::AutoWeight(doc, false);
    

    ... would be in python:

    wmgr = c4d.modules.character.CAWeightMgr
    wmgr.SetParameter(doc,c4d.ID_CA_WEIGHT_MGR_AUTOWEIGHT_MODE,c4d.ID_CA_WEIGHT_MGR_AUTOWEIGHT_MODE_VISIBLE)
    wmgr.SetParameter(doc,c4d.ID_CA_WEIGHT_MGR_AUTOWEIGHT_VISIBILITY_RATIO,1.0)
    c4d.EventAdd()
    wasSuccessfull = wmgr.AutoWeight(doc,False)
    print wasSuccessfull
    

    Parameter were set correctly (and UI was also updated properly) but the actual FunctionCall "AutoWeight" failed. And this goes on with almost all other functions 😞

    The only functions that work (at least for me) were selecting und unselecting joints in the weight manager.

    CAWeightMgr.NormalizeWeights()
    CAWeightMgr.ClearWeights()
    CAWeightMgr.AutoWeight()
    CAWeightMgr.MirrorWeights()
    CAWeightMgr.BakeWeights()
    CAWeightMgr.CopyWeights()
    CAWeightMgr.PasteWeights()
    CAWeightMgr.FlipWeights()
    CAWeightMgr.SmoothWeights()
    CAWeightMgr.ApplyWeightFunction()
    

    ... return code of the above functions is always False 😞

    Would be great when a detailed example of using one of these functions could be posted.

    cheers,
    Jens

    1 Reply Last reply Reply Quote 0
    • S
      s_bach
      last edited by May 25, 2019, 2:13 PM

      Hello,

      CAWeightMgr is a static class; all member functions are static functions:

      It should be something like this:

      c4d.modules.character.CAWeightMgr.SetParameter(doc, c4d.ID_CA_WEIGHT_MGR_ENABLE_DISPLAY, True)
      

      Some simple example would be:

      # This example creates and adds a weight tag and a skin object
      # to the given polygon object. The joints stored in the given list
      # are linked in the weight tag. The weight manager is updated
      # and used to create auto-weights.
      
      # add weight tag and skin object
      
      weightTag = c4d.modules.character.CAWeightTag()
      if weightTag is None:
      		return
      
      skinObject = c4d.BaseObject(c4d.Oskin)
      if skinObject is None:
      		return
      
      polyObject.InsertTag(weightTag)
      doc.InsertObject(skinObject, polyObject, None)
      
      # add joints
      
      for joint in joints:
          weightTag.AddJoint(joint)
      		
      # select tag
      doc.SetActiveTag(weightTag, c4d.SELECTION_NEW)
      
      # update weight manager
      c4d.modules.character.CAWeightMgr.Update(doc)
      
      # select all joints
      c4d.modules.character.CAWeightMgr.SelectAllJoints(doc)
      
      # auto weight
      c4d.modules.character.CAWeightMgr.AutoWeight(doc, False)
      
      c4d.EventAdd()
      

      best wishes,
      Sebastian

      MAXON SDK Specialist

      Development Blog, MAXON Registered Developer

      1 Reply Last reply Reply Quote 2
      • R
        ruckzuck
        last edited by May 25, 2019, 2:31 PM

        Thanks Sebastian for your answer !

        Unfortunately using CAWeightMgr as static class makes no difference for me: it's still not working.

        Simple example:

        • create plane
        • give plane a weight tag
        • create joint
        • insert joint into joint list of weight tag
        • open weight manager
        • select joint and click on "apply all" (mode should be already on "absolute")

        Now this single joint has 100% weighting of all plane points

        Give plane a python script tag and insert this single code line (while joint is still selected in weight manager):

        print c4d.modules.character.CAWeightMgr.ClearWeights(doc)
        

        This should zero the weights of the selected joint - but it doesn't. Return value is always false ☹

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by Manuel May 27, 2019, 2:48 PM May 27, 2019, 2:47 PM

          hello,

          I can confirm that, after running the code, the function is trying to create an "undo" state on the document and as it can't it just get out.

          This function is working fine if you call it in the Script Manager.

          Calling this function in a python tag (that will run over and over) is not a good place.
          Do you have a particular scenario in mind ?

          Cheers
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 1
          • R
            ruckzuck
            last edited by May 27, 2019, 6:13 PM

            Hi Manuel,

            perfect - in the Script Manager everything works as expected.
            Running the code via python tag isn't important to me - I just wasn't aware of this difference ScriptMgr <> PythonTag concerning the execution of the code.

            Thanks a lot for your solution !

            Cheers,
            Jens

            1 Reply Last reply Reply Quote 0
            3 out of 5
            • First post
              Last post

            Looks like your connection to Maxon Developers was lost, please wait while we try to reconnect.