|
If a drawing 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 by using ISldWorks.EnableBackgroundProcessing.
Setting this property to true allows the SolidWorks API to
open the drawing with the drawing view processing running in a background process.
This is how the drawing
is opened when it is opened interactively.
Because you cannot make changes to the drawing while the
background process is running, you should use ISldWorks.EnableBackgroundProcessing with
ISldWorks::IsBackgroundProcessingCompleted.
Click a bulleted
item to jump to the sample code written in that language that
demonstrates their use.
C# sample code
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using System;
using
System.Diagnostics;
Namespace
EnableBackgroundProcessingCSharp.csproj
{
Partial
Public
Class SolidWorksMacro
{
public
void Main()
{
DrawingDoc swDrawing;
string
strFileName = null;
int status = 0;
int warnings = 0;
strFileName = "<your_drawing_document>.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
process running...");
}
swApp.EnableBackgroundProcessing =
false;
swApp = null;
}
/// <summary>
/// The SldWorks swApp variable is
pre-assigned for
you.
/// </summary>
public
SldWorks swApp;
}
}
back to top
VB.NET sample
code
Imports
SolidWorks.Interop.sldworks
Imports
SolidWorks.Interop.swconst
Imports System
Imports
System.Diagnostics
Partial
Class SolidWorksMacro
Public
Sub main()
Dim
swDrawing As
DrawingDoc
Dim
strFileName As
String
Dim
longstatus As
Long
Dim
longwarnings As
Long
strFileName =
"<your_drawing_document>.slddrw"
swApp.EnableBackgroundProcessing
= True
swDrawing = swApp.OpenDoc6(strFileName,
swDocumentTypes_e.swDocDRAWING,
swDocumentTypes_e.swOpenDocOptions_Silent,
"", longstatus,
longwarnings)
While (swApp.IsBackgroundProcessingCompleted(strFileName)
= False)
Debug.Print("Background
process running...")
End
While
swApp.EnableBackgroundProcessing
= False
swApp =
Nothing
End
Sub
'''
<summary>
''' The
SldWorks swApp variable is pre-assigned for you.
'''
</summary>
Public
swApp As
SldWorks
End
Class
back to top
VBA sample
code
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swDrawing As SldWorks.DrawingDoc
Dim strFileName As String
Dim longstatus As Long
Dim longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
strFileName = "<your_drawing_document>.slddrw"
swApp.EnableBackgroundProcessing = True
Set swDrawing = swApp.OpenDoc6(strFileName,
swDocDRAWING,
_
swOpenDocOptions_Silent,
"", longstatus, longwarnings)
While (swApp.IsBackgroundProcessingCompleted(strFileName) =
False)
Debug.Print ("Background process running...")
Wend
swApp.EnableBackgroundProcessing = False
Set swApp = Nothing
End Sub
|