PostCommand Close command.

PostCommand Close command.

Anonymous
Not applicable
4,922 Views
4 Replies
Message 1 of 5

PostCommand Close command.

Anonymous
Not applicable

I'm want to learn how to use the post command correctly.  My attempt is to show a Sync display dialog.  I can use it once but after the second try I get an exemption message : "Revit does not support more than one command are posted".  How can I ensure that when the window from SynchronizeAndModifySettings is done I finish my post? 

 

The method is very simple. 

public void SynchronizeWithCentralWindow(Document doc, UIApplication uiapp)
        {
            var syncCmd = RevitCommandId.LookupPostableCommandId(PostableCommand.SynchronizeAndModifySettings);
            try
            {
                uiapp.PostCommand(syncCmd);

            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }

thank you. 

0 Likes
Accepted solutions (1)
4,923 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

I've spent half my Sunday looking at this problem and what I have discovered is that I have a first command running which opens my UI and creates a csv file.  The second command is launched from a FileSystemWatcher when csv file is edited which attempts to run my PostCommand during the same session of my add-in.  

 

The trick will be to closing my first Post when my file is edited from my FileSystemWatcher event is triggered and starting a new command.  I'm not sure if this is the issue but I feel I've got a place to start. It works the first time because it creates the file and uses the PostCommand, however,  the second time it's fired when the file is edited using FileSystemWatcher but the first post is started.

 

Any thoughts? 

0 Likes
Message 3 of 5

jeremytammik
Autodesk
Autodesk

Dear Danny,

 

Thank you for your query.

 

The method of choice to use to determine that Revit has terminated execution of a command is to subscribe to the Idling event.

 

When your Idling event handler is called, you know that Revit has completed processing of all pending tasks and is ready for (new) action. You can then unsubscribe again from the Idling event, right there in the event handler.

 

Lots of samples are discussed in The Building Coder topic group 

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 5

BobbyC.Jones
Advocate
Advocate
Accepted solution

I concur with Jeremy on the Idling event.  I even wrote a wrapper around it to make using it more friendly, https://forums.autodesk.com/t5/revit-api-forum/a-question-about-suppressing-warning-messages-in-revi....

 

The Idling event wrapper is the RevitCommandEndedMonitor class.  You could use it like this:

 

public void SynchronizeWithCentralWindow(Document doc, UIApplication uiapp)
{
    var syncCmd = RevitCommandId.LookupPostableCommandId(PostableCommand.SynchronizeAndModifySettings);

var commandMonitor = new RevitCommandEndedMonitor(uiapp);
commandMonitor.CommandEnded += OnCommandEnded;
uiapp.PostCommand(syncCmd); }


private void OnCommandEnded(object sender, EventArgs eventArgs)
{
//continue processing after the syncCmd has ended
}

 

 

 

 

--
Bobby C. Jones
Message 5 of 5

ChengboZhang
Enthusiast
Enthusiast

It looks very concise~
Awesome

0 Likes