The stack overflow error you're encountering with the batch save utility in Civil 3D can be tricky, especially when dealing with a large number of files and objects. Here are some suggestions and alternatives that might help you tackle this issue:
1. Memory Management:
Increase System Resources: Ensure that your system has sufficient RAM and virtual memory allocated. Sometimes, increasing system resources can help alleviate stack overflow issues, especially with large drawings.
Run in Smaller Batches: If possible, split the 500+ files into smaller batches and run your script on these subsets to reduce the load on the batch save utility.
2. Script Optimization:
Simplify Commands: The _SETBYLAYER command can be resource-intensive when applied to all objects in a large drawing. Consider breaking down the command to process objects in smaller chunks, if possible.
Try Another Approach: Instead of using the SETBYLAYER command on all objects in one go, try iterating over object types or layers separately. This could help reduce the risk of a stack overflow.
3. Use Dynamo or Custom Code:
Dynamo: Dynamo for Civil 3D could be a viable alternative if you have experience with it. It allows you to automate tasks with more control and flexibility. You can create a script in Dynamo to loop through all files and execute the necessary commands in a more controlled manner.
AutoLISP or .NET API: If you're comfortable with coding, AutoLISP or the Civil 3D .NET API can offer more robust handling of large-scale batch processes. These programming options provide better error handling and memory management, which could prevent stack overflow errors.
4. Custom Batch Processing Tools:
Custom Batch Scripts: If Dynamo or coding isn't an option, consider developing a custom batch processing tool that works alongside Civil 3D. You can script the process to open each file, execute the commands, save, and close the file with more granular control over memory usage.
5. Civil 3D Performance Settings:
Adjust Settings: Check the Civil 3D performance settings, such as disabling hardware acceleration temporarily or adjusting display settings, to see if this reduces the likelihood of errors during batch processing.
6. Testing Environment:
Create a Test Environment: Set up a test environment where you can simulate the batch process with a subset of files. This can help you identify specific bottlenecks or issues in the script before running it on all 500+ files.
7. Consider Third-Party Tools:
Third-Party Batch Tools: Some third-party tools designed for batch processing in AutoCAD and Civil 3D offer enhanced capabilities for large projects. Tools like AutoCAD's AutoScript or Civil 3D Batch Plot might offer better stability for extensive batch operations.
By using these strategies, you should be able to overcome the limitations of the batch save utility and ensure that your weekly batch processing tasks run smoothly. If you go the Dynamo route, you'll have more flexibility and the ability to fine-tune the process to your needs.