Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    changing Renderpath problem

    PYTHON Development
    0
    22
    12.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 14/03/2013 at 06:00, xxxxxxxx wrote:

      You're right, I missed that. Hm.. Did you ensure that the 'Save' checkmark is set in the render-data?

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 14/03/2013 at 06:04, xxxxxxxx wrote:

        Do you mean manually as in opening the render settings and checking the boxes? if so, yes, and also, if i don't try to tamper with the path in the plugin it renders just fine.

        If you mean checking the save-checkbox in pyhton, then no

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 14/03/2013 at 06:08, xxxxxxxx wrote:

          Also, i just noticed, that the images thet appear in the picture viewer have neither a name or a directory lited under Info

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 14/03/2013 at 06:45, xxxxxxxx wrote:

            you could try a raw string, python might get confused with the path seperators

            renderData[c4d.RDATA_PATH] = r'{0}\_{1}'.format(renderData[c4d.RDATA_PATH], layerName)
            
            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 14/03/2013 at 07:40, xxxxxxxx wrote:

              I found the solution:

              I needed to move the .GetData() to .renderDocument(...), updated code:

                
                def renderDocument(self, layerName) :  
                    """  
                    Taking the document and rendering it according to the normal rendersettings of the document.  
                    Ads '_LAYERNAME', LAYERNAME being the name of the layer, to the renderpath.  
                    """  
                    doc = c4d.documents.GetActiveDocument()  
                    renderData = doc.GetActiveRenderData()  
                    xResolution = int(round(renderData[c4d.RDATA_XRES]))  
                    yResolution = int(round(renderData[c4d.RDATA_YRES]))  
                
                    if renderData[c4d.RDATA_PATH] != "":  
                        storedPath = renderData[c4d.RDATA_PATH]  
                        print renderData[c4d.RDATA_PATH]  
                        renderData[c4d.RDATA_PATH] =r'{0}_{1}'.format(renderData[c4d.RDATA_PATH], layerName)  
                        print renderData[c4d.RDATA_PATH]  
                        c4d.EventAdd()  
                
                    renderBmp = c4d.bitmaps.BaseBitmap()  
                    renderBmp.Init(x=xResolution, y=yResolution, depth=32, )  
                
                    result = documents.RenderDocument(doc, renderData.GetData(), renderBmp, c4d.RENDERFLAGS_EXTERNAL)  
                    renderData[c4d.RDATA_PATH] = storedPath  
                    if result==c4d.RENDERRESULT_OK:  
                        c4d.bitmaps.ShowBitmap(renderBmp)     # show image in pictureViewer  
                    return True  
              

              I kept littledevils notation for combining strings though 😉 find it very neat XD

              Thanks for your help both of you!

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 14/03/2013 at 07:59, xxxxxxxx wrote:

                are you sure ? i don't think using the gelistnode as an interface instead of a bc
                does make so much difference, but who knows, c4d tends to be akward ;).  and 
                just for clarification, my example is more than a different notation.

                this won't work as a path string in python
                'c:\somefolder\somefile.dat'

                but these will (the little prefix r is a raw string)
                'c:\\somefolder\\somefile.dat'
                r'c:\somefolder\somefile.dat'

                http://docs.python.org/2/reference/lexical_analysis.html#literals

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 14/03/2013 at 08:06, xxxxxxxx wrote:

                  @Ferdinand: No, this is applies to string-literals only. A string that does already exist will not be
                  processed for backslash-escaping again. So the string doesn't care if there is a \n or \r or any
                  escape sequence when concatenating, just when being parsed by the Python parser. It is an
                  annotation to the coder, not a runtime thingy.

                  ref = r'Hello \nobody'
                  string_a = ref + ', how are you?'
                  string_b = '%s%s' % (ref, ', how are you?')
                  string_c = '{0}{1}'.format(ref, ', how are you?')
                    
                  assert string_a == string_b == string_c
                  

                  @Amadeo: I agree with Ferdinand, it doesn't look like there should be a semantical difference
                  in the code. Are you sure you didn't change anything else?

                  Best,
                  Niklas

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 14/03/2013 at 08:22, xxxxxxxx wrote:

                    [OK] rd = doc.GetActiveRenderData()
                    [OK] print rd[[c4d.RDATA_PATH]]
                    c:\nline\nline
                    [OK] rd[[c4d.RDATA_PATH]] + 'abc'
                    'c:\\nline\\nlineabc'
                    

                    c4d won't accept this path. so you have to force your ouput into raw again not
                    sure if string.format does this by default.

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      On 14/03/2013 at 08:26, xxxxxxxx wrote:

                      I don't see why it won't accept this path. Looks valid to me.

                      Btw, are the doubled brackets intended?

                      [OK] print rd **[[** c4d.RDATA_PATH **]]** 
                      
                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        On 14/03/2013 at 08:35, xxxxxxxx wrote:

                        for brackets i don't know, haven't really seen them the console font is so tiny. the snippet is
                        directly from the console, c4d put them there. for accepting the path - does c4d accept double 
                        backlashes instead of single ones ? after __add__ the raw string is transformed into the 
                        escaped form and rdata[pathblah] actually contains the double backlashes.

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          On 14/03/2013 at 08:40, xxxxxxxx wrote:

                          There are no double backslashes in the string. There are double-backslashes in the output because
                          you didn't print the string. See Python's __repr__.

                          Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
                          Type "help", "copyright", "credits" or "license" for more information.
                          \>>> str = 'C:\\nobody\\noway'
                          \>>> str
                          'C:\\nobody\\noway'
                          \>>> print str
                          C:\nobody\noway
                          \>>> str + '\\notime'
                          'C:\\nobody\\noway\\notime'
                          \>>> print str + '\\notime'
                          C:\nobody\noway\notime
                          
                          1 Reply Last reply Reply Quote 0
                          • H
                            Helper
                            last edited by

                            On 14/03/2013 at 09:55, xxxxxxxx wrote:

                            ah ok, i didn't think of that, i stand corrected 😉

                            1 Reply Last reply Reply Quote 0
                            • H
                              Helper
                              last edited by

                              On 14/03/2013 at 09:56, xxxxxxxx wrote:

                              Hey Guys,

                              I checked again:

                              if i change

                              doc.GetActiveRenderData()

                              back to

                              doc.GetActiveRenderData().GetData()

                              and

                              documents.RenderDocument(doc, renderData.GetData(), renderBmp, c4d.RENDERFLAGS_EXTERNAL)

                              to

                              documents.RenderDocument(doc, renderData, renderBmp, c4d.RENDERFLAGS_EXTERNAL)

                              Thers no file output to disk anymore, just pictureviewer

                              Is that weird?

                              1 Reply Last reply Reply Quote 0
                              • H
                                Helper
                                last edited by

                                On 14/03/2013 at 10:00, xxxxxxxx wrote:

                                It is indeed. Could you provide an SSCCE?

                                -Nik

                                1 Reply Last reply Reply Quote 0
                                • H
                                  Helper
                                  last edited by

                                  On 14/03/2013 at 10:12, xxxxxxxx wrote:

                                  I read your link, but i'm not too sure what that's supposed to be ^^sorry

                                  would it not be an option to simply send you the code? or the plugin? because i don't think it can be trimmed to far and i don't know how to make it work without all the parts. Does that even make sense?^^

                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    Helper
                                    last edited by

                                    On 14/03/2013 at 10:17, xxxxxxxx wrote:

                                    SSCCE = Short Self Contained Correct Example

                                    => Just paste some code that shows the problem and can be run right in the script
                                    manager or in a Python plugin-file. 😉

                                    You can also send it via PM if you don't want to make it public.

                                    Best,
                                    -Niklas

                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      Helper
                                      last edited by

                                      On 14/03/2013 at 10:28, xxxxxxxx wrote:

                                      I'll get back to you tomorrow, is that ok?

                                      Thanks a lot,

                                      Aurel

                                      1 Reply Last reply Reply Quote 0
                                      • H
                                        Helper
                                        last edited by

                                        On 15/03/2013 at 01:15, xxxxxxxx wrote:

                                        Hey NiklasR,

                                        Here is what i belive to be a SSCCE:

                                          
                                          
                                        import c4d  
                                        from c4d import gui, plugins, documents  
                                        import os  
                                          
                                        if __name__=='__main__':  
                                              doc = c4d.documents.GetActiveDocument()  
                                              renderData = doc.GetActiveRenderData()  
                                              xResolution = int(round(renderData[c4d.RDATA_XRES]))  
                                              yResolution = int(round(renderData[c4d.RDATA_YRES]))  
                                              pathChange = False  
                                          
                                              if renderData[c4d.RDATA_PATH] != "":  
                                                  storedPath = renderData[c4d.RDATA_PATH]  
                                                  renderData[c4d.RDATA_PATH] =r'{0}_{1}'.format(renderData[c4d.RDATA_PATH], "extension")  
                                                  c4d.EventAdd()  
                                                  pathChange = True  
                                          
                                              renderBmp = c4d.bitmaps.BaseBitmap()  
                                              renderBmp.Init(x=xResolution, y=yResolution, depth=32, )  
                                          
                                              result = documents.RenderDocument(doc, renderData.GetData(), renderBmp, c4d.RENDERFLAGS_EXTERNAL)  
                                              if pathChange == True:  
                                                  renderData[c4d.RDATA_PATH] = storedPath  
                                              if result==c4d.RENDERRESULT_OK:  
                                                  c4d.bitmaps.ShowBitmap(renderBmp)     # show image in pictureViewer  
                                          
                                        

                                        Just create a new scene, save the renderoutput in some folder. If you run this script, the rendered file will actually be output to the folder. If you move the .GetData() to doc.GetActiveRenderData().GetData() and remove it from renderData.GetData(), theres no more file output.

                                        Aurel

                                        1 Reply Last reply Reply Quote 0
                                        • H
                                          Helper
                                          last edited by

                                          On 15/03/2013 at 06:21, xxxxxxxx wrote:

                                          Hi Amadeo,

                                          yes that is perfect, thanks.

                                          I'm also very confused, I can reproduce the behavior you describe. I don't see what is wrong
                                          in your code, mine works (see below). Anyway, you could still just save the image by hand. The
                                          script below is doing this as well so you will end up with two images when the Save parameter
                                          is checked in the render-data.

                                          import os
                                          import c4d
                                            
                                          def main() :
                                              rdata = doc.GetActiveRenderData().GetData()
                                           **    # rdata[c4d.RDATA_SAVEIMAGE] = False**
                                              xres = int(round(rdata[c4d.RDATA_XRES]))
                                              yres = int(round(rdata[c4d.RDATA_YRES]))
                                            
                                              path = rdata[c4d.RDATA_PATH]
                                              if not path:
                                                  c4d.gui.MessageDialog("no save-path specified")
                                                  return
                                            
                                              dirname = os.path.dirname(path)
                                              if not os.path.exists(dirname) :
                                                  os.makedirs(dirname)
                                              elif not os.path.isdir(dirname) :
                                                  c4d.gui.MessageDialog("destination directory can not be created.")
                                                  return
                                            
                                              path = '%s_extension' % path
                                           **    # rdata[c4d.RDATA_PATH] = path**
                                              fileformat = rdata[c4d.RDATA_FORMAT]
                                            
                                              bmp = c4d.bitmaps.BaseBitmap()
                                              if bmp.Init(xres, yres, 32) != c4d.IMAGERESULT_OK:
                                                  c4d.gui.MessageDialog("could not allocated bitmap for render.")
                                                  return
                                            
                                              result = c4d.documents.RenderDocument(doc, rdata, bmp, c4d.RENDERFLAGS_EXTERNAL)
                                              if result != c4d.RENDERRESULT_OK:
                                                  c4d.gui.MessageDialog("rendering was not successful, see console.")
                                                  print "rendering failed with error-code", result
                                                  return
                                            
                                              result = bmp.Save(path, fileformat)
                                            
                                              if result != c4d.IMAGERESULT_OK:
                                                  c4d.gui.MessageDialog("rendered bitmap could not be saved, see console.")
                                                  print "saving bitmap failed with error-code", result
                                            
                                          main()
                                          

                                          It seems to be the setting of the RDATA_PATH, because when you uncomment the red line,
                                          the RenderDocument() function does not save automatically anymore.

                                          Best,
                                          -Niklas

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post