API code for all languages (when possible) with TaskDialog Ids and WriteJournalComment

Arnost makes a good comment below reminding us to think about how Revit and our API applications will work with non-English versions of Revit.

Please remember that the text will not always be in English! It comes from resources and will be properly localized in foreign versions of Revit. Using the string locally is all right, but it is better to rely on Dialog Id, which should also be available (although not always is) in the event argument.

He was writing in response to the code I posted:

t.Message == "The floor/roof overlaps the highlighted wall(s). Would you like to join geometry and cut the overlapping volume out of the wall(s)?"

It would be better to avoid including the English text in the API logic, but sometimes we have no choice. Here are 5 task dialogs – 2 have a DialogId and for 3 that property is empty. And when there is no DialogId the only option is to base the comparison on the text string of the message.

‘C 02-Feb-2013 14:16:39.716; 1:< TaskDialogShowingEventArgs,The floor/roof overlaps the highlighted wall(s). Would you like to join geometry and cut the overlapping volume out of the wall(s)?,,

‘C 02-Feb-2013 14:16:21.362;   1:< TaskDialogShowingEventArgs,Would you like to attach the highlighted walls to the roof?,,

‘C 02-Feb-2013 14:15:41.234; 1:< TaskDialogShowingEventArgs,Would you like to rename corresponding views?,,

‘C 02-Feb-2013 14:21:03.890; 2:< TaskDialogShowingEventArgs,Do you want to save changes to uni2.rvt?,TaskDialog_Save_File,

‘C 02-Feb-2013 14:22:10.362; 1:< TaskDialogShowingEventArgs,You are trying to load the family Table-Dining Round w Chairs, which already exists in this project. What do you want to do?,TaskDialog_Family_Already_Exists,

Here’s the macro code to write the TaskDialog message text and id to the journal file.

private void Module_Startup(object sender, EventArgs e)
    UIApplication uiapp = new UIApplication(this.Application);
    uiapp.DialogBoxShowing += new EventHandler<DialogBoxShowingEventArgs>(taskDialogInfo);

private void taskDialogInfo(object o, DialogBoxShowingEventArgs e)
    TaskDialogShowingEventArgs t = e as TaskDialogShowingEventArgs;
    if (t != null)
        this.Application.WriteJournalComment("TaskDialogShowingEventArgs," + t.Message + "," + t.DialogId + ",",true);

In most cases it can be more convenient to show the data (t.Message and t.DialogId) in a TaskDialog, but you can’t show a TaskDialog during the DialogBoxShowing event when Revit is trying to show its own dialog box.

Using “Step Into” to look at the values in Sharp Develop usually works, but you can’t step into a function that is triggered when an event occurs.

So WriteJournalComment is a great solution in this case.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s