本帖最后由 knowbaby 于 2016-10-7 22:28 编辑
首先,原贴地址https://www.icax.org/thread-925975-2-1.html
闷大的宏中存在的问题见下
我在闷大的宏的基础上重新修改了一下解决了此问题
- Sub main()
- Dim PathName As String
- Dim SheetName() As String
- Dim ConfigName As String
- Dim SplittedPathName() As String
- Dim ModelName As String
- On Error Resume Next
- Set swApp = Application.SldWorks
- Set drawing = swApp.ActiveDoc
- If drawing Is Nothing Then
- MsgBox "请打开图纸"
- Exit Sub
- End If
- If drawing.GetType <> 3 Then Exit Sub
- SheetName = drawing.GetSheetNames
- SheetCount = drawing.GetSheetCount
- 'For i = 0 To SheetCount - 1
- ' drawing.ActivateSheet SheetName(i)
- ' Set swSheet = drawing.GetCurrentSheet
- ' swSheet.SetName "[ DISCUZ_CODE_0 ]quot; & i
- 'Next
- SheetName = drawing.GetSheetNames
- For i = 0 To SheetCount - 1 '更改图纸名称形式为 图号+配置+N个"," 方便后面重新命名
- drawing.ActivateSheet SheetName(i)
- Set swView = drawing.GetFirstView.GetNextView
- PathName = swView.GetReferencedModelName
- ConfigName = swView.ReferencedConfiguration
- SplittedPathName = Split(PathName, "")
- ModelName = SplittedPathName(UBound(SplittedPathName))
- ModelName = Left(ModelName, Len(ModelName) - 7)
- Set swSheet = drawing.GetCurrentSheet
- If ConfigName = "Default" Or ConfigName = "默认" Or ConfigName = "預設" Then
- thissheetname = ModelName
- Else
- thissheetname = ModelName & ConfigName
- End If
- swSheet.SetName thissheetname
- CurrentSheetName = swSheet.GetName
- c = 1
- While CurrentSheetName <> thissheetname
- thissheetname = thissheetname & ","
- swSheet.SetName thissheetname
- CurrentSheetName = swSheet.GetName
- c = c + 1
- Wend
-
- Next
- SheetName = drawing.GetSheetNames
- For i = 0 To SheetCount - 1 '更改同配置图纸形式为 图号+配置+(第几张图纸)
- drawing.ActivateSheet SheetName(i)
-
- Set swView = drawing.GetFirstView.GetNextView
-
- SheetName = drawing.GetSheetNames
-
- Temp = 1
- If Right(SheetName(i), 1) = "," Then
- While Right(SheetName(i), 1) = ","
- SheetName(i) = Left(SheetName(i), Len(SheetName(i)) - 1)
-
- Temp = Temp + 1
- Wend
-
- Set swSheet = drawing.GetCurrentSheet
-
- swSheet.SetName SheetName(i) & "(" & Temp & ")"
-
- Else
-
- Set swSheet = drawing.GetCurrentSheet
-
- swSheet.SetName SheetName(i) & "(" & Temp & ")"
-
- End If
-
-
- Next
- SheetName = drawing.GetSheetNames
- drawing.ActivateSheet SheetName(0)
- End Sub
复制代码 其中注释掉了闷大的$$ & i
因为一般情况下不会出现此类情况,并且如果批量零件图纸操作的时候影响运行速度 @Francis |