' Delete all dimensions from current document ' ' Author: Kyle Kershaw ' Organization: Engineering Geometry Systems ' Date: 10/21/2003 ' Copyright (c) 2003, Engineering Geometry Systems ' ' General Description ' ' This macro iterates through each model object and if it is a dimension, selects it. ' After all dimensions are selected, The selected items are deleted. ' ' Creates a CAD toolbar if one does not exist and populates it with a DeleteDimensions button ' Removes button/deletes bar if empty when macro is unloaded ' Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long,lParam As Long) As Long Public Sub DeleteDimensions Dim models As FMModels Set models = Application.ActiveDocument.Models Dim model As FMModel For Each model In models If (model.ModelType = eMT_Dim) Then model.Select(True, False) End If Next model DeleteSelectedItems End Sub Private Sub DeleteSelectedItems( ) Const ID_FEATURES_DELETE = 32822 Const WM_COMMAND = &H0111 Dim doc As MFGDocument Dim hwnd As Long ,wMsg As Long, wParam As Long, lParam As Long Set doc = Application.ActiveDocument hwnd = doc.ActiveWindow.HWnd wMsg = WM_COMMAND wParam = ID_FEATURES_DELETE lParam = 0 SendMessage( hwnd, wMsg, wParam, lParam) End Sub ' ' Add a toolbar and buttons upon loading of this addin into FeatureCAM. ' Private Sub AddIn_OnConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) ' Bar name Button name Button face ID MakeButtonAndBar "CAD", "DeleteDimensions", 37 End Sub ' ' remove button or hide toolbar if add-in deselected ' Private Sub AddIn_OnDisConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) HideDeleteBarButton "CAD", "DeleteDimensions" End Sub Private Sub MakeButtonAndBar(ByVal bar_name As String, ByVal button_name As String, _ ByVal button_id As Integer) Dim bars As FMCmdBars, bar As FMCmdBar, ctrl As FMCmdBarBtn Set bars = Application.CommandBars Set bar = bars(bar_name) If bar Is Nothing Then Set bar = bars.Add(bar_name) Else bar.Visible = True End If Set ctrl = bar.Controls(button_name) If ctrl Is Nothing Then Set ctrl = bar.Controls.Add( ,,button_name) ctrl.FaceId = button_id bar.Visible = True End If End Sub Private Sub HideDeleteBarButton(ByVal bar_name As String, ByVal button_name As String) Dim bars As FMCmdBars, bar As FMCmdBar, ctrl As FMCmdBarCtrl Set bars = Application.CommandBars Set bar = bars(bar_name) If Not bar Is Nothing Then Set ctrl = bar.Controls(button_name) If Not ctrl Is Nothing Then If bar.Controls.Count > 1 Then ctrl.Delete Else bar.Visible=False End If End If End If End Sub