Enable Background Processing When Opening Drawing Document (C#)
If a drawing document takes more time to open via the SolidWorks API than it
does interactively, then you might be able to open the drawing more efficiently
in the SolidWorks API using ISldWorks::EnableBackgroundProcessing.
Setting this property to true opens the drawing while processing the drawing
views in a background process.
Because you cannot make changes to the drawing while the background process
is running, you should use ISldWorks::EnableBackgroundProcessing with
ISldWorks::IsBackgroundProcessingCompleted .
//---------------------------------------------------------------------------
// Preconditions: Specified drawing document exists.
//
// Postconditions: Specified drawing document opens.
//---------------------------------------------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace
EnableBackgroundProcessingCSharp.csproj
{
public
partial
class SolidWorksMacro
{
public
void Main()
{
DrawingDoc swDrawing;
string
strFileName = null;
int status = 0;
int warnings =
0;
strFileName = "c:\\Program
Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\advdrawings\\foodprocessor.slddrw";
swApp.EnableBackgroundProcessing =
true;
swDrawing = (DrawingDoc)swApp.OpenDoc6(strFileName, (int)swDocumentTypes_e.swDocDRAWING,
(int)swOpenDocOptions_e.swOpenDocOptions_Silent,
"",
ref status,
ref warnings);
while ((swApp.IsBackgroundProcessingCompleted(strFileName)
== false))
{
Debug.Print("Background
processing ongoing...");
}
swApp.EnableBackgroundProcessing =
false;
swApp = null;
}
///
<summary>
///
The SldWorks swApp variable is pre-assigned for you.
///
</summary>
public
SldWorks swApp;
}
}