How to clean the save path if IsEmpty is FALSE



  • On 21/11/2015 at 13:04, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   16 
    Platform:   Windows  ;   
    Language(s) :   C.O.F.F.E.E  ;

    ---------

    Hello guys, I'm not a programmer but I like to try creating small solutions for my day to day.
    I have wrote this script in COFFEE in order to quickly adjust some parameters in Render Settings. It's working fine but I wanted to improve it.

    I wanted to automatically clear the save path if the condition IsEmpty was FALSE.
    The solution I found was a popup requesting to user do it manually.

    Anyone knows how can I do it (clear the save path)?

    Thanks

    Below, the C.O.F.F.E.E. script:

    // Activate Save Image
    if (renderdata()#RDATA_SAVEIMAGE=FALSE)
    return NULL;
    else(renderdata()#RDATA_SAVEIMAGE=TRUE);

    var save_path=renderdata()#RDATA_PATH; // Store the currently save path
    var file_name=doc->GetFilename()->GetLastString(); // Capture the name of c4d project

    if (save_path->IsEmpty())
    {
    save_path->AddLast(file_name); // Add the c4d project name to save path
    save_path->DelSuffix(); // Remove .c4d extension
    renderdata()#RDATA_PATH=save_path; // Load it in the Save field

    // Avoid duplicated name
    //     save_path->RemoveLast();
    //     renderdata()#RDATA_PATH=save_path;

    renderdata()#RDATA_XRES_VIRTUAL=800; // Width
    renderdata()#RDATA_YRES_VIRTUAL=600; // Height
    renderdata()#RDATA_FORMAT=1104; // JPG format
    CallCommand(12099); // Render to Picture Viewer
    }
    else
    {
    CallCommand(12161); // Edit Render Settings...
    TextDialog("Clear the save path!", GEMB_OK);
    }



  • On 21/11/2015 at 13:29, xxxxxxxx wrote:

    Construct a new (and therefore empty) Filename object and assign that:

      
    var f = new(Filename);   
    renderdata()#RDATA_PATH = f;   
    


  • On 21/11/2015 at 14:13, xxxxxxxx wrote:

    Thanks a lot Cairyn!
    It worked...

    My new code:

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

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

    renderdata()#RDATA_PATH = empty;
    save_path=renderdata()#RDATA_PATH;
    save_path->AddLast(file_name);
    save_path->DelSuffix();
    renderdata()#RDATA_PATH=save_path;
    renderdata()#RDATA_XRES_VIRTUAL=800;
    renderdata()#RDATA_YRES_VIRTUAL=600;
    renderdata()#RDATA_FORMAT=1104;
    CallCommand(12099);



  • On 21/11/2015 at 14:54, xxxxxxxx wrote:

    Good that it works for you. Mind if I ask?:

    1. What is this code supposed to mean?

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

    From the formatting, it looks as if you try to put a condition behind the "else". However, it's actually a command that sets the SAVEIMAGE value to TRUE. An "else" does not have a condition.
    In this case it doesn't hurt, because the assignment is just setting the value of SAVEIMAGE to the same it already has (because the "if" has this value in the condition), but it doesn't do anything useful either.

    2. You are doing a lot of assignments that are fairly pointless with the path, first setting the RDATA_PATH to an empty filename, then assigning that to some other variable, then assigning it back to RDATA_PATH...

    The whole code could be shorter:

      
    if (renderdata()#RDATA_SAVEIMAGE=FALSE) return NULL;   
      
    var file_name=doc->GetFilename()->GetLastString();   
    var save_path=new(Filename);   
    save_path->AddLast(file_name);   
    save_path->DelSuffix();   
    renderdata()#RDATA_PATH=save_path;   
    renderdata()#RDATA_XRES_VIRTUAL=800;   
    renderdata()#RDATA_YRES_VIRTUAL=600;   
    renderdata()#RDATA_FORMAT=1104;   
    CallCommand(12099);   
    

    (Disclaimer: I didn't test it but it should be equivalent.)



  • 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;

    Tks



  • 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 :-(

    Thanks



  • 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 :-(
    Thanks

    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;   
    else(renderdata()#RDATA_SAVEIMAGE=TRUE);   
    

    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

      
    renderdata()#RDATA_SAVEIMAGE=TRUE;   
    

    (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);   
    save_path->AddLast(file_name);   
    save_path->DelSuffix();   
    renderdata()#RDATA_SAVEIMAGE=TRUE;   
    renderdata()#RDATA_PATH=save_path;   
    renderdata()#RDATA_XRES_VIRTUAL=800;   
    renderdata()#RDATA_YRES_VIRTUAL=600;   
    renderdata()#RDATA_FORMAT=1104;   
    CallCommand(12099);   
    

    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   
        c4d.EventAdd()   
      
    if __name__=='__main__':   
        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:

    Hello,

    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,
    Sebastian


Log in to reply