简体   繁体   English

提示用户使用C#中的Revit API回答布尔选择

[英]Prompt user to answer boolean choice using Revit API in C#

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. 我用C#创建了一个Revit插件,该插件使完全不了解3D技术的用户可以选择一个家族,并将其插入他们的项目中。 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 ? TaskDialog.Show是可以解决问题的方法吗?

Thanks in advance. 提前致谢。

Vincent's approach is good. 文森特的方法很好。 The one thing that I like a little bit more is to use the CommandLink options with TaskDialog. 我更喜欢的一件事是将CommandLink选项与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;
 }

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. 经过测试并证明该代码可在2014年在Revit宏中使用,因此该插件中的其他任何地方也应能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM