2017-08-25 79 views
0

这是我第一次写宏,所以我不确定这个错误是什么意思或如何解决它。任何人都可以提醒我吗?任何帮助,将不胜感激。我想说我已经尝试了一些解决方案,但正如我所说,这是我第一次不知道该怎么尝试。SharpDevelop中的宏错误 - 未声明

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

我没有在VB中工作,但在C#宏中,我不得不使用this.ActiveUIDocument.Document来获取活动文档。

Dim currentDoc As Document = this.ActiveUIDocument.Document 

也许'我'没有被宣布? 也只是注意到你打算遍历一个视图集合,但它看起来像你的viewCollector是ViewSheets的元素的集合。 sheetCollector在哪里定义?