> Find Outside Edges of Face Example (VBA)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show Table of Contents

Find Outside Edges of Face Example (VBA)

This example shows how to find the outside edges of the selected face.

 

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

'

' Preconditions: Part is open and a face is selected.

'

' Postconditions: None

'

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

Option Explicit

Sub CreateTessCurve _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swSketch As SldWorks.sketch, _

    swTrimCurve As SldWorks.curve _

)

    Const nChordTol                 As Double = 0.001   ' Meters

    Const nLengthTol                As Double = 0.001   ' Meters

    Dim nStartParam                 As Double

    Dim nEndParam                   As Double

    Dim bIsClosed                   As Boolean

    Dim bIsPeriodic                 As Boolean

    Dim vStartPt                    As Variant

    Dim vEndPt                      As Variant

    Dim vTessPts                    As Variant

    Dim swSketchSeg                 As SldWorks.SketchSegment

    Dim bRet                        As Boolean

    Dim i                           As Long

    

    ' Really not needed because curve is a trimmed curve,

    ' so could pass in trim points as parameters

    bRet = swTrimCurve.GetEndParams(nStartParam, nEndParam, bIsClosed, bIsPeriodic): Debug.Assert bRet

    

    vStartPt = swTrimCurve.Evaluate(nStartParam)

    vEndPt = swTrimCurve.Evaluate(nEndParam)

    

    vTessPts = swTrimCurve.GetTessPts(nChordTol, nLengthTol, (vStartPt), (vEndPt))

    

    

    ' Disable VB range checking because tessellation points

    ' may not be a multiple of 6

    On Error Resume Next

    For i = 0 To UBound(vTessPts) Step 3

        Set swSketchSeg = swModel.CreateLine2( _

                            vTessPts(i + 0), vTessPts(i + 1), vTessPts(i + 2), _

                            vTessPts(i + 3), vTessPts(i + 4), vTessPts(i + 5))

    Next i

    On Error GoTo 0

End Sub

Sub CreateTessLoop _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swLoop As SldWorks.Loop2 _

)

    Dim vEdgeArr                    As Variant

    Dim vEdge                       As Variant

    Dim swEdge                      As SldWorks.Edge

    Dim swCurve                     As SldWorks.curve

    Dim swSketch                    As SldWorks.sketch

    Dim bRet                        As Boolean

    swModel.Insert3DSketch2 False

    swModel.SetAddToDB True

    swModel.SetDisplayWhenAdded False

    

    Set swSketch = swModel.GetActiveSketch2

    vEdgeArr = swLoop.GetEdges: Debug.Assert UBound(vEdgeArr) >= 0

    For Each vEdge In vEdgeArr

        Set swEdge = vEdge

        Set swCurve = swEdge.GetCurve

        

        CreateTessCurve swApp, swModel, swSketch, swCurve

    Next vEdge

        

    swModel.SetDisplayWhenAdded True

    swModel.SetAddToDB False

    swModel.Insert3DSketch2 True

    

    bRet = swModel.EditRebuild3: Debug.Assert bRet

End Sub

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swPart                      As SldWorks.PartDoc

    Dim swSelMgr                    As SldWorks.SelectionMgr

    Dim swFace                      As SldWorks.face2

    Dim swLoop                      As SldWorks.Loop2

    

    Dim i                           As Long

    Dim bRet                        As Boolean

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swPart = swModel

    Set swSelMgr = swModel.SelectionManager

    Set swFace = swSelMgr.GetSelectedObject5(1)

    

    Debug.Print "FaceArea  = " & swFace.GetArea * 1000000# & " mm^2"

    Debug.Print "  LoopCount    = " & swFace.GetLoopCount

    Debug.Print ""

    

    Set swLoop = swFace.GetFirstLoop

    Do While Not swLoop Is Nothing

        i = i + 1

        

        Debug.Print "  Loop(" & i & ")"

        Debug.Print "    IsOuter    = " & swLoop.IsOuter

        Debug.Print "    IsSingular = " & swLoop.IsSingular

        

        If swLoop.IsOuter Then

            CreateTessLoop swApp, swModel, swLoop

        End If

        

        Set swLoop = swLoop.GetNext

    Loop

End Sub

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



Related SolidWorks Forum Content

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:   Find Outside Edges of Face Example (VBA)
*Comment:  
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) 2012 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of DS SolidWorks or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2012 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.