Insert Hatch Example (VBA)
This example shows how to insert a hatch on a closed sketch in a drawing.
The following image demonstrates the example.
'------------------------------------------------------------
'
' Preconditions: Drawing containing a closed sketch is
open.
'
' Postconditions: Hatch is inserted.
'
'------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("Arc29",
"SKETCHSEGMENT", 0.08421725979537, 0.08635799134766, 0, False,
0, Nothing, 0)
Dim selSkSeg As SldWorks.SketchSegment
Dim selSk As SldWorks.Sketch
Set selSkSeg = SelMgr.GetSelectedObject6(1,
-1)
Set selSk = selSkSeg.GetSketch
Part.InsertHatchedFace
Dim hatchArr As Variant
Dim vobj As Variant
Dim skHatch As SldWorks.SketchHatch
hatchArr = selSk.GetSketchHatches
For Each vobj In hatchArr
Set
skHatch = vobj
skHatch.Scale2 = 4
Next vobj
End Sub