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
    • Register
    • Login
    1. Home
    2. Visualride 0
    V
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 3
    • Best 0
    • Controversial 0
    • Groups 0

    Visualride 0

    @Visualride 0

    0
    Reputation
    2
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Visualride 0 Unfollow Follow

    Latest posts made by Visualride 0

    • RE: Crash from processing too many xrefs.

      8000 files. Average about 4mb. The total is about 29gb.

      posted in Cinema 4D SDK
      V
      Visualride 0
    • RE: Crash from processing too many xrefs.

      @ferdinand
      Thank you for your response and suggestions.

      I created a script version of my plugin, but it still crashed after running out of memory. Here it is in the bare bones version paired down to simply loading all the files into a list, opening them and closing the file. My included screenshot shows the memory load increasing till I run out of memory. How do I avoid this?

      import c4d, math, string
      from c4d import gui, plugins, utils, bitmaps
      import os
      
      
      # Main function
      def main():
          
          filesList = []
          initialPath = "/Volumes/Argo3D/"
          rootDir = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "***** -PLEASE CHOOSE THE DIRECTORY ROOT- *****", c4d.FILESELECT_DIRECTORY, "", initialPath) + "/"
      
          findText = c4d.gui.InputDialog("Enter the text to find (To replace)", "")
          if findText == "":
              c4d.gui.MessageDialog("No FIND text entered")
              return
          replaceText = c4d.gui.InputDialog("Enter the text to replace the found text", "")
          if replaceText == "":
              c4d.gui.MessageDialog("No REPLACE text entered")
              return
      
          for root, subFolders, files in os.walk(rootDir):
              for file in files:
                  if file[-4:] == ".c4d":
                      pathWithFile = root + "/" + file
                      filesList.append(pathWithFile)
      
          for fixFile in filesList:
              changed = False
              c4d.documents.LoadFile(fixFile)
              doc = c4d.documents.GetActiveDocument()
              c4d.documents.InsertBaseDocument(doc)
              c4d.documents.SetActiveDocument(doc)
              c4d.documents.SaveDocument(doc, fixFile, c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)
              c4d.documents.KillDocument(doc)
          c4d.gui.MessageDialog("Done!")
      
      
          c4d.EventAdd()
      
      # Execute main()
      if __name__=='__main__':
          main()
      

      Screenshot 2024-02-08 at 8.12.35 AM.png

      posted in Cinema 4D SDK
      V
      Visualride 0
    • Crash from processing too many xrefs.

      My plugin searches for and replaces strings of text in xrefs. It first gathers into a list all xref c4d files from a designated directory tree. If the directory contains more than a hundred or so legacy xrefs, which have several embedded xrefs, the plugin crashes.
      Two questions:

      1. Based on my supplied code, is there a way to optimize what I have to avoid crashes?
      2. Is there a way to flush the cache after every directory of files processed? I've tried cache_clear() with no luck.
        Here are, hopefully, the relevant parts of my code:
      def GetVirtualObjects(self, op, hierarchyhelp):
              dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
              if dirty is False:
                  return op.GetCache(hierarchyhelp)
      
              baseNull = c4d.BaseObject(c4d.Onull)
              pluginNode = c4d.BaseObject(c4d.Onull)
              pluginNode.InsertUnder(baseNull)
      
              c4d.EventAdd()
              return baseNull
      
      def Process_Process(self, op, rootDir, findTextList, replaceTextList, simulateFolderOnOff, simulateFolder, logFile_OnOff, logFileFolder):
              filesList = []
              now = datetime.now()
              logReport = ("Date: " + now.strftime("%m-%d-%Y") + '\n' + "Time: " + now.strftime("%H:%M:%S") + '\n' + '\n')
      
              for root, subFolders, files in os.walk(rootDir):
                  for file in files:
                      if file[-4:] == ".c4d":
                          pathWithFile = root + "/" + file
                          filesList.append(pathWithFile)
      
              changed = False
              for fixFile in filesList:
                  c4d.documents.LoadFile(fixFile)
                  doc = c4d.documents.GetActiveDocument()
                  c4d.documents.InsertBaseDocument(doc)
                  c4d.documents.SetActiveDocument(doc)
                  logFile = True
      
                  xList = []
                  Selected = self.get_all_objects(doc.GetFirstObject(), [])
                  for ListOb in Selected:
                      theType = ListOb.GetTypeName()
                      if theType == "Legacy XRef" or theType == "Simple XRef":
                          if ListOb[c4d.SCENEINSTANCE_FILENAME] != None:
                              xList.append(ListOb) #Build xref list
                  for y in xList:
                      xrefNameAndPath = y[c4d.SCENEINSTANCE_FILENAME]
                      originalXrefNameAndPath = xrefNameAndPath
                      for x in range(10):
                          if findTextList[x] != "":
                              finalXrefNameAndPath = self.ireplace(findTextList[x], replaceTextList[x], xrefNameAndPath)
                              if xrefNameAndPath != finalXrefNameAndPath:
                                  y[c4d.SCENEINSTANCE_FILENAME] = finalXrefNameAndPath
                                  if logFile == True:
                                      logReport = (logReport + "File: " + fixFile + '\n')
                                  logFile = False
                                  xrefNameAndPath = finalXrefNameAndPath
                                  changed = True
                      if changed == True:
                          logReport = (logReport + "Original Xref Name: " + originalXrefNameAndPath + '\n' + "New Xref Name: " + finalXrefNameAndPath + '\n')
      
                  if changed == True:
                      logReport = (logReport + '\n')
                      if simulateFolderOnOff == False:
                          c4d.documents.SaveDocument(doc, fixFile, c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)
                      if simulateFolderOnOff == True:
                          theFileName = self.get_name(fixFile)
                          simFolder_name = (simulateFolder + '/' + theFileName)
                          c4d.documents.SaveDocument(doc, simFolder_name, c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)
      
                  changed = False
                  c4d.documents.KillDocument(doc)
      
              return logReport
      
      posted in Cinema 4D SDK r25 python macos
      V
      Visualride 0