- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here's a code snippet from a project I'm working on (processing a large number of surfaces from point files in Civil 3D):
// Create and open a new drawing, from the specified template
Document doc = AcApplication.DocumentManager.Add(templateFileName);
AcApplication.DocumentManager.MdiActiveDocument = doc;
Database db = doc.Database;
// need to wait for Civil 3D to catch up!
MessageBox.Show(surfacename);
// Create the surface
using (Transaction trans = db.TransactionManager.StartTransaction())
{
// get the point file format object, required for import:
PointFileFormatCollection ptFileFormats = PointFileFormatCollection.GetPointFileFormats(db);
PointFileFormat ptFormat = ptFileFormats[ptFileFormat];
ObjectId styleId = GetStyleId(surfaceStyleName);
ObjectId surfaceId = TinSurface.Create(filename, styleId);
TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;What's odd, is that this works, pretty much the way I want it to, except for the MessageBox.Show(surfacename); line.
If I remove this line, or replace it with Thread.Sleep(30000); or for (int i=0; i<1000000; i++) {}, the program crashes on the TinSurface.Create(filename, styleId); line with a "Fail to create surface" error. I've tried using TinSurface.Create(db, surfacename); and it still crashes. I've also tried creating all of the drawing files first, then coming back and using DocumentManager.Open(). I can access existing surfaces using this technique, but I can't create them without the MessageBox.Show() statement. When I simply add the surfaces to the active drawing, the program works perfectly, but I want to put the surfaces into separate drawings for performance reasons.
Does anyone know what the MessageBox.Show() statement is doing that could be replicated without actually stopping the program to request input from the user? What part of the process did I miss? Do I need to reset the UI, or something along those lines, and how would I go about doing so?
Solved! Go to Solution.