这将自动删除特定目录中的所有PDF,在本例中为E:\Temp ;将其更改为存储PDF的项目文件夹
- [color=red]If Len(Dir("E:\Temp\*.pdf")) 0 Then[/color] [color=green]' Checks to see if there are any PDFs in E:Temp[/color]
- [color=red]fso.DeleteFile "E:\Temp\*.pdf", True[/color] [color=green]' If there are, delete them[/color]
- [color=red]End If[/color]
该行将自动覆盖任何可能与所复制PDF同名的PDF
- fso.CopyFile colHyps.Item(0).URL, "E:\Temp", True
当你把这一切放在一起,你会得到这个… - Option Explicit
- Public Sub Main()
- Dim objBlock As AcadBlockReference
- Dim objEnt As AcadEntity
- Dim colHyps As AcadHyperlinks
- Dim fso As FileSystemObject
-
- Set fso = New FileSystemObject
- [color=red]If Len(Dir("E:\Temp\*.pdf")) 0 Then[/color] [color=green]' Checks to see if there are any PDFs in E:Temp[/color]
- [color=red]fso.DeleteFile "E:\Temp\*.pdf", True[/color] [color=green]' If there are, delete them[/color]
- [color=red]End If[/color]
-
- For Each objEnt In ThisDrawing.ModelSpace
- If TypeOf objEnt Is AcadBlockReference Then
- Set objBlock = objEnt
- Set colHyps = objBlock.Hyperlinks
- On Error Resume Next ' In case we encounter any blocks that DON'T have hyperlinks
- [color=red]fso.CopyFile colHyps.Item(0).URL, "E:\Temp", True[/color] [color=green]' replace E:\Temp\ with your project directory[/color]
- [color=green]' The TRUE option will automatically overwrite any existing files with the same name[/color]
- End If
- Next objEnt
-
- Set fso = Nothing
- End Sub
|