AnsweredAssumed Answered

Solidworks API: How to stop the Thickness Analysis from closing?

Question asked by Chong Kai San on May 25, 2020

' Main function of our VBA program
Sub main()


Dim utAddIn As SWUtilities.gtcocswUtilities
Dim utThicknessAnalysis As SWUtilities.gtcocswThicknessAnalysis
Dim nOption As SWUtilities.gtResultOptions_e
Dim nResolution As SWUtilities.gttckResolutionOptions_e
Dim strReportName As String
Dim lStatus As Long
Dim bAddToBinder As Boolean
Dim bSaveToEdwg As Boolean
Dim bOverWrite As Boolean
Dim vCriticalFeatureNames As Variant
Dim lIdx As Long
Dim dRangeMin As Double
Dim dRangeMax As Double
Dim lNumFaces As Long
Dim dSurfArea As Double
Dim dPerAnalysisArea As Double
Dim lNumRanges As Long
Dim dThicknessLimit As Double
Dim lErrors As Long
Dim lWarnings As Long
Dim sPart As String
Dim Part As Object
Dim FileDirectory As String

' Connect to SOLIDWORKS
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

'Show specific view (Not neccesary) & Zoom Screen to fit
Part.ShowNamedView2 "*Trimetric", 8
Part.ViewZoomtofit2

'Determine current file directory
'FileDirectory = CurDir$
'Debug.Print FileDirectory

' Load the SOLIDWORKS Utilities add-in
Set utAddIn = swApp.GetAddInObject("Utilities.UtilitiesApp")
' Get the thickness analysis tool
Set utThicknessAnalysis = utAddIn.ThicknessAnalysis
' Initialize the thickness analysis tool
lStatus = utThicknessAnalysis.Init()
If lStatus <> gtNOErr Then
Debug.Print "Thickness analysis tool could not be initialized: " & CStr(lStatus)
Exit Sub
End If

' Set the options
' Save the report
nOption = gtResultSaveReport
' Use high resolution
nResolution = gttckHighResolution
' Save the report to this folder
strReportName = "c:\test\report"
' Add the report to the Design Binder
bAddToBinder = True
' Do not save the report to eDrawings
bSaveToEdwg = False
' Allow the report to be overwritten, both in Design Binder and
' on disk, so that you can rerun the analysis
bOverWrite = True
' Set the thickness threshold
dThicknessLimit = 0.0005
' Run the analysis
lStatus = utThicknessAnalysis.RunThinAnalysis2(dThicknessLimit, nResolution, nOption, strReportName, bAddToBinder, bSaveToEdwg, bOverWrite)

' Check the result
If lStatus <> gtNOErr Then
Debug.Print "Thickness analysis completed an with error: " & CStr(lStatus)
' Close the thickness analysis tool
lStatus = utThicknessAnalysis.Close()
' Release
Set utThicknessAnalysis = Nothing
Set utAddIn = Nothing
Exit Sub
End If

' Close the thickness analysis tool
lStatus = utThicknessAnalysis.Close()
' Release
Set utThicknessAnalysis = Nothing
Set utAddIn = Nothing
' Done
Exit Sub
End Sub

I use the above code that run thickness analysis in a part and it works well. The only problem is I can't let it just stay at the analysis view, it will automatically closed even the following code:

' Close the thickness analysis tool
lStatus = utThicknessAnalysis.Close()
' Release
Set utThicknessAnalysis = Nothing
Set utAddIn = Nothing
' Done
Exit Sub

Any idea how I can stop the analysis from closing? I want to use a userform button to control the analysis to be just on or close. The image indicate what I means for analysis ( I want this page to just stay until I manually close it) 


Outcomes