这是我第一次编写宏,因此我不确定此错误的含义或修复方法。任何人都可以建议我吗?任何帮助,将不胜感激。我想说我已经尝试了一些解决方案,但正如我所说,这是我第一次这么做,所以不确定甚至尝试什么。
Public Sub DeleteUnusedViews()
'define current document
Dim currentDoc As Document = Me.Application.ActiveUIDocument.Document
'get all views
Dim viewCollector = New FilteredElementCollector(currentDoc)
viewCollector.OfCategory(BuiltInCategory.OST_Sheets)
'create list of views to delete
Dim viewsToDelete As New List(Of View)
'loop through views and check if it's on a sheet
For Each curView As View In viewCollector
'check if view is a template
If curView.IsTemplate = False Then
'check if view can be added to sheet
If Viewport.CanAddViewToSheet(currentDoc, sheetCollector.FirstElement.Id, curView.Id) = True Then
'add view to delete list
viewsToDelete.Add(curView)
End If
End If
Next
'create transaction
Dim curTrans As New Transaction(currentDoc)
curTrans.Start("Delete unused views")
'delete views in list
For Each curViewToDelete As View In viewsToDelete
currentDoc.Delete(curViewToDelete.Id)
Next
'commit changes
curTrans.Commit
curTrans.Dispose
'alert the user
TaskDialog.Show("Deleted Views", "Deleted " & viewsToDelete.Count & " views.")
End Sub
答案 0 :(得分:0)
我没有在VB工作过,但在C#宏中我必须使用this.ActiveUIDocument.Document来获取活动文档。
Dim currentDoc As Document = this.ActiveUIDocument.Document
也许'我'未申报? 还注意到你打算迭代一组视图,但看起来你的viewCollector是一个ViewSheets元素的集合。 sheetCollector在哪里定义?