Hide Table of Contents

Insert Hatch Example Example (VB.NET)

This example shows how to insert a Hatch in a drawing document.

' Preconditions:
' 1. Create a VB.NET Windows console project.
' 2. Copy and paste this project into the VB.NET IDE.
' 3. Add a reference to:
'    install_dir\APISDK\tlb\DraftSight.Interop.dsAutomation.dll.
' 4. Add references to System and System.Windows.Forms.
' 5. Start DraftSight and open a drawing document.
' 6. Start debugging the project.
' Postconditions: A Hatch is inserted in the drawing document
' and zoomed to fit.

Imports System.Collections.Generic
Imports System.Text
Imports DraftSight.Interop.dsAutomation
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Diagnostics

Module Module1

Dim dsApp As DraftSight.Interop.dsAutomation.Application

Sub Main()
'Connect to DraftSight application
        dsApp = GetObject(, "DraftSight.Application")
dsApp.AbortRunningCommand() ' abort any command currently running in DraftSight to avoid nested commands

'Get active document
        Dim dsDoc As Document = dsApp.GetActiveDocument()
If dsDoc Is Nothing Then
            MessageBox.Show("There are no open documents in DraftSight.")
        End If

        'Get model space
        Dim dsModel As Model = dsDoc.GetModel()

'Get Sketch Manager
        Dim dsSketchMgr As SketchManager = dsModel.GetSketchManager()

'Hatch parameters
        Dim boundaryPointCountArray As Integer() = New Integer() {4}
Dim boundaryPoints As Double() = New Double() {0, 0, 2, 0, 2, 2, 0, 2}
Dim patternName As String = "ANSI31"
        Dim patternScale As Double = 1.0
Dim patternAngle As Double = Math.PI / 4 ' In radians

        'Insert Hatch
        Dim dsHatch As Hatch = dsSketchMgr.InsertHatchByBoundary(boundaryPointCountArray, boundaryPoints, patternName, patternScale, patternAngle)
If dsHatch IsNot Nothing Then
            'Change color of Hatch
            Dim dsColor As Color = dsHatch.Color
            dsHatch.Color = dsColor

'Zoom to fit
            dsApp.Zoom(dsZoomRange_e.dsZoomRange_Fit, Nothing, Nothing)
            MessageBox.Show("Hatch entity was not added to the current drawing.")
End If
    End Sub
End Module

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

Subject:   Feedback on Help Topics
Page:   Insert Hatch Example (VB.NET)
*   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:


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

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.