代码如下,希望不要贻笑大方才好:
- Dim swApp As SldWorks.SldWorks
- Dim swDoc As SldWorks.ModelDoc2
- Dim longstatus As Long
- Dim longwarnings As Long
- Dim PathName As String
- Dim FilePath As String
- Dim FullFileName As String
- Dim swDocName As String
- Dim swDocType As Long
- Dim fso As New Scripting.FileSystemObject
- Dim MYext As String
- Sub main()
- On Error Resume Next
- Set swApp = Application.SldWorks
- FilePath = InputBox("本程序将向指定路径下的模型文件填写“页码”属性。" & Chr(13) & "请输入或粘贴完整路径后按“确定”。")
- If FilePath = "" Then Exit Sub
- FilePath = FilePath & ""
- BatchFolder FilePath, ".SLDPRT", ".SLDASM", True
- End Sub
- '批量处理文件夹的递归过程
- Sub BatchFolder(folder As String, ext As String, ext2 As String, silent As Boolean)
- Dim swModelDocExt As ModelDocExtension
- Dim swCustProp As CustomPropertyManager
- Dim Page_Pre As String
- Dim Page_Qty As String
-
- If Right(folder, 1) <> "" Then folder = folder & ""
- ChDir (folder)
- PathName = Dir(folder)
-
- Page_Pre = InputBox("请输入页码的前缀再按“确定”,无前缀按任意键。")
- Page_Qty = 0 '页码递增基数
-
- Do Until PathName = ""
- FullFileName = folder & PathName
- MYext = Right(UCase$(PathName), 7)
-
- If MYext = ext Or MYext = ext2 Then '如果这个文件类型是所需的,就进行处理
- swDocType = Switch(MYext = ".SLDPRT", swDocPART, MYext = ".SLDDRW", swDocDRAWING, MYext = ".SLDASM", swDocASSEMBLY, True, -1)
- Set swDoc = swApp.OpenDoc6(FullFileName, swDocType, swOpenDocOptions_Silent, "", longstatus, longwarnings)
- Set swDoc = swApp.ActiveDoc
-
- swDocName = Mid(swDoc.GetPathName, InStrRev(swDoc.GetPathName, "") + 1)
- swDocName = Left(swDocName, InStrRev(swDocName, ".") - 1)
-
- Page_Qty = Page_Qty + 1 '页码递增基数+1
- swDoc.DeleteCustomInfo2 "", ("底图张次")
- swDoc.AddCustomInfo3 "", ("底图张次"), 30, Page_Pre & Page_Qty
- swDoc.Save '保存
-
- swApp.CloseDoc swDoc.GetTitle '关闭文件
-
- Set swDoc = Nothing
- End If
- PathName = Dir
- Loop
-
- '如果有子文件夹,进行递归处理
- ' Dim myFolder As folder
- ' Dim mySub As folder
- '
- ' Set myFolder = fso.GetFolder(folder)
- ' For Each mySub In myFolder.SubFolders
- ' BatchFolder mySub.Path, ext, ext2, silent
- ' Next
- End Sub
复制代码
|