- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to write an addin that will cycle through all of the views (open or not) spell check them and then close all the views with exception of the original view. Below is the code I've got to date, I can run the spell check on the first view but as soon as it swtiches to the next view it throws an error.
Public Function Execute(ByVal cmdData As ExternalCommandData, ByRef msg As String, ByVal elemSet As ElementSet) As Result Implements IExternalCommand.Execute
_cachedCmdData = cmdData
Try
'Dim uiapp As UIApplication = cmdData.Application
''TODO: add your code below.
MsgBox("Running Spell Check on **ALL** Views")
'collect inital view to restore after spell check
Dim actView As Autodesk.Revit.DB.View = CachedUiApp.ActiveUIDocument.ActiveView
Dim actViewID = actView.Id
'collect all views
Dim views As List(Of ElementFilter) = New List(Of ElementFilter)
views.Add(New ElementClassFilter(GetType(View3D)))
views.Add(New ElementClassFilter(GetType(ViewDrafting)))
views.Add(New ElementClassFilter(GetType(ViewPlan)))
views.Add(New ElementClassFilter(GetType(ViewSection)))
Dim filter As LogicalOrFilter = New LogicalOrFilter(views)
Dim col As FilteredElementCollector
col = New FilteredElementCollector(CachedDoc)
col.WhereElementIsNotElementType()
col.WherePasses(filter)
'parse through views and spell check each one
For Each CurView As Autodesk.Revit.DB.View In col
'MsgBox(CurView.ViewName)
If CurView.IsTemplate = False Then
CachedUiApp.ActiveUIDocument.ActiveView = CurView
CachedUiApp.PostCommand(RevitCommandId.LookupCommandId("ID_CHECK_SPELLING"))
'RaiseEvent <test></test> uiapp.Idling = New EventHandler((IdlingEventArgs), (Onidle()))
End If
Next
'restore intial view and close all others
Dim openViews = CachedUiApp.ActiveUIDocument.GetOpenUIViews()
For Each openView As Autodesk.Revit.UI.UIView In openViews
If openView.ViewId <> actViewID Then
openView.Close()
End If
Next
Return Result.Succeeded
Catch ex As Exception
msg = ex.ToString()
Return Result.Failed
End Try
End Function
Here's the Error I get:
Autodesk.Revit.Exceptions.InvalidOperationException: Revit does not support more than one command are posted.
at Autodesk.Revit.UI.UIApplication.PostCommand(RevitCommandId commandId)
at RevitSpellCheck.SpellCheck.Execute(ExternalCommandData cmdData, String& msg, ElementSet elemSet) in C:\Users\BWebb\Documents\Visual Studio 2010\Projects\RevitSpellCheck\RevitSpellCheck\SpellCheck.vb:line 106
Any suggestions are greatly appreciated.
Solved! Go to Solution.