8000 files. Average about 4mb. The total is about 29gb.
V
Latest posts made by Visualride 0
-
RE: Crash from processing too many xrefs.
-
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()
-
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:- Based on my supplied code, is there a way to optimize what I have to avoid crashes?
- 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