InsertRenderData and a while statement
On 02/02/2016 at 07:00, xxxxxxxx wrote:
I'm trying to pull render data from a template file and insert it into the active document. I can do it one line at a time using
rD = templateFile.GetFirstRenderData()
rD1 = rD.GetNext()
"templateFile" is a file that the user loads and the script then loads the document to pull the render data.
Then I InsertRenderData(rD) into the active document. It all works if I do line by line but a "while" statement would be best for this as I don't know how many id's of Render Settings I'm pulling from the template.
When I put it into a "while" loop it crashes. It seems to pull the first ID but then it gets stuck in the active document and stops pulling from the loaded file, it will just pull the settings from the active document. I know I'm missing something but I just can't find it on google. Any help would be great! Maybe there is a better way!
On 03/02/2016 at 13:15, xxxxxxxx wrote:
welcome to the Plugin Café forums
A while loop should be no problem here. Can you post your entire while loop, so can have a look.
On 08/02/2016 at 07:20, xxxxxxxx wrote:
Thanks for the kind welcome!
Sorry for the slow response. I'm on a locked down machine in production. I'll recreate what I have the best I can, very abbreviated:
import c4d, os
from c4d import gui, documents
import c4d.documents as cdoc #the c stands for current, easier for me to see
#I select the file through the load dialog
selectedFile = c4d.storage(LoadDialog....
#Then I load that file (not sure if that's needed??)
loadTemplate = c4d.documents.LoadDocument(selectedFile, loadflags=c4d.SCENEFILTER_0,)
tRD = loadTemplate.GetFirstRenderData()
#so this is where I would put the loop if it didn't crash, something like this:
tRD = tRD.GetNext()
That's pretty much the jist of it. It will pick up the first setting but then loop in the current document and to infinity. Maybe my structure is incorrect for this type of thing. Still learning :).
On 08/02/2016 at 07:59, xxxxxxxx wrote:
Try to call tRD.Remove() before activeDoc.InsertRenderData()
On 08/02/2016 at 08:02, xxxxxxxx wrote:
Or use a clone. What Niklas means, any GeListNode derived entity is only allowed to reside in one list/tree.
On 08/02/2016 at 09:48, xxxxxxxx wrote:
Niklas: Calling tRD.Remove() before activeDoc.InsertRenderData(tRD) still puts it into a infinite loop. I might be doing it wrong?
Andreas: I saw the clone stuff in the documentation but I'm not sure how to really use it. I'll look more into that. I would like this to be compatible as far back as R15 if possible and I think the clone is a new feature in r17? I might be wrong but thanks for pointing me that way.
On 08/02/2016 at 10:50, xxxxxxxx wrote:
Ah yes, you should either be cloning it or getting the next object before calling Remove(), otherwise it won't work of course (tRD.GetNext() will return None after you called Remove())
Are you sure the infinite loop is the while loop in your code? It could be somewhere else, eg. resulting
from an invalid insertion of a node in the tree (as it happened without calling Remove()). I'll try to replicate
your example when I have time tomorrow.
On 08/02/2016 at 10:56, xxxxxxxx wrote:
Yeah, clone seems the best way. As for the infinite loop, my code is basically what I wrote here. It does the one thing and that's all. When I swap out the loop for doing it by hand:
tRD1 = tRD.GetNext(tRD)
for each one I have, it works without crashes or errors. Tedious but works for now, in production.
Thanks for all the help! Really appreciate it. I'll investigate the clone, maybe tonight if I get some time.
On 08/02/2016 at 23:17, xxxxxxxx wrote:
So this works for me without problems:
import os import c4d def main() : fname = c4d.storage.LoadDialog() if not fname: return temp = c4d.documents.LoadDocument(fname, loadflags = c4d.SCENEFILTER_0) if not temp: c4d.gui.MessageDialog("scene file could not be loaded.") return doc.StartUndo() trd = temp.GetFirstRenderData() while trd: next_trd = trd.GetNext() trd.Remove() doc.InsertRenderData(trd) doc.AddUndo(c4d.UNDOTYPE_NEW, trd) trd = next_trd doc.EndUndo() c4d.EventAdd() if __name__ == '__main__': main()
On 09/02/2016 at 07:23, xxxxxxxx wrote:
Amazing, works perfectly! Thanks so much!!!