AnsweredAssumed Answered

Hatch Override Layer & Color macro

Question asked by Wojciech Pogorzelski on Oct 30, 2019
Latest reply on Nov 5, 2019 by Deepak Gupta

I was able to modify the macro posted here:

to the point so it works on every view in a drawing sheet resetting the Hatch colour to default and moving it to defined layer:

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

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View

Dim swSketch As SldWorks.Sketch
Dim swSketchHatch As SldWorks.SketchHatch
Dim vSketchHatch As Variant
Const ToLayerHatch As String = "Kreskowanie"

Dim m As Long
Dim longstatus As Long, longwarnings As Long
Option Explicit

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView


While Not swView Is Nothing
Set swSketch = swView.GetSketch

vSketchHatch = swSketch.GetSketchHatches


If Not IsEmpty(vSketchHatch) Then
For m = 0 To UBound(vSketchHatch)
Set swSketchHatch = vSketchHatch(m)
swSketchHatch.Color = -1 'color = default
swSketchHatch.Layer = ToLayerHatch
Next m
End If


' Get next drawing view
Set swView = swView.GetNextView


End Sub

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

Unfortunatelly it works only on a Hatch added manually to a surface.

It doesn't work on a section-cut views at all.

Any idea on what to add so it would work on section-cut views as well?