Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Sketch Segments in Active Sketch

API and Macros

Count Sketch Segments in Active Sketch

by  MadMango  Posted    (Edited  )
This macro can help you trouble shoot some performance related problems you may have with certain models. By being able to count the number of sketch segments in any active sketch, you can determine if a particular sketch might have too many sketch segments. Currently there is no defined "upper limit" to the number of sketch segments, but a good rule of thumb would be to have no more than 300.

This macro was written in SW03, if you have problems with an older/newer version of SolidWorks, please let me know.

Code:
Option Explicit

Public Enum swSkSegments_e
    swSketchLINE = 0
    swSketchARC = 1
    swSketchELLIPSE = 2
    swSketchSPLINE = 3
    swSketchTEXT = 4
    swSketchPARABOLA = 5
End Enum

Dim Total As Integer



Sub main()
    Dim sSkSegmentsName(5)      As String
    
    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swSelMgr                As SldWorks.SelectionMgr
    Dim swFeat                  As SldWorks.feature
    Dim swSketch                As SldWorks.sketch
    Dim vSkSegArr               As Variant
    Dim vSkSeg                  As Variant
    Dim swSkSeg                 As SldWorks.SketchSegment
    Dim swSkLine                As SldWorks.SketchLine
    Dim swSkArc                 As SldWorks.SketchArc
    Dim swSkEllipse             As SldWorks.SketchEllipse
    Dim swSkSpline              As SldWorks.SketchSpline
    Dim swSkText                As SldWorks.SketchText
    Dim swSkParabola            As SldWorks.SketchParabola
    Dim vID                     As Variant
    Dim i                       As Long
    Dim bRet                    As Boolean
    Total = 0
  On Error GoTo huboalgo
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swFeat = swSelMgr.GetSelectedObject4(1)
    Set swSketch = swFeat.GetSpecificFeature
   
    
    vSkSegArr = swSketch.GetSketchSegments
    For Each vSkSeg In vSkSegArr
        Set swSkSeg = vSkSeg
        Total = Total + 1
    Next vSkSeg
    MsgBox "Total of segments: " & Total, vbInformation, "SEGMENTS COUNT"
    GoTo THEEND
huboalgo:
    MsgBox "Please select an sketch", vbCritical, "MACRO ERROR"
THEEND:
End Sub

An small update, this has been converted to an Add-In. You can find it at http://www.esoxrepublic.com/freeware/

Many thanks to [blue]TheTick[/blue] for the conversion to an Add-In.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search