On 15/10/2014 at 08:39, xxxxxxxx wrote:
Thanks again for the example code. I notice you are using GetNext() which appears to be undocumented. I expected there would be a get next but when I reviewed the C4D API it is not listed at all.
http://plugincafe.com/python/
I ran your example code on the default document that appears when you open C4D. I expected to see one document name printed because that is all that is loaded when you open the C4D appliocation. However, your code produced 2 print lines ("Untitled 1"). I was curious to see what GetNext() returns so I printed the contents of the doc variable and sure enough it was None.
I altered your code so it was more clear that the while should stop when the doc variable is None , but the loop still seems to run twice when it really should only run once on the blank C4D document.
import c4d
from c4d import documents
def main() :
#Start with the first document
doc = documents.GetFirstDocument()
#Then grab the next ones using a loop
while doc != None:
print (doc.GetDocumentName())
#Search for a specific object here
doc = doc.GetNext()
print(doc)
c4d.EventAdd()
if __name__=='__main__':
main()
I am just trying to get my head around this seeming flaw in execution. Is there some C4D based rule in python that would cause the loop to execute twice?
For instance, I run this code in Blender and it and it prints one value. I run this same code in C4D and I get two values printed..?
def main() :
var = 1
while var != None:
print (var)
var = None
if __name__=='__main__':
main()