Hide Table of Contents

Get Sketch Regions Example (VB.NET)

This example shows how to get the sketch regions in a sketch.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Open a model document that contains a Sketch1 feature and
'    one or more sketch regions.
' 2. Press F5 after each region is processed.
'
' Postconditions: None
'----------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics


Partial Class SolidWorksMacro

    
Sub main()

        
Dim myModel As ModelDoc2
        
Dim myPart As PartDoc
        
Dim SelMgr As SelectionMgr
        
Dim mySelectData As SelectData
        
Dim myFeature As Feature
        
Dim mySketch As Sketch
        
Dim regionCount As Integer
        Dim vSkRegions As Object
        Dim skRegion As SketchRegion
        
Dim myLoop As Loop2
        
Dim edgeCount As Integer, vertexCount As Integer
        Dim vEdges As Object, myEdge As Edge
        
Dim vVertices As Object, myVertex As Vertex
        
Dim vPoint As Object, X As Double, Y As Double, Z As Double
        Dim outer As Boolean, strOuter As String
        Dim i As Integer, j As Integer, k As Integer
        Dim boolstatus As Boolean

        myModel = swApp.ActiveDoc
        SelMgr = myModel.SelectionManager
        mySelectData = SelMgr.CreateSelectData
        myPart = myModel
        myFeature = myPart.FeatureByName(
"Sketch1")
        mySketch = myFeature.GetSpecificFeature2()
        
'             or
        '    Set mySketch = myModel.GetActiveSketch2()
        '    Set myFeature = mySketch

        If Not mySketch Is Nothing Then
            regionCount = mySketch.GetSketchRegionCount()
            Debug.Print(
"")
            Debug.Print(regionCount &
" regions in sketch " & myFeature.Name)

            vSkRegions = mySketch.GetSketchRegions()

            
For i = LBound(vSkRegions) To UBound(vSkRegions)
                skRegion = vSkRegions(i)

                
If Not skRegion Is Nothing Then
                    Debug.Print("  Region " & i & ":")
                    j = 0
                    myLoop = skRegion.GetFirstLoop()
                    
While Not myLoop Is Nothing
                        edgeCount = myLoop.GetEdgeCount()
                        vertexCount = myLoop.GetVertexCount()
                        outer = myLoop.IsOuter()

                        
If outer = 0 Then
                            strOuter = "Inner loop"
                        Else
                            strOuter = "Outer loop"
                        End If

                        Debug.Print("    Loop " & j & ": " & edgeCount & " edges, " & vertexCount & " vertices, " & strOuter)

                        vEdges = myLoop.GetEdges()

                        
For k = LBound(vEdges) To UBound(vEdges)
                            myEdge = vEdges(k)
                            
If Not myEdge Is Nothing Then
                                Debug.Print("      Edge " & k & ": ")
                            
End If

                        Next k

                        vVertices = myLoop.GetVertices()

                        
For k = LBound(vVertices) To UBound(vVertices)
                            myVertex = vVertices(k)
                            
If Not myVertex Is Nothing Then
                                vPoint = myVertex.GetPoint()
                                X = vPoint(0)
                                Y = vPoint(1)
                                Z = vPoint(2)

                                Debug.Print(
"      Vertex " & k & ": " & "(" & X & ", " & Y & ", " & Z & ")")
                            
End If
                        Next k

                        myLoop = myLoop.GetNext()
                        j = j + 1
                    
End While

                    boolstatus = skRegion.Select2(False, mySelectData)
                    
If boolstatus = 0 Then
                        Debug.Print("    Selection of region failed.")
                    
End If

                    Stop

                End If

            Next i

        
End If

    End Sub

    
    
Public swApp As SldWorks


End Class

 



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:   Get Sketch Regions Example (VB.NET)
*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) 2015 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.