I am using the API to automatically generate a bunch of drawings. The user is prompted to select a drawing template, and then the drawings are created in a loop. For some reason, there are always a few drawings in the set which don't load the selected template. I suspect it has something to do with creating new documents so quickly, but what should I do to address this?
I'm using SolidWorks 2012 SP 2.0.
I have provided excerpts from my code below (C#) to show what I'm doing.
//...
string drawingTemplate = SelectDrawingTemplate();
if (string.IsNullOrWhiteSpace(drawingTemplate))
return;
var bodyFeatures = GetBodyFeatures(partDocument);
foreach (IBody2 bodyFeature in bodyFeatures)
{
//...
var drawing = NewDrawing(drawingTemplate);
//...
}
//...
The NewDrawing method looks like this:
SolidworksApi macrosprivate IDrawingDoc NewDrawing(string drawingTemplate)
{
if (!File.Exists(drawingTemplate))
throw new Exception("Drawing template does not exist.");
int paperSizeA = (int)swDwgPaperSizes_e.swDwgPaperAsize;
return (IDrawingDoc)SolidWorks.Application.NewDocument(drawingTemplate, paperSizeA, 0, 0);
}