Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Spell Check all Sheets

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
2307 Views, 7 Replies

Spell Check all Sheets

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

 

7 REPLIES 7
Message 2 of 8
PhillipM
in reply to: Anonymous

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.

Message 3 of 8
Anonymous
in reply to: PhillipM

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

Message 4 of 8
PhillipM
in reply to: Anonymous

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

Message 5 of 8
Anonymous
in reply to: PhillipM

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?

Message 6 of 8
augusto.goncalves
in reply to: Anonymous

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



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 7 of 8
Anonymous
in reply to: Anonymous

Hi,

 

did you have any luck with this macro?

 

thanks

hisham

Message 8 of 8
matthew_taylor
in reply to: Anonymous

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?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community