18 Replies Latest reply on Jul 20, 2017 11:05 AM by Matt Bieringer

    Autonumbering Based on Operation

    Matt Bieringer

      Hello all,

      I am kind of stumped. I have started to make a macro that will number our op sheets based on operation number. I can currently count each op sheet which and the macro will start back at one when the operation number changes, but I cant seem to figure out how to get it to count the total number of sheets per operation then do the individual number.

      Sub main()
          Dim swApp           As SldWorks.SldWorks
          Dim swModel         As SldWorks.ModelDoc2
          Dim swDrawing       As SldWorks.DrawingDoc
          Dim swSelMgr        As SldWorks.SelectionMgr
          Dim swNote          As SldWorks.Note
          Dim swView          As SldWorks.View
          Dim swSheet         As SldWorks.Sheet
          Dim swAnno          As SldWorks.Annotation
          Dim swSelObj            As Object
          Dim SheetCount, e, k, t As Integer
          Dim i, j, x, y          As Integer
          Dim strop               As String
          Dim strop2              As String
          Dim descriptionText     As String
          Dim SheetNames()        As String
          Dim sheets(0)           As Long
          Dim foundNote           As Boolean
          Dim ret                 As Boolean
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swDrawing = swModel
          SheetNames = swDrawing.GetSheetNames
          swDrawing.ActivateSheet SheetNames(0)
          SheetCount = swDrawing.GetSheetCount
          If swApp.ActiveDoc.GetType <> swDocDRAWING Then
              swApp.SendMsgToUser2 "This Macro Is Only For Use On Drawing Documents!", swMbWarning, swMbOk
          End If
      t = 1
      For e = 1 To SheetCount
      strop2 = strop
          If e > 1 Then swDrawing.SheetNext
              Set swView = swDrawing.GetFirstView
              Set swNote = swView.GetFirstNote
              Do While Not swNote Is Nothing
                  If (swNote.GetName = "DetailItem32") Then
                      foundNote = True
                      strop = swNote.GetText
                  End If
                  Set swNote = swNote.GetNext
              t = t + 1
          If strop2 <> strop Then t = 1
          swApp.SendMsgToUser ("OP #" & strop & " : " & t)
          Next i
      Next e
      swDrawing.ForceRebuild3 True
      End Sub