I have this m
acro “Hide all in parts and assembly” it’s supposed to hide all sketches and planes and collapse the tree and move the freezebar to the end. It works fine in most cases but there are 2 unwanted behaviours I’d like to correct.
1) It does not hide the visible sketch of a structural member.
2) It flattens some (!) sheet metal parts.
Does anyone know what might cause this? And how to fix it offcourse? I tried some things but I’m not well versed in coding and macro’s.
(posted in full for reference)
Code: Select all
'Hide All in Parts and Assembly.swp -------------07/12/14
'Description: Macro to hide all planes, axis, co-ordinate system, 2d-3d sketches, origin in the active part/assembly file and set FreezeBar to end.
'Precondition: Any active part/assembly file to be saved.
'Postcondition: Active part/assembly will be saved with FreezeBar enabled and set to end with the specified entities set to *hidden.
' Macro is based on the requirements by Ruairi Mulligan: https://forum.solidworks.com/message/438806#438806
'*Hidden means as right-clicking an item and selecting Hide on the shortcut menu.
' Please back up your data before use and USE AT OWN RISK
' This macro is provided as is. No claims, support, refund, safety net, or
' warranties are expressed or implied. By using this macro and/or its code in
' any way whatsoever, the user and any entities which the user represents,
' agree to hold the authors free of any and all liability. Free distribution
' and use of this code in other free works is welcome. If any portion of
' this code is used in other works, credit to the authors must be placed in
' that work within a user viewable location (e.g., macro header). All other
' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited
' without the expressed written consent by the authors. Use at your own risk!
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta (http://gupta9665 . com/)
' -------------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim nStart As Single
Dim i As Long
Dim bShowConfig As Boolean
Dim bRebuild As Boolean
Dim bRet As Boolean
Dim swFeat As SldWorks.Feature
Dim nErrors As Long
Dim nWarnings As Long
Sub main()
On Error Resume Next
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'Check if there is any Part or Assembly file
If swModel Is Nothing Or swModel.GetType = 3 Then
MsgBox "Please open a Part/Assembly first and then try again!!"
Exit Sub
End If
' Enabling the Freeze bar
swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swUserEnableFreezeBar, True
'Traverse All configuration Features and hiding the references geometries, origin and sketches
vConfNameArr = swModel.GetConfigurationNames
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
bShowConfig = swModel.ShowConfiguration2(sConfigName)
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing
'Hiding 2d sketch, 3d sketch and Origin
If "ProfileFeature" = swFeat.GetTypeName Or "3DProfileFeature" = swFeat.GetTypeName Or "OriginProfileFeature" = swFeat.GetTypeName Then
bRet = swFeat.Select2(False, 0): Debug.Assert bRet
swModel.BlankSketch
End If
'Hiding planes, axis, co-ordinate system
If "RefPlane" = swFeat.GetTypeName Or "RefAxis" = swFeat.GetTypeName Or "CoordSys" = swFeat.GetTypeName Then
bRet = swFeat.Select2(False, 0): Debug.Assert bRet
swModel.BlankRefGeom
End If
Set swFeat = swFeat.GetNextFeature
Loop
Next i
swModel.ClearSelection2 True
swModel.ForceRebuild3 (False) 'Rebuild the model
swModel.ShowNamedView2 "*Isometric", -1 ' Set the Isometric View
swModel.ViewZoomtofit2 ' Zoom to fit
swModel.Extension.RunCommand swCommands_Collapseallitems_Tree, "" ' Collapse Feature Tree
swModel.FeatureManager.EditFreeze SwConst.swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", True ' Move freeze bar to end of the feature tree
swModel.Save3 swSaveAsOptions_Silent, nErrors, nWarnings 'Save the file
MsgBox swModel.GetTitle & " is ready to Check-In!!" 'File ready to check in
End Sub