Prompt user to answer boolean choice using Revit API in C#
Asked Answered
G

2

5

I created a Revit plugin in C# that allow users totally new to 3D technology to choose a family, and insert it in their project. But right now the user does not have the choice between placing an object on the point anywhere or on a face. It's either one or the other. Right now my code looks like this :

bool useSimpleInsertionPoint = false; //or true
bool useFaceReference = true; //or false
if (useSimpleInsertionPoint)
{
//my code for insertion on point here
}
if (useFaceReference)
{
//my code for face insertion here
}

What I would like to do is ask the user what does he want to do. Does TaskDialog.Show would do the trick or is it something else ?

Thanks in advance.

Guglielmo answered 3/3, 2015 at 10:18 Comment(0)
W
5

Vincent's approach is good. The one thing that I like a little bit more is to use the CommandLink options with TaskDialog. This gives you the "big option" buttons to pick from, provides both an answer as well as an optional line of "explanation" about each answer.

The code looks like:

TaskDialog td = new TaskDialog("Decision");
td.MainContent = "What do you want to do?";
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
                   "Use Simple Insertion Point",
                   "This option works for free-floating items");
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2,
                    "Use Face Reference",
                    "Use this option to place the family on a wall or other surface");

switch (td.Show())
 {
     case TaskDialogResult.CommandLink1:
        // do the simple stuff
        break;

     case TaskDialogResult.CommandLink2:
       // do the face reference
        break;

     default:
       // handle any other case.
        break;
 }
Washrag answered 4/3, 2015 at 13:34 Comment(1)
In case someone reads this, this example illustrates both approaches together in one Dialog.Communalism
S
3

This should do the trick:

TaskDialog dialog = new TaskDialog("Decision");
dialog.MainContent = "What do you want to do?";
dialog.AllowCancellation = true;
dialog.CommonButtons = TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No;

TaskDialogResult result = dialog.Show();
if(result == TaskDialogResult.Yes){
    // Yes
    TaskDialog.Show("yes", "YES!!");
}
else
{
    // No
    TaskDialog.Show("no", "NO!!");
}

Code tested and proved to work in a Revit macro in 2014 so should work fine anywhere else in an add-in as well.

Spahi answered 3/3, 2015 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.