Tuesday, February 07, 2012
Exception when calling....
Last Post 12 Feb 2010 03:42 PM by R.D. Holland. 1 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
bomanUser is Offline
New Member
New Member
Posts:5

--
11 Feb 2010 02:13 AM  

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

 

R.D. HollandUser is Offline
Solid Edge Developer
New Member
New Member
Posts:50

--
12 Feb 2010 03:42 PM  
Why not just set the draft object to what is returned from the open call?

draft = (SolidEdgeDraft.DraftDocument) application.Documents.Open(tempDir + "\\" + fi.Name, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
You are not authorized to post a reply.

Active Forums 4.2
Copyright © 2011 JasonNewell.NET