Hide Table of Contents

Run Thickness Analysis Example (VBA)

This example shows how to run a thickness analysis and generate reports using the SolidWorks Utilities API.

 

'---------------------------------------------

'

' Preconditions: Substitute the name of your part, which you

'          want to analyze, for xyz.sldprt.

'

' Postconditions:

'          (1) Thickness analysis report is added to the Design Binder.

'          (2) Thickness analysis report is saved to disk.

'

'----------------------------------------------

Option Explicit

 

Dim swApp As SldWorks.SldWorks

 

Sub main()

    Dim swModel                 As SldWorks.ModelDoc2

    Dim utAddIn                 As SWUtilities.gtcocswUtilities

    Dim utThicknessAnalysis     As SWUtilities.gtcocswThicknessAnalysis

    Dim nOptions                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    

        

    ' Connect to SolidWorks

    Set swApp = Application.SldWorks

 

    ' Load the document for analysis

    Set swModel = swApp.OpenDoc6("xyz.SLDPRT", swDocPART, swOpenDocOptions_Silent, "", lErrors, lWarnings)

    

    ' 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

    nOptions = gtResultSaveReport

    

    ' Use high resolution

    nResolution = gttckHighResolution

    

    ' Strip the extension from the model name to

    ' get the name of the folder where to save the report

    strReportName = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, ".") - 1)

    

    ' Add the report to the Design Binder

    bAddToBinder = True

 

    ' Save the report to eDrawings

    bSaveToEdwg = True

    

    ' 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.025

    

    ' Run the analysis

    lStatus = utThicknessAnalysis.RunThinAnalysis2(dThicknessLimit, nResolution, nOptions, 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

    

    '

    ' Get results

    '

    

    Debug.Print "Total surface area analyzed              = " & CStr(utThicknessAnalysis.GetTotalSurfaceAreaAnalyzed(lStatus))

    Debug.Print "Critical area                            = " & CStr(utThicknessAnalysis.GetCriticalSurfaceArea(lStatus))

    Debug.Print "Maximum deviation                        = " & CStr(utThicknessAnalysis.GetMaxDeviationfromTargetThickness(lStatus))

    Debug.Print "Average weighted thickness critical area = " & CStr(utThicknessAnalysis.GetAvgWeightedTckOnCritArea(lStatus))

    Debug.Print "Average weighted thickness analyzed area = " & CStr(utThicknessAnalysis.GetAvgWeightedTckOnAnalArea(lStatus))

    Debug.Print "Number of critical faces                 = " & CStr(utThicknessAnalysis.GetNumCriticalFaces(lStatus))

    Debug.Print "Number of critical features              = " & CStr(utThicknessAnalysis.GetNumCriticalFeatures(lStatus))

    

    vCriticalFeatureNames = utThicknessAnalysis.GetCriticalFeatureNames(lStatus)

    If Not IsEmpty(vCriticalFeatureNames) Then

        Debug.Print "Critical features:"

        For lIdx = LBound(vCriticalFeatureNames) To UBound(vCriticalFeatureNames)

            Debug.Print "  " & vCriticalFeatureNames(lIdx)

        Next lIdx

    End If

    

    Debug.Print "Minimum thickness analyzed area          = " & CStr(utThicknessAnalysis.GetMinTckOnAnalArea(lStatus))

    Debug.Print "Maximum thickness analyzed area          = " & CStr(utThicknessAnalysis.GetMaxTckOnAnalArea(lStatus))

    lNumRanges = utThicknessAnalysis.GetIntervalCount(lStatus)    

    Debug.Print "Number of intervals                      = " & lNumRanges CStr(utThicknessAnalysis.GetIntervalCount(lStatus))

    

    For lIdx = 1 To lNumRanges

        Debug.Print "  #" & CStr(lIdx)        

        lStatus = utThicknessAnalysis.GetAnalysisDetails(lIdx, dRangeMin, dRangeMax, lNumFaces, dSurfArea, dPerAnalysisArea)

        If lStatus <> gtNOErr Then

            Debug.Print "Could not obtain analysis details."            

        Else

        

            Debug.Print "     min            = " & CStr(dRangeMin)

            Debug.Print "     max            = " & CStr(dRangeMax)

            Debug.Print "     #faces         = " & CStr(lNumFaces)

            Debug.Print "     surf area      = " & CStr(dSurfArea)

            Debug.Print "     %analyzed area = " & CStr(dPerAnalysisArea)

        End If    

        

    Next lIdx

    ' Close the thickness analysis tool

    lStatus = utThicknessAnalysis.Close()

    

    ' Release

    Set utThicknessAnalysis = Nothing

    Set utAddIn = Nothing

    

    ' Done

    Exit Sub

 

End Sub



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Run Thickness Analysis (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.