AnsweredAssumed Answered

Freeze/unfreeze all part features macro help

Question asked by Adam Doerr on Nov 6, 2018
Latest reply on Nov 6, 2018 by Deepak Gupta

I'm trying to create a macro that will either freeze or unfreeze all features in a part, but I'm getting stuck and looking for some guidance. I'm pretty out of date with my programming skills, so I'm hoping someone can help me out. Through the SW online API help and examples from the forums, I've been able to create very simple macros that work for freeze and unfreeze separately (see below for the code), but not all in one macro. What I'd really like is the macro to somehow check if the part's features are already frozen and if so then unfreeze all features, if not it would just freeze all features. Another issue I'm having is after I run the freeze version of the macro, the Feature Manager scrolls to the right a bit and has the last feature selected. I was able to find the command to deselect the feature, but not scroll the menu back over leftwards so the user can see the feature icons.

 

Here's a quick step by step breakdown of what I'm after:

1. Part is open in Solidworks

2. User runs the macro through a keyboard shortcut

3. Macro checks for frozen features, if it finds them then it unfreezes all features and ends.

4. If it does not find frozen features it freezes all features, clears the last feature's selection, scrolls the Feature Manager back to the left, and ends.

 

Here's what I have so far:

Dim swApp As Object

Dim Part As Object

Dim swModel As SldWorks.ModelDoc2

Dim boolstatus As Boolean

 

Sub main()

 

Set swApp = Application.SldWorks

swApp.SetUserPreferenceToggle swUserEnableFreezeBar, True

Set Part = swApp.ActiveDoc

 

If Part.GetType <> swDocPART Then

MsgBox "Incorrect document type! This macro only works on parts."

Exit Sub

End If

 

boolstatus = Part.FeatureManager.EditFreeze(swMoveFreezeBarToEnd, "", True)

Part.ClearSelection2 True

 

'Here's the command I've found that will unfreeze all of the features:

'boolstatus = Part.FeatureManager.EditFreeze(swMoveFreezeBarToTop, "", True)

 

End Sub

Outcomes