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/Cinema4DCPPSDK/html/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);
... would be in python:
wmgr = c4d.modules.character.CAWeightMgr
wasSuccessfull = wmgr.AutoWeight(doc,False)
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.
... 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.
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:
skinObject = c4d.BaseObject(c4d.Oskin)
if skinObject is None:
doc.InsertObject(skinObject, polyObject, None)
# add joints
for joint in joints:
# select tag
# update weight manager
# select all joints
# auto weight
Thanks Sebastian for your answer !
Unfortunately using CAWeightMgr as static class makes no difference for me: it's still not working.
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):
This should zero the weights of the selected joint - but it doesn't. Return value is always false
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 ?
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 !