I'm trying to convert a working COFFEE script for changing the modeling axis to Python. Updated tool data is printed to the Console but the Axis parameter is not changing.
tool_dat = doc.GetActiveToolData()
tool_dat[c4d.MDATA_AXIS_MODE] = c4d.MDATA_AXIS_MODE_FREE
The script you posted does work with for instance the Live Selection tool but does not work with Move/Scale/Rotate tools.
The following script changes the MDATA_AXIS_MODE to MDATA_AXIS_MODE_FREE for any active tool:
from c4d import plugins
def SetToolData(doc, toolID, paramID, data):
plug = plugins.FindPlugin(toolID, c4d.PLUGINTYPE_TOOL)
if plug is None:
plug[paramID] = data
SetToolData(doc, doc.GetAction(), c4d.MDATA_AXIS_MODE, c4d.MDATA_AXIS_MODE_FREE)
The above script does not use GetActiveToolData(). It retrieves the object for the active tool (with FindPlugin()) and sets the parameter (with operator ).
For some technical reason, several tools need their settings to be changed via parameters and not accessing the tool data container directly.
Thanks for the solution and explanation Yannick. It's working perfectly now and I can finish converting my scripts.