By JDHill
#361191
I'm not sure if I can do that, but I'll take a look.
User avatar
By jc4d
#361212
What about just linking the display color of the object with Object ID color and just a switch to enable and disable this color, because when a texture is applied to that object this goes "invisible" when use color is on. I guess no need for anything fashion :)
Here is a rudimentary xpresso example:
Image

Cheers
JC
By JDHill
#361239
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 all
import 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:
  1. create a Python Generator object.
  2. Set its Optimize Cache to checked.
  3. set its Reset on Frame 0 to un-checked.
  4. copy the above code into its Code area.
  5. add a UserData to it (in the AM UserData menu).
  6. 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).
User avatar
By jc4d
#361252
dariolanza wrote:Nice workaround ; )
Thanks :)

@JDHill
Wow thank you.
Yes you are right my solution is only per object and in the long run=big projects is not pratical and even to use it on old projects but your solution is per document or global which make it practical.

Now I´m in my fear zone, for me the coding and those things are like the boogie man for me :oops:, but it works even in a big project that I´m working right now, the only thing is if an object has a texture applied the ID color doesn´t show, so I tried "in my own prehistoric way" to change the value of if obj and obj.GetType() == 1023866 and obj[c4d.ID_USERDATA,1]: to 2 and 0 the USERDATA value to see if I can get the texture back in the viewport but no luck here, the good thing about this script is that this respect the hierarchy and even exclude a child object with another color that the parent one.

I made another rudimentary attempt in xpresso where if checkbox is un-checked the texture that is applied to the object is visible again.
Is there a way to translate this xpresso thingy to your script JDHill? (sorry maybe I´m to naive and this can´t be done)

Here is the file in R14: http://dropcanvas.com/ezrpg

Cheers,
Juan
By JDHill
#361264
You were on the right track, but the change you want to make is in this line:
Code: Select all
 t_mode = 1; # this is Automatic mode
Just change this from 1 to 2, to use the "On" mode, rather than the "Automatic" one, similar to what you are doing in your xpresso tag.
Help with swimming pool water

Hi Andreas " I would say the above "fake[…]

render engines and Maxwell

Other rendering engines are evolving day by day, m[…]