changing Renderpath problem

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

Hello everyone,

I'm working on a plugin written in python, and theres one thing i can't fix. I try to change the Renderpath from render to render, and i think it works, but for some reason it doesn't save the rendered image after the change in the path. No file output to anywhere. Here is the 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().GetData()  
      xResolution = int(round(renderData[c4d.RDATA_XRES]))  
      yResolution = int(round(renderData[c4d.RDATA_YRES]))  
  
      if renderData[c4d.RDATA_PATH] != "":  
          print str(renderData[c4d.RDATA_PATH])  
          renderData[c4d.RDATA_PATH] = str(renderData[c4d.RDATA_PATH]) + "_" + str(layerName)  
          print str(renderData[c4d.RDATA_PATH])  
          c4d.EventAdd()  
            
      renderBmp = c4d.bitmaps.BaseBitmap()  
      renderBmp.Init(x=xResolution, y=yResolution, depth=32, )  
  
      result = documents.RenderDocument(doc, renderData, renderBmp, c4d.RENDERFLAGS_EXTERNAL)  
  
      if result==c4d.RENDERRESULT_OK:  
          c4d.bitmaps.ShowBitmap(renderBmp)     # show image in pictureViewer  
      return True  

If I comment the red section out (the path change) it renders fine. Also, the renderpath seems to change correctly between the two print statements. Furthermore, i checked things like RDATA_SAVEIMAGE, RDATA_GLOBALSAVE, and they are both set to one (hence true?) all the time.

Thanks for your help

Aurel

On 14/03/2013 at 05:30, xxxxxxxx wrote:

Use either GetDataInstance() or set the data container back via SetData(). The GetData() method
returns a copy of the original container. This information can be found in the documentation, so
read well before using a method.

Best,
Niklas

On 14/03/2013 at 05:57, xxxxxxxx wrote:

Hey NiklasR,

I see what you mean, but since i actually render the document by passing in renderData, doesn't it take the changed parameters into account anyway? -because if i use GetDataInstance(), it still doesn't actally save the images. However, the paths change, because they always concatenate the previous path with the name of the layer:

/Users/pixcube03/Desktop/RenderTestPlugin/test  -> in the beginning
/Users/pixcube03/Desktop/RenderTestPlugin/test_Layer1 ->after first render
/Users/pixcube03/Desktop/RenderTestPlugin/test_Layer1_Layer2 -> after second Render...

instead of:

/Users/pixcube03/Desktop/RenderTestPlugin/test_Layer2

So that's not what i was looking for.

All images definitly get rendered, they appear in the pictureviewer, they just aren't being saved to disk.

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?

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

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

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)

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!

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

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

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.

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 **]]** 

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.

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

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

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

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?

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

It is indeed. Could you provide an SSCCE?

-Nik

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?^^

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

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

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

Thanks a lot,

Aurel