Rob Edwards

Toggle 'Marked For Drawing' Macro

Discussion created by Rob Edwards on Jan 8, 2019
Latest reply on Jan 9, 2019 by Ray McHugh

* I'm currently re-organising all my macros and I found a few I'd forgotten about.  So I'll try and tidy them up a bit and post them.

 

' SOLIDWORKS
' This macro will flip (toggle) 'Marked for Drawing' on all your dimensions.
' Works in a part file or an assembly but doesn't go down into your components
' Warning - I'm a joiner not a programmer, so use at your own risk!
' https://forum.solidworks.com/people/1-2SZI4TC

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeature As SldWorks.Feature
Dim swDisplayDimension As SldWorks.DisplayDimension
Dim swDimension As SldWorks.Dimension
Dim colFeaturesWithDims As Collection
Dim colDispDims As Collection

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    Set colFeaturesWithDims = New Collection
    Set swFeature = swModel.FirstFeature
    
    Do While Not swFeature Is Nothing
        If HasDisplayDimensions(swFeature) Then
            On Error Resume Next 'we don't care if already in the collection
                Call colFeaturesWithDims.Add(Item:=swFeature, key:=swFeature.Name)
            On Error GoTo 0
        End If
        Set swFeature = swFeature.GetNextFeature
    Loop

    Dim i As Integer
    For i = 1 To colFeaturesWithDims.Count
        Debug.Print colFeaturesWithDims(i).Name
    Next
    
    Set colDispDims = New Collection
    For i = 1 To colFeaturesWithDims.Count
        Set swFeature = colFeaturesWithDims(i)
        Set swDisplayDimension = swFeature.GetFirstDisplayDimension

        Do While Not swDisplayDimension Is Nothing
            On Error Resume Next 'we don't care if already in the collection
                Call colDispDims.Add(Item:=swDisplayDimension, key:=swDisplayDimension.GetDimension.FullName)
            On Error GoTo 0
            Set swDisplayDimension = swFeature.GetNextDisplayDimension(swDisplayDimension)
        Loop
    Next
   
    For i = 1 To colDispDims.Count
        Set swDisplayDimension = colDispDims(i)
        With swDisplayDimension
            Debug.Print .GetNameForSelection, .MarkedForDrawing
           .MarkedForDrawing = IIf(.MarkedForDrawing, False, True)
        End With
    Next
    
    Call swApp.SendMsgToUser2(colDispDims.Count & " dimension" & IIf(colDispDims.Count = 1, "", "s") & " flipped", swMbInformation, swMbOk)
   
End Sub

Private Function HasDisplayDimensions(swFeature As SldWorks.Feature) As Boolean
    HasDisplayDimensions = Not swFeature.GetFirstDisplayDimension Is Nothing
End Function

Outcomes