Yes, the workaround is good. The difference between that, though, and what is appropriate to do from tag code is that you are changing attributes of the cube -- customarily, tags ride along on objects and modify their output, but not the objects themselves. So, removing the tag should leave the object as it was. Additionally, there is the issue that while in your example, you are using one tag for one object, an Object Properties tag works by inheritance, and so needs to affect an unknown number of objects.
A more appropriate solution is to use a script or command that, when run, traverses the object tree and performs the modification you are making above. This is an explicit user-action that carries along with it the statement "
yes, I am aware that I am modifying my model." Here is some python that does that:
Code: Select allimport c4d
from c4d import *
class mx:
ID_MXOBJPROPSTAG = 1023118;
ID_MXOBJIDCOLOR = 1201;
def traverse(obj, to_default, mode, color):
while obj:
t_mode = mode;
t_color = color;
if not to_default:
tag = obj.GetTag(mx.ID_MXOBJPROPSTAG);
if tag:
t_mode = 1; # this is Automatic mode
t_color = tag.__getitem__(mx.ID_MXOBJIDCOLOR);
obj.__setitem__(c4d.ID_BASEOBJECT_COLOR, t_color);
obj.__setitem__(c4d.ID_BASEOBJECT_USECOLOR, t_mode);
traverse(obj.GetDown(), to_default, t_mode, t_color);
obj = obj.GetNext();
def display_color_to_objid(obj):
traverse(obj, False, 0, Vector(255));
def display_color_to_default(obj):
traverse(obj, True, 0, Vector(255));
def main():
doc = documents.GetActiveDocument();
top = doc.GetFirstObject();
obj = doc.GetActiveObject();
if obj and obj.GetType() == 1023866 and obj[c4d.ID_USERDATA,1]:
# this is a PythonGenerator object, it has a UserData
# and the value of the first slot evaluated to True
display_color_to_default(top);
else:
# this code might be running anywhere, so we are going
# to assume that it wants to synchronize obj id colors
display_color_to_objid(top);
EventAdd();
if __name__=='__main__':
main()
What you can do with this is:
- create a Python Generator object.
- Set its Optimize Cache to checked.
- set its Reset on Frame 0 to un-checked.
- copy the above code into its Code area.
- add a UserData to it (in the AM UserData menu).
- name the UserData "Set to default" and make its type Boolean.
The Python Generator should now have a new tab in its AM interface, with a single
Set to default checkbox. Whenever you toggle this checkbox, the code will be run, and will set the display color of all of your objects. When it is checked, they will be set to use default values; when un-checked, they will be set to use the Object ID colors specified in your Maxwell Object Properties tags. If you un-check the Python Generator's
Optimize Cache parameter, this code will be run whenever the document is calculated, meaning that it will run constantly, so if you add/remove/move/change an Object Properties tag, the document will update. That is pretty expensive, though, so you probably want to keep that checked, and use the Python Generator's
Force Update button to update things when you move or change Object Properties tags.
There would be other ways to use it as well, for example, by putting it into two toolbar buttons -- rather than checking for the existence of the Python Generator and its UserData, one button would call the
display_color_to_objid(obj) function, and the other
display_color_to_default(obj).