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.
<p>//...</p><p></p><p>string drawingTemplate = SelectDrawingTemplate();</p><p></p><p>if (string.IsNullOrWhiteSpace(drawingTemplate))</p><p> return;</p><p></p><p>var bodyFeatures = GetBodyFeatures(partDocument);</p><p></p><p>foreach (IBody2 bodyFeature in bodyFeatures)</p><p>{</p><p> //...</p><p> var drawing = NewDrawing(drawingTemplate);</p><p> //...</p><p>}</p><p></p><p>//...</p>The NewDrawing method looks like this:
<p>private IDrawingDoc NewDrawing(string drawingTemplate)</p><p>{</p><p> if (!File.Exists(drawingTemplate))</p><p> throw new Exception("Drawing template does not exist.");</p><p></p><p><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> int paperSizeA = (int)swDwgPaperSizes_e.swDwgPaperAsize;</span></p><p></p><p> return (IDrawingDoc)SolidWorks.Application.NewDocument(drawingTemplate, paperSizeA, 0, 0);</p><p>}</p>SolidworksApi macros