Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    'GENERATOR_FLAG' not updating with frame advance

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 287 Views
    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 Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 23/07/2012 at 10:08, xxxxxxxx wrote:

      Hi all,

      I'm missing something to allow Python to register a scene change when I tell it to advance a frame with a call command (c4d.CallCommand(12414)).  I am trying to find out when an object is 'Enabled' on a frame and then render that frame and saving the image with that object name.  All is doing well, but when the frame advances, Python doesn't seem to register the changes in 'Enabled' states, which are animated on and off, frame to frame.  I also wanted to capture which camera is active on a particular frame as well and run into the same problem of Python not picking up the updated frame state.  All attempts to update Cinema per frame have failed so far.  What do I do?

      Also, while I'm asking questions, is there a better way to check to pause and see if the render is still rendering (I'm using c4d.CheckIsRunning), or is this the best way?

      -Disclaimer: I'm new to programming, so the following code is rough, slow and could probably be broken up into functions, but that will come later when I am more comfortable with the language.

      import c4d, math, string
      from c4d import gui, utils
        
      #Reverses order of render list, renames list items to be legal, and then renders with new names.
        
      def main() :
        
          c4d.CallCommand(12112) #Select All
          c4d.CallCommand(100004748); #Unfold All
          c4d.CallCommand(100004766) #Select all
          Selected = doc.GetActiveObjects(1)
          myDoc = c4d.documents.GetActiveDocument()
        
          c4d.CallCommand(12501) #Goto Start Frame
          startFrame = 0
          hasRendered = 0
          curFrame = doc.GetTime().GetFrame(doc.GetFps())
          bc = c4d.BaseContainer() 
          shiftMod = 0  
          theFrame = 0 
          while theFrame < 99:
              curFrame = doc.GetTime().GetFrame(doc.GetFps())
              print "*****************************************"
              print "     THE CURRENT FRAME IS : " + str(curFrame)  
              print "*****************************************"     
              for ListOb in Selected:
                  curFrame = doc.GetTime().GetFrame(doc.GetFps())
                  theType = ListOb.GetTypeName()
                  xName = ListOb.GetName() #return the name of an object
                  print "The object type is: " + theType
                  if ListOb[c4d.ID_BASEOBJECT_GENERATOR_FLAG] == 0:
                      print xName + " is turned OFF"
                  if ListOb[c4d.ID_BASEOBJECT_GENERATOR_FLAG] == 1:
                      print xName + " is turned ON"    
                  if theType != "XRef" or ListOb[c4d.ID_BASEOBJECT_GENERATOR_FLAG] != 1:
                      print "This is not an xref OR it is not turned on."                      
                  if theType == "XRef" and ListOb[c4d.ID_BASEOBJECT_GENERATOR_FLAG] == 1:            
                      xName = ListOb.GetName() #return the name of an object 
                      xName = xName[5:] + "_"
                      if xName[-4:] == ".c4d":
                          xName = xName[:-4]
                      xName = string.replace(xName, "/", "_")
                      xName = string.replace(xName, "(", "--")
                      xName = string.replace(xName, ")", "--")
                      xName = string.replace(xName, ".", "_")
                      xName = string.replace(xName, ",", "_")
                      print "--------------------------------------------------------"
                      print xName + "will render on this frame => " + str(curFrame)
                      print "--------------------------------------------------------"
                      path = "Users/david.cox/Desktop/testFolder/Accessory_catalog_Scene/"
                      rd = doc.GetActiveRenderData()
                      #path = rd[c4d.RDATA_PATH]
                      rd[c4d.RDATA_FRAMEFROM] = (c4d.BaseTime(startFrame + 1,30))
                      rd[c4d.RDATA_FRAMESEQUENCE] = (c4d.RDATA_FRAMESEQUENCE_CURRENTFRAME)
                      rd[c4d.RDATA_PATH] = path + xName
                      if hasRendered == 0:
                          c4d.CallCommand (12099) #calls the renderer
                      hasRendered = 1
                      isRend = c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING)
                      while isRend == 1:
                          isRend = c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING)
                          hasRendered = 0
              
                          if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.BFM_INPUT_CHANNEL,bc) :        
                              if bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QSHIFT:
                                  shiftMod=1
                                  print "Breaking out of loop"
                                  break
                          if shiftMod==1:
                              break
                      #if hasRendered == 0:
                      if shiftMod==1:
                          break
              c4d.CallCommand(12414) #Advance a frame
              theFrame += 1
              
          c4d.CallCommand(12501) #Goto Start Frame
          c4d.EventAdd()
                  
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 24/07/2012 at 16:00, xxxxxxxx wrote:

        Although the code is more convoluted, I finally got it to work with GetGeData() to tell me if the object is in the "Enabled" state at the current frame.  This is more messy than it should be because of the run around that I (had to?) took to find out the state of a key on a particular frame.

        I'm still looking for a better way to run this without Cinema being in a "beachball" state (the cursor display when a Mac program is not responding) till the render completes because of my 'while' loop: c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING) to constantly check if the current frame is completed.  Is there a way for Python to pause cranking away till a 'end of frame' mark is reached and then continue?

        Anyways, here is my amateur code so far that is working for me:

        import c4d, math, string
        from c4d import gui, utils
          
        #Looks for enabled xref's on a frame, renames list items to be legal, and then renders with xref names.
          
        def main() :
          
            c4d.CallCommand(12112) #Select All
            c4d.CallCommand(100004748); #Unfold All
            c4d.CallCommand(100004766) #Select all
            Selected = doc.GetActiveObjects(1)
            myDoc = c4d.documents.GetActiveDocument()
          
            #c4d.CallCommand(12501) #Goto Start Frame
            #startFrame = 0
            startFrame = int(c4d.gui.InputDialog("Enter the Start Frame"))
            doc.SetTime(c4d.BaseTime(startFrame,30))
            bc = c4d.BaseContainer() 
            shiftMod = 0
            fps = myDoc.GetFps()  
            theFrame = startFrame 
            while theFrame < 360:
                curFrame = doc.GetTime().GetFrame(doc.GetFps())
                print "*****************************************"
                print "     THE CURRENT FRAME IS : " + str(curFrame)  
                print "*****************************************"   
                for ListOb in Selected:
                    trList = ListOb.GetCTracks()
                    theType = ListOb.GetTypeName()
                    for i, v in enumerate(trList) :                
                        if trList[i].GetName() == "Enabled" and theType == "XRef":
                            crv = trList[i].GetCurve()
                            print ListOb.GetName()
                            keyCount = crv.GetKeyCount()
                            print "The key count is: " + str(keyCount)
                            oo = 0
                            ww = 0
                            while oo < keyCount and ww == 0:
                                key = crv.GetKey(oo)
                                keyVal = key.GetGeData()
                                if keyVal == 1:
                                    keyTime = key.GetTime()
                                    theEnabledFrame = keyTime.GetFrame(fps)
                                    print "The key is at frame: " + str(theEnabledFrame)
                                    if theEnabledFrame == curFrame:
                                        ww += 1                                      
                                        xName = ListOb.GetName() #return the name of an object 
                                        if xName[-4:] == ".c4d":
                                            xName = xName[:-4]
                                        xName = string.replace(xName, "/", "_")
                                        xName = string.replace(xName, "(", "--")
                                        xName = string.replace(xName, ")", "--")
                                        xName = string.replace(xName, ".", "_")
                                        xName = string.replace(xName, ",", "_")
                                        xName = string.replace(xName, "+", "-and-")
                                        xName = xName[5:] + "_"
                                        print "--------------------------------------------------------"
                                        print xName + " will render on this frame => " + str(curFrame)
                                        print "--------------------------------------------------------"
                                        path = "Users/david.cox/Desktop/testFolder/Accessory_catalog_Scene/"
                                        rd = doc.GetActiveRenderData()
                                        #path = rd[c4d.RDATA_PATH]
                                        rd[c4d.RDATA_FRAMEFROM] = (c4d.BaseTime(startFrame,30))
                                        rd[c4d.RDATA_FRAMESEQUENCE] = (c4d.RDATA_FRAMESEQUENCE_CURRENTFRAME)
                                        rd[c4d.RDATA_PATH] = path + xName
                                        c4d.CallCommand (12099) # ********** CALLS THE RENDERER ************
                                        isRend = c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING)
                                        while isRend == 1:
                                            isRend = c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING)                       
                                            if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.BFM_INPUT_CHANNEL,bc) :        
                                                if bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QSHIFT:
                                                    shiftMod=1
                                                    print "Breaking out of loop"
                                                    break
                                            if shiftMod==1:
                                                break                                
                                        if shiftMod==1:
                                            break
                                    if shiftMod==1:
                                        break
                                if shiftMod==1:
                                    break
                                oo += 1
                c4d.CallCommand(12414) #Advance a frame
                theFrame += 1
                
            c4d.CallCommand(12501) #Goto Start Frame
            c4d.EventAdd()
                    
        if __name__=='__main__':
            main()
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post