problems with CAWeightMgr
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); 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.
s_bach last edited by
CAWeightMgris 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()
Thanks Sebastian for your answer !
Unfortunately using CAWeightMgr as static class makes no difference for me: it's still not working.
- 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):
This should zero the weights of the selected joint - but it doesn't. Return value is always false
m_magalhaes last edited by m_magalhaes
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 !