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) Drawing is open.

'       (2) Drawing view is selected.

'

' Postconditions: None

'

' Notes: Currently there is only read access to the

'        FaceHatch object. However, there is read-write

'        access to the SketchHatch object.

'

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

Option Explicit

Public Enum swDrawingViewTypes_e

    swDrawingSheet = 1

    swDrawingSectionView = 2

    swDrawingDetailView = 3

    swDrawingProjectedView = 4

    swDrawingAuxiliaryView = 5

    swDrawingStandardView = 6

    swDrawingNamedView = 7

    swDrawingRelativeView = 8

End Enum

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.GetSelectedObject5(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

            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) 2013 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.