forum.featurecam.com
http://forum.featurecam.com/

Addon - Hide/Show/Delete Unused Curves
http://forum.featurecam.com/viewtopic.php?f=11&t=1663
Page 1 of 1

Author:  vf1kf [ Mon Jul 15, 2013 7:30 pm ]
Post subject:  Addon - Hide/Show/Delete Unused Curves

I made this addin in response to this post on the site: viewtopic.php?f=10&t=1656&p=6417#p6417
Most of it was created by cutting and pasting code from existing addins included with the featurecam install. It could be cleaned up with some case statements, but is perfectly functional as is.

It creates a toolbar button that opens a dialog with the options to show, hide or delete all unused curves.

Here is the addin for your perusal:

Code:
'#Language "WWB-COM"

Option Explicit
Sub HSD_Unused_Curves



    Dim result As Long

   Begin Dialog UserDialog 370,200, "Unused Curves Dialog"
        Text 10,10,350,15,"What would you like to do with all your unused curves?"
      PushButton   85,  40, 200,  30,   "Show"
      PushButton   85,  80, 200,  30,   "Hide"
      PushButton   85,  120, 200,  30,   "Delete"
        CancelButton 85,160,200,30
    End Dialog
    Dim dlg As UserDialog

    result = Dialog(dlg)

   If result = 0 Then
      Exit Sub
   End If
   If result = 1 Then
      Show_Unused_Curves
   End If
   If result = 2 Then
      Hide_Unused_Curves
   End If
   If result = 3 Then
      Delete_Unused_Curves
   End If

End Sub


Private Sub Hide_Unused_Curves
   Dim doc As FMDocument
    Set doc = ActiveDocument
   Dim c As FMCurve

    For Each c In doc.curves
        If c.IsPartOfFeature = False Then
            c.Visible = False
        End If
    Next
End Sub
Private Sub Delete_Unused_Curves
   Dim doc As FMDocument
    Set doc = ActiveDocument
   Dim c As FMCurve
   Dim result As Long

   Begin Dialog UserDialog 340,60, "Confirmation Dialog"
       Text 10,10,330,15,"Are you sure you want to delete all unused curves?"
        OKButton 120,35,40,20
        CancelButton 180,35,60,20
    End Dialog
    Dim dlg As UserDialog

    result = Dialog(dlg)

    If result <> -1 Then
       HSD_Unused_Curves
       Exit Sub
      End If

       For Each c In doc.curves
        If c.IsPartOfFeature = False Then
            c.Delete
            Exit Sub
        End If
    Next
End Sub
Private Sub Show_Unused_Curves
   Dim doc As FMDocument
    Set doc = ActiveDocument
   Dim c As FMCurve

    For Each c In doc.curves
        If c.IsPartOfFeature = False Then
            c.Visible = True
        End If
    Next
End Sub

' Add a toolbar button for this macro upon loading of this addin into FeatureCAM.
Private Sub OnLoadAddin()
   MakeButtonAndBar "Macros", "HSD_Unused_Curves", 38
End Sub

' Remove the toolbar button for this macro upon unloading of this addin from FeatureCAM.
Private Sub OnUnloadAddin()
   HideDeleteBarButton "Macros", "HSD_Unused_Curves"
End Sub
Private Sub AddIn_OnConnect(ByVal flags As FeatureCAM.tagFMAddInFlags)
   OnLoadAddin
End Sub

Private Sub AddIn_OnDisConnect(ByVal flags As FeatureCAM.tagFMAddInFlags)
   OnUnloadAddin
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
            ctrl.Delete
            bar.Visible=False
         End If
      End If
   End If
End Sub


Attachments:
Hide Show Delete Unused Curves.zip [1.12 KiB]
Downloaded 474 times

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/