此程序需要改进.
不知你是否打开过"减肥"过后的图形,是空白图形.
由于On Error Resume Next
和缺少On Error GoTo 0语句,后续错误将被忽略.
- Private Sub cmddo_click()
- Size = 0
- On Error Resume Next
- Set acadapp = GetObject(, "AutoCAD.application")
- If Err Then
- Err.Clear
- Set acadapp = CreateObject("AutoCAD.application")
- If Err Then
- MsgBox Err.Description
- Exit Sub
- End If
- End If
- Set acaddoc = acadapp.activedocument
- For i = 0 To File1.ListCount - 1 Step 1
- If File1.Selected(i) Then '对列表文件进行处理
- a = Path + File1.List(i)
- File1.Selected(i) = False
- acaddoc.apen a '拼写错误,acaddoc.open也会导致错误,但都被忽略
- acaddoc.activeviewport.zoomall
- acaddoc.purgeall
- acaddoc.purgeall
- acaddoc.purgeall
- acaddoc.purgeall
- acaddoc.purgeall
- MkDir "d:\jianfei" '如果存在,将会产生错误
- acaddoc.saveas "d:\jianfei" & File1.List(i) & ".dwg"'保存的不一定是a
- Size = Size + FileLen("d:\jianfei" & File1.List(i) & ".dwg")
- End If
- Next i
- Text2.Text = Str(Size)
- acadapp.quit'如果是用户正在使用,也将提示退出.
- End Sub
以下是改写后的代码:
- Private Sub cmddo_click()
- Size = 0
- On Error Resume Next
- Set AcadApp = GetObject(, "AutoCAD.application")
- If Err Then
- NewApp = True
- Err.Clear
- Set AcadApp = CreateObject("AutoCAD.application")
- If Err Then
- MsgBox Err.Description
- Exit Sub
- End If
- End If
- On Error GoTo 0 '关闭错误陷井,以便调试后续语句.
- For i = 0 To File1.ListCount - 1 Step 1
- If File1.Selected(i) Then '对列表文件进行处理
- a = Path + File1.List(i)
- File1.Selected(i) = False
- AcadApp.documents.open a
- For Each CurDoc In AcadApp.documents
- If CurDoc.FullName = a Then
- AcadApp.zoomall
- CurDoc.PurgeAll
- CurDoc.PurgeAll
- CurDoc.PurgeAll
- CurDoc.PurgeAll
- CurDoc.SaveAs Dir1.Path & "S_" & File1.List(i)
- CurDoc.Close
- Size = Size + FileLen(Dir1.Path & "S_" & File1.List(i))
- End If
- Next CurDoc
- End If
- Next i
- Text2.Text = Str(Size)
- If NewApp = True Then AcadApp.quit
- Set AcadApp = Nothing
- End Sub
|