How to clean the save path if IsEmpty is FALSE

  • On 21/11/2015 at 17:09, xxxxxxxx wrote:

    Thanks again Cairyn, for your attention.

    Actually I'm Noob in COFFEE, and as I said I'm not a programmer. This code I have builded trying parts of codes, observing another scripts.
    You helped me to understand that logical issue, about the use of the condition "if".

    I have tried your last suggestion, but with no success.
    And then, eliminating that condition, it worked fine, just using renderdata()#RDATA_SAVEIMAGE=TRUE;


  • On 21/11/2015 at 17:41, xxxxxxxx wrote:

    The only problem with your 'if' statement is that in order to test you use == and not =, so:

    if (renderdata()#RDATA_SAVEIMAGE==FALSE) return NULL;

    That should also avoid the inevitable problem when you realize that the renders aren't being saved or ALWAYS being saved with your non-conditional setting. :)

  • On 21/11/2015 at 17:50, xxxxxxxx wrote:

    For more information about the comparison options, in the COFFEE documentation, go to Tutorials->The C.O.F.F.E.E. Primer->C.O.F.F.E.E. Flow Control

  • On 21/11/2015 at 17:50, xxxxxxxx wrote:

    If I use ==FALSE, nothing happens when the save are disabled :-(


  • On 21/11/2015 at 17:51, xxxxxxxx wrote:

    Thank you Robert!

  • On 22/11/2015 at 02:33, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    The only problem with your 'if' statement is that in order to test you use == and not =

    Oops, I completely overlooked that! Teaches me to answer forum questions at midnight ;-)

  • On 22/11/2015 at 03:36, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    If I use ==FALSE, nothing happens when the save are disabled :-(

    Wasn't that intended? RDATA_SAVEIMAGE represents the checkbox inside of the "Save" tab. If it is unchecked, then you cannot enter a string into the "File..." field because it is also disabled, and an assignment to the RDATA_PATH doesn't work.

    I thought you wanted to have exactly that behavior because you had that "if" condition at the beginning.

    What you actually got with your code was the behavior "set the Save checkbox to TRUE every time" because of the "=="/"=" confusion in the original code. Let me explain:

    if (renderdata()#RDATA_SAVEIMAGE=FALSE)   
    return NULL;   

    What does this do? "renderdata()#RDATA_SAVEIMAGE=FALSE" is an assignment that sets the "Save" flag to FALSE. It is not a check whether the flag is currently FALSE (as Robert rightfully said, that would be "renderdata()#RDATA_SAVEIMAGE==FALSE"), but a brutal overwrite.

    Assignments however also return a value (the assigned value) at the same time, which is the only reason why you can syntactically write an assignment into an "if" condition (and earn the curses of a million desperate students of C, C++, and COFFEE...).

    So practically the "if" condition gets a constant (the FALSE which you assign), and NEVER executes the "return NULL" part. It always jumps into the "else" part.

    The "else" part has again an assignment, to the same variable: "renderdata()#RDATA_SAVEIMAGE=TRUE". This sets your flag to TRUE (checks the checkbox), so now you always have the "Save" enabled and can overwrite the "File..." string.

    The code snippet above essentially compresses to


    (and I really should have caught that the first time ;-) )

    and the full function is

    var file_name=doc->GetFilename()->GetLastString();   
    var save_path=new(Filename);   

    No "if", no "else".

    You still need to have the "Save" generally enabled (different checkbox in the Renderer pane) or else your "Save" setting in the Save pane and the filename will not be written.

    Sadly I have no idea how to access that checkbox, so question to support would be: What is the correct way to set the checkboxes "Save", "Multi-Pass", "Stereoscopic", and "Material Override" in the RENDERSETTING_STATICTAB? Can't find that for C++ or Python either...

  • On 22/11/2015 at 06:56, xxxxxxxx wrote:

    Yes, you are right, what I wanted was just always keep Save on.
    I used the condition "if" and "else" by a lack of knowledge.

    I appreciate your class, I'm still learning and it motivates me.

    I have read in another post about the Save you mentioned. Another user told that all those options in the left column of Render Settings are not accessible by COFFEE, just by Python or C++.

    But for the purpose that I thought, the code that you helped me to fix is perfect for now. I have 50 folders each one with a .c4d and tex and different settings, whose I want to build an index with thumbnails.

    Would be better if I had the control over the left column, so I could disable any effects, like Global Illumination, before to rendering.

    Thanks a lot!
    Have a good day.

    PS. I'm sorry for my english, it's not my default language ;-)

  • On 22/11/2015 at 09:15, xxxxxxxx wrote:

    Ah, now I found them. The four IDs I missed are actually part of the RDATA_ enumeration type, and accessible through Python:

    renderdata[c4d.RDATA_GLOBALSAVE] = True   
    renderdata[c4d.RDATA_STEREO] = True   
    renderdata[c4d.RDATA_MATERIAL_OVERRIDE] = True   
    renderdata[c4d.RDATA_MULTIPASS_ENABLE] = True   

    They were a bit hard to identify since they are just listed with all the other RDATA_ ids. I seem to have looked into a different enumeration at first too ;-)

    Anyway, if you would use Python instead of COFFEE, your script would look like this, including the leftmost "Save" checkbox:

    import c4d   
    from c4d import gui   
    def main() :   
        file_name = doc.GetDocumentName()   
        renderdata = doc.GetActiveRenderData()   
        posLastDot = file_name.rfind(".")   
        if posLastDot <> -1:   
            file_name = file_name[:posLastDot]   
        renderdata[c4d.RDATA_GLOBALSAVE] = True   
        renderdata[c4d.RDATA_SAVEIMAGE] = True   
        renderdata[c4d.RDATA_PATH] = file_name   
        renderdata[c4d.RDATA_XRES_VIRTUAL] = 800   
        renderdata[c4d.RDATA_YRES_VIRTUAL] = 600   
        renderdata[c4d.RDATA_FORMAT] = 1104   
    if __name__=='__main__':   

    If you are just starting with programming, I would actually recommend using Python in the first place. COFFEE seems to be a bit behind the times, and I would not really be surprised if Maxon declares it "legacy" one day.

  • On 22/11/2015 at 14:18, xxxxxxxx wrote:

    woow thanks!

    Nice work!

  • On 23/11/2015 at 01:32, xxxxxxxx wrote:


    if you are starting to learn a script language for Cinema 4D you might want to focus on Python since the Python API covers more areas of Cinema 4D and offers more functionality.

    Best wishes,

Log in to reply