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在哪裏定義?