I have the following code snippet that gives me an exception on the line:
draft = (SolidEdgeDraft.DraftDocument)application.ActiveDocument;
This code loops through all *dft files and opens them one by one
Here is the sample code
SolidEdgeDraft.DraftDocument draft = null;
SolidEdgeDraft.Sheet sheet = null;
SolidEdgeDraft.DrawingViews drawingViews = null;
SolidEdgeDraft.DrawingView drawingView = null;
SolidEdgeFramework.Variables variables = null;
SolidEdgeFramework.variable variable = null;
// Start exception handling
try
{
// Loop all dft files
foreach (FileInfo fi in rgFiles)
{
// Open current dft file;
application.Documents.Open(tempDir + "\\" + fi.Name, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
// Get the active document which shall be the current dft
draft = (SolidEdgeDraft.DraftDocument)application.ActiveDocument;
// Get the active document which shall be the current dft
sheet = (SolidEdgeDraft.Sheet)draft.ActiveSheet;
// Get all drawing views from the sheet
drawingViews = (SolidEdgeDraft.DrawingViews)sheet.DrawingViews;
// code continues here..........
However if i just add the following code that waits for five seconds before opening the draft then everything works
// Open current dft file;
application.Documents.Open(tempDir + "\\" + fi.Name, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
// Wait for five seconds in order for draft document to fully open
Thread.Sleep(5000);
// Get the active document which shall be the current dft
draft = (SolidEdgeDraft.DraftDocument)application.ActiveDocument;
However I would like to avoid to have an hardcoded wait sequence (because I tried with one second first which works for most models but fails sometimes).
Is there an alternate way of doing this?
Kind Regards
Kjell-Åke