我对宏了解的也不算好,替换格式代码主要在for循环中,把替换标准代码插入里面即可。
如下:
- Sub main()
- Set swApp = Application.SldWorks
- Set Drawing = swApp.ActiveDoc
- If Drawing.GetType <> 3 Then Exit Sub
- RetoreSheetName = Drawing.GetCurrentSheet.GetName
- SheetName = Drawing.GetSheetNames
- SheetCount = Drawing.GetSheetCount
- '更改绘图标准+++++++++++++++
- Dim 本宏目录 As String
- Dim 标准文件 As String
- Dim 标准文件全名 As String
- 本宏目录 = swApp.GetCurrentMacroPathName '获得本宏文件路径+文件名
- 本宏目录 = Left(本宏目录, InStrRev(本宏目录, "")) '提出路径
- 标准文件 = Dir(本宏目录 & "*.sldstd") '搜寻标准文件
- 标准文件全名 = 本宏目录 & 标准文件
- If 标准文件 = "" Then
- MsgBox "没有绘图标准文件,请把绘图标准文件(*.sldstd类型)放至本宏同一目录!"
- Exit Sub
- End If
- '+++++++++++++++
-
- For i = 0 To SheetCount - 1
- Drawing.ActivateSheet SheetName(i)
- swTemplate = Drawing.GetCurrentSheet.GetTemplateName
- swTemplatePath = Split(swTemplate, "")
- swTemplate = swTemplatePath(UBound(swTemplatePath))
- vSheetProps = Drawing.GetCurrentSheet.GetProperties()
- Drawing.SetupSheet4 Drawing.GetCurrentSheet.GetName, 0, 0, vSheetProps(2), vSheetProps(3), vSheetProps(4), "", 1, 1, ""
- Drawing.SetupSheet4 Drawing.GetCurrentSheet.GetName, 12, 12, vSheetProps(2), vSheetProps(3), vSheetProps(4), swTemplate, 0, 0, ""
- vSheetProps = Drawing.GetCurrentSheet.GetProperties()
-
- '更改绘图标准+++++++++++++++
- If 标准文件 <> "" Then Drawing.Extension.LoadDraftingStandard 标准文件全名
- Drawing.Save2 Silent
- '+++++++++++++++
-
- Next
- Drawing.ActivateSheet RetoreSheetName
- End Sub
复制代码
|