Drawing Labels
Posted: Tue May 16, 2023 3:16 pm
Is there a way to set the automatic Section & Detail labeling so that if I have a multi-sheet drawing, it will have labels start at "A" for each sheet in the drawing file?
Code: Select all
Const A_CHAR As Integer = 65
Const Z_CHAR As Integer = 90
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim curChar As Integer
Dim curChar2 As Integer
Dim curChar3 As Integer
'
Sub main()
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
If swDraw Is Nothing Then
MsgBox "Please open drawing document"
End
End If
Dim vSheetNames() As String
vSheetNames = swDraw.GetSheetNames
Dim sheetInd As Integer
curChar = A_CHAR
curChar2 = A_CHAR
curChar3 = A_CHAR
For sheetInd = 0 To UBound(vSheetNames)
swDraw.ActivateSheet vSheetNames(sheetInd)
Set swSheet = swDraw.Sheet(vSheetNames(sheetInd))
Dim vViews As Variant
vViews = swSheet.GetViews
Dim i As Integer
'Debug.Print UBound(vViews)
'If UBound(vViews) Is Nothing Then
' if sheet has no views skip
'Else
For i = 0 To UBound(vViews)
Dim swView As SldWorks.View
Set swView = vViews(i)
Select Case swView.Type
Case swDrawingViewTypes_e.swDrawingSectionView
Dim swSectionView As SldWorks.DrSection
Set swSectionView = swView.GetSection
Debug.Print swSectionView.GetLabel
swSectionView.SetLabel2 GetNextName
Case swDrawingViewTypes_e.swDrawingDetailView
Dim swDetailedView As SldWorks.DetailCircle
Set swDetailedView = swView.GetDetail
Debug.Print swDetailedView.GetLabel
swDetailedView.SetLabel GetNextName
End Select
Next
'End If
Next
swDraw.ForceRebuild
End Sub
Function GetNextName() As String
If curChar > Z_CHAR Then
If curChar2 > Z_CHAR Then
MsgBox ("Overflow")
End
Else
If curChar3 > Z_CHAR Then
curChar3 = A_CHAR
curChar2 = curChar2 + 1
End If
' FirstLet = curChar2
' SecondLet = curChar3
GetNextName = Chr(curChar2) & Chr(curChar3)
curChar3 = curChar3 + 1
End If
Else
GetNextName = Chr(curChar)
curChar = curChar + 1
End If
End Function
Great Thanks! I'll definitely try it out!mattpeneguy wrote: ↑Tue May 16, 2023 4:03 pm You can try the following macro when you separate the sheets out. It'll rename the views starting with A.