Hide Table of Contents

Get Hatching Data Example (VBA)

This example shows how to get hatching data from a drawing view.

In a drawing view, hatching can be applied by the user to any face or, as in the case of a section view, automatically applied by the SOLIDWORKS software. Hatching applied by the user is accessed through the ISketchHatch object. In contrast, hatching in a section view is accessed through the IFaceHatch object.

'------------------------------------------------
' Preconditions:
' 1. Open public_documents\introsw\bolt-assembly.slddrw.
' 2. Select Section View A-A in the FeatureManager design tree.
' 3. Open the Immediate window.
'
' Postconditions:
' 1. Gets hatching data.
' 2. Examine the Immediate window.
'--------------------------------------------------
Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swView As SldWorks.View
    Dim swSketch As SldWorks.Sketch
    Dim vFaceHatch As Variant
    Dim swFaceHatch As SldWorks.FaceHatch
    Dim swFace As SldWorks.Face2
    Dim vSketchHatch As Variant
    Dim swSketchHatch As SldWorks.SketchHatch
    Dim i As Long
    Dim bRet As Boolean
    
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc    
    Set swSelMgr = swModel.SelectionManager
    Set swView = swSelMgr.GetSelectedObjec6(1, -1)
    Set swSketch = swView.GetSketch
    Debug.Print "View   = " & swView.Name
    Debug.Print "  Type = " & swView.Type
    Debug.Print ""
    vFaceHatch = swView.GetFaceHatches
    If Not IsEmpty(vFaceHatch) Then
        Debug.Print "  Face hatches:"
        Debug.Print ""
        For i = 0 To UBound(vFaceHatch)
            Set swFaceHatch = vFaceHatch(i)
            Set swFace = swFaceHatch.Face
            ' Cannot select a face because a face is in model
            bRet = swFace.Select2(True, 0)
            ' Get sketch hatch data
            ' 1 radian = 180º/p = 57.295779513º or approximately 57.3º
            Debug.Print "  Angle          = " & swFaceHatch.Angle * 57.3 & " degrees"
            Debug.Print "  Color          = " & swFaceHatch.Color
            Debug.Print "  Definition     = " + swFaceHatch.Definition
            Debug.Print "  Layer          = " & swFaceHatch.Layer
            Debug.Print "  Pattern        = " + swFaceHatch.Pattern
            Debug.Print "  Scale          = " & swFaceHatch.Scale2
            Debug.Print "  SolidFill      = " & swFaceHatch.SolidFill
            Debug.Print "  -----------------------"
        Next i
    End If
    vSketchHatch = swSketch.GetSketchHatches
    If Not IsEmpty(vSketchHatch) Then
        Debug.Print "  Sketch hatches:"
        Debug.Print ""
        For i = 0 To UBound(vSketchHatch)
            Set swSketchHatch = vSketchHatch(i)
            Set swFace = swSketchHatch.GetFace
            ' Cannot select a face because a face is in model
            bRet = swFace.Select2(True, 0)
            ' Get sketch hatch data
            Debug.Print "  Angle          = " & swSketchHatch.Angle * 57.3 & " degrees"
            Debug.Print "  Color          = " & swSketchHatch.Color
            Debug.Print "  ID             = [" & swSketchHatch.GetID(0) & ", " & swSketchHatch.GetID(1) & "]"
            Debug.Print "  Layer          = " & swSketchHatch.Layer
            Debug.Print "  LayerOverride  = " & swSketchHatch.LayerOverride
            Debug.Print "  Pattern        = " + swSketchHatch.Pattern
            Debug.Print "  Scale          = " & swSketchHatch.Scale2
            Debug.Print "  SolidFill      = " & swSketchHatch.SolidFill
            Debug.Print "  -----------------------"
        Next i
    End If
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:   Get Hatching Data Example (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) 2019 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.