I'm trying to create a macro that will spell check all sheets in a project. I have what I think should work, but I get an error that says something like "revit does not support more than one posted command". I think the problem might be that the post command has not finished when it's already trying to change the activeview to the next sheet. Any ideas? I thought this was going to be an easy macro for me to start with.
public void theMacro() { Document doc = this.ActiveUIDocument.Document; UIApplication application = this; FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection<Element> collection = collector.OfClass(typeof(ViewSheet)).ToElements(); RevitCommandId id = RevitCommandId.LookupCommandId("ID_CHECK_SPELLING"); foreach (Element element in collection) { if (!element.HasPhases()) { //this is how I'm getting sheets - probably a better way application.ActiveUIDocument.ActiveView.Equals(element); application.CreateAddInCommandBinding( id ); application.PostCommand(id); } }
}
Unfortunately you can only call a postable command at the end of your external command. You can not run it within a loop like that.
Not using PostCommand.
From the API Help file...
Command posting
The method
posts a command to Revit. Revit will invoke it when control returns from the current API context. Only certain commands can be posted using this method:
So Revit will not complete the command untill your code/macro has finshed. In your case you have that being called in a loop so first time through it posts the command and waits for your macro to finish, then it tries to post again in the next loop. That is where it is having issues.
I hope that explains it?
Cheers
phillip
Yes, that helps. Thank you. But I guess I'm trying to figure out if there is another way to do it.
I'm sure C# has some kind of built-in spell check capability but that would be a crazy amount of work. I would basically have to recreate the whole check spelling window (including ignore, ignore all, change to, etc) that Revit currently uses (no thanks!).
It seems like there has to be a way to do this. Is there any other way to access Revit's spell check without using PostCommand? What if I did this without using a macro and made an add-in instead?
Hello,
In fact this is relatively easy to do. I'll mix some quasi-code and some proper code:
dim elementIds as icollection(of elementid)=new list (of elementid)
dim allSheets as ienumerable(of viewsheet)=new filteredelementcollector (doc).ofclass(gettype(viewsheet)).cast(of viewsheet)
For each sheet as viewsheet in allSheets
dim allText as filteredelementcollector =new filteredelementcollector (doc, sheet.id).ofcategory(BuiltInCategory.OST_TextNotes)
'add to allText to elementIds
next
m_docUi.Selection.SetElementIds(elementIds)
Dim spellCheck As UI.RevitCommandId = _ UI.RevitCommandId.LookupPostableCommandId(UI.PostableCommand.CheckSpelling) If appUi.CanPostCommand(spellCheck) Then appUi.PostCommand(spellCheck) End If
Be aware that there is (what I would consider a bug) where the user could enter an infinite loop and Revit will not return focus to the user.
I have described it in a Revit Idea, along with some other thoughts:
https://forums.autodesk.com/t5/revit-ideas/spellcheck/idi-p/6688376
Can't find what you're looking for? Ask the community or share your knowledge.