RDATA_SAVEIMAGE doesn't save image



  • On 10/04/2013 at 08:23, xxxxxxxx wrote:

    Hello there!

    I want to render several pictures where the objects in the scene get different materials. After rendering the rendered images should be automatically saved. But with my code C4D doesn't save the images at all.

    Here's the interesting part of my code:

      
    def Execute(self, doc) :  
          WTO = WalkThroughObjects(doc)    #helps me to handle objects  
            
          rdata = doc.GetActiveRenderData()  
          renderData = rdata.GetClone(c4d.COPYFLAGS_NO_HIERARCHY)  
          renderData[c4d.RDATA_XRES] = 1280  
          renderData[c4d.RDATA_YRES] = 1024  
          renderData[c4d.RDATA_SAVEIMAGE] = True  
          renderData[c4d.RDATA_FORMAT] = c4d.FILTER_PNG  
          renderData[c4d.RDATA_FORMATDEPTH] = c4d.RDATA_FORMATDEPTH_16  
          renderData[c4d.RDATA_FRAMESEQUENCE] = c4d.RDATA_FRAMESEQUENCE_CURRENTFRAME  
            
          matList = doc.GetMaterials()  
          for mat in matList:  
              self.removeAllTags(doc, WTO)  
              self.setObjectsMaterials(doc, WTO, mat)  
              rPath = 'Rendering_{0}.png'.format(mat.GetName())  
              renderData[c4d.RDATA_PATH] = rPath  
              print rPath              
                
              renderBmp = c4d.bitmaps.BaseBitmap()  
              renderBmp.Init(x=renderData[c4d.RDATA_XRES], y=renderData[c4d.RDATA_YRES], depth=32)  
              documents.RenderDocument(doc, renderData.GetData(), renderBmp, c4d.RENDERFLAGS_EXTERNAL)  
              c4d.bitmaps.ShowBitmap(renderBmp)  
              print 'Material rendered: ', mat.GetName()  
    

    The help of C4d states

    Geben Sie statt eines Pfades nur einen Namen ein, werden berechnete Bilder oder Animationen im selben Verzeichnis abgelegt, in dem sich auch die Szene befindet.
    Translated: If there is only a name not a path given, rendered pictures or animations will be saved in the same folder as the scene.

    So what do I miss? From my sight of view there is nothing wrong. Any help would be appreciated :)



  • On 10/04/2013 at 08:39, xxxxxxxx wrote:

    You better save it on your own. :) I also couldn't figure out how to actually do it. That it works in one
    case but not the other is rather odd, see:  https://plugincafe.maxon.net/topic/7028/7936_changing-renderpath-problem&KW=RDATA_SAVEIMAGE&PID=32941#32941
    ~~
    ~~
    I wouldn't rely on this fact.

    Ok wait. I can currently make it save correctly (still confused why it didn't work back then), but I think
    in your case it is the problem that you haven't read the documentation well enough. 😉
    The document will not be render when the bitmap resolution is not equal to the resolution in the
    render-data. The X and YRES in the render-data could be a floating-point number which is rounded
    by the renderer. You also have to round it:

    _<_dt id="c4d.s.render" style=": rgb251, 234, 174;"_>_c4d.documents.RenderDocument( docrdatabmp [,  renderflags=0th=None ])[](file:///C:/Users/niklas/Documents/Documentations/Cinema%204D/R14/Python/help/modules/c4d.documents/index.html?highlight=renderdoc#c4d.documents.RenderDocument)

    Renders the document to a bitmap. You need to initialize the image with the size of the render data:

    import c4d
    from c4d import bitmaps, documents
    
    doc = documents.GetActiveDocument()
    rd = doc.GetActiveRenderData().GetData()
    xres = int(round(rd[c4d.RDATA_XRES]))
    yres = int(round(rd[c4d.RDATA_YRES]))
    
    bmp = bitmaps.BaseBitmap()
    #Initialize the bitmap with the result size
    #The resolution must match with the output size of the render settings
    bmp.Init(x=xres, y=yres, depth=32)
    
    res = documents.RenderDocument(doc, rd, bmp, c4d.RENDERFLAGS_EXTERNAL)
    if res==c4d.RENDERRESULT_OK:
        bitmaps.ShowBitmap(bmp)
    

    Best,
    -Niklas



  • On 10/04/2013 at 09:03, xxxxxxxx wrote:

    Thanks for your answer!
    I changed

    renderBmp.Init(x=renderData[c4d.RDATA_XRES], y=renderData[c4d.RDATA_YRES], depth=32)
    

    to

    renderBmp.Init(x=int(round(renderData[c4d.RDATA_XRES])), y=int(round(renderData[c4d.RDATA_YRES])), depth=32)
    

    The result is the same, still no saving. I'll try your answer you crossed out.



  • On 10/04/2013 at 10:25, xxxxxxxx wrote:

    c4d does not round the resolution, but takes the floor of it. 512.79 px will be rendered at 512 px,
    just as 512.0 px, so int(myfloat) should be sufficient. for your saving problem - i am a bit confused. 
    there is no saving logic in your code. you render the image to a bitmap and then you do nothing 
    with the bitmap.

    edit : read basebitmap.save()



  • On 10/04/2013 at 11:12, xxxxxxxx wrote:

    @littledevil: Interesting, I've never checked it before because it is clearly stated in the docs that
    we should round the x and y resolution. So the documentation is mistaken, I think. Thanks for
    pointing it out!

    The render-data contains the information about saving the scene, check out this script: http://bit.ly/XDswcG
    It works for me, the scene renders and the image is output.

    -Niklas



  • On 10/04/2013 at 11:52, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    The render-data contains the information about saving the scene, check out this script: http://bit.ly/XDswcG It works for me, the scene renders and the image is output.
    -Niklas

    sure it does work, because you feed the render path to save() result = bmp.Save(..). 
    the op does not do something like that. therefore his bitmap is not being saved. or am i
    overlooking something here ?

    edit : i do not like clicking packed/shortened url links :(



  • On 10/04/2013 at 14:36, xxxxxxxx wrote:

    @littledevil: Lol, you're right. I had it in mind differently and didn't even check .. *shame*
    Why don't you? I don't like extremely long urls which is why I have shortened it. The onboard
    tool for creating a hyperlink is bad and I was too lazy using bbcode. ^^



  • On 10/04/2013 at 15:01, xxxxxxxx wrote:

    i want to decide if i really want to visit http:\\haxxor.ruforum.vu.lulz?&fskdfhkasbfkshdfks-dasfkhksd.php;?#=234682?sdafgj. packed links make that impossible.



  • On 10/04/2013 at 22:46, xxxxxxxx wrote:

    http:\\haxxor.ruforum.vu.lulz

    I like that! 😂

    i am a bit confused. 
    there is no saving logic in your code

    Now it's on me to be confused. You tell me, that I have to save the bitmap myself? So renderData[c4d.RDATA_SAVEIMAGE] = True simply does have no function at all? So why is it there then? Why isn't this (not really given) functionality not stated in the documentation? It's frustrating -.-
    Thanks for all your answers, I'll go saving manually now...

    €: looked up save() and tried to implement it. Needless to say that it doesn't work on the first try. The docu is great. I mean " data (BaseContainer) – The data." really clearly states what to put as the parameter...



  • On 11/04/2013 at 00:44, xxxxxxxx wrote:

    data is an optional parameter, look at nikklas russian porn forum example link, you 
    just need to specify the format and the path. about the RDATA_SAVEIMAGE flag : you 
    have to keep in mind that the renderdata container is there to feed the native c4d render 
    command, so this option is simply ignored by this method, because there are some cases 
    where you want to render the scene and do NOT want to (over)write the output image.
    RDATA_SAVEIMAGE is simply the little checkbox in the save menu of your rendersettings.


Log in to reply