Spell Check all Sheets

Spell Check all Sheets

Anonymous
Not applicable
3,058 Views
7 Replies
Message 1 of 8

Spell Check all Sheets

Anonymous
Not applicable

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);
	     }
	}
}

 

0 Likes
3,059 Views
7 Replies
Replies (7)
Message 2 of 8

PhillipM
Advocate
Advocate

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.

0 Likes
Message 3 of 8

Anonymous
Not applicable

Are you saying there is no way to automate spell check for every sheet in a project? 

0 Likes
Message 4 of 8

PhillipM
Advocate
Advocate

Not using PostCommand.

 

From the API Help file...

 

Command posting

The method

  • UIApplication.PostCommand()

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

0 Likes
Message 5 of 8

Anonymous
Not applicable

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?

0 Likes
Message 6 of 8

augusto.goncalves
Alumni
Alumni
Agree with Phillip, cannot see any other Revit API to do this...
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 7 of 8

Anonymous
Not applicable

Hi,

 

did you have any luck with this macro?

 

thanks

hisham

0 Likes
Message 8 of 8

matthew_taylor
Advisor
Advisor

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


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes