Disable all Crosshatches in drawing section view

Programming and macros
User avatar
mp3-250
Posts: 630
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 704
x 347

Disable all Crosshatches in drawing section view

Unread post by mp3-250 »

I have been trying to disable the section hatching for every component in a section view.
Disabling the material hatching and setting the area fill to none.

Looping every single face in the view seems to take forever to process a single face...is there a better way to achieve this?

Sample code from the help I modified just select a section in a assembly and start the macro.

Code: Select all


'-----------------------------------------------------------------
' 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 face hatch 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 vFaceHatch As Variant
    Dim swFaceHatch As SldWorks.FaceHatch
    Dim swFace As SldWorks.Face2
    Dim i As Long
    Dim temp As Boolean
    
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swView = swSelMgr.GetSelectedObject6(1, -1)
    Debug.Print "View   = " & swView.Name
    Debug.Print "  Type = " & swView.Type
    vFaceHatch = swView.GetFaceHatches
    If IsEmpty(vFaceHatch) Then
        Debug.Print "  No face hatches in selected view."
        Exit Sub
    End If
    Debug.Print "  Number of face hatches in this view = " & (UBound(vFaceHatch) + 1)
    If Not IsEmpty(vFaceHatch) Then
        Debug.Print "  Face hatches ="
        Debug.Print ""
        For i = 0 To UBound(vFaceHatch)

            Set swFaceHatch = vFaceHatch(i)
            ' Get face hatch data            
               Debug.Print "Current Material crosshatch = " & swFaceHatch.UseMaterialHatch
                              Debug.Print "Current Material crosshatch = " & swFaceHatch.UseMaterialHatch
               Set swFace = swFaceHatch.Face
               swFace.Select2 True, 0
               swFaceHatch.UseMaterialHatch = False
               swFaceHatch.HatchType = 1
        Next i

    End If
End Sub

by mp3-250 » Fri Apr 05, 2024 2:27 am
The hatching triggers a view update if automatic view update is ON

disabling view autoupdate until the loop finish greatly speed up the process,
Less than 10 seconds seconds to process 250 faces

Code: Select all

Dim swDrawing As SldWorks.DrawingDoc
Set swDrawing = swModel
swDrawing.AutomaticViewUpdate = False
Go to full post
User avatar
mp3-250
Posts: 630
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 704
x 347

Re: Disable all Crosshatches in drawing section view

Unread post by mp3-250 »

The hatching triggers a view update if automatic view update is ON

disabling view autoupdate until the loop finish greatly speed up the process,
Less than 10 seconds seconds to process 250 faces

Code: Select all

Dim swDrawing As SldWorks.DrawingDoc
Set swDrawing = swModel
swDrawing.AutomaticViewUpdate = False
Post Reply