SDK
最新
False
横幅背景图像
开发者指南
上次更新日期 2024年3月23日

创建自定义向导

使用 官方 订阅源 ( ) 中的 UiPath.Activities.APIhttps://pkgs.dev.azure.com/uipath/Public.Feeds/_packaging/UiPath-Official/nuget/v3/index.json 包,您可以将自己的自定义向导添加到 Studio 的功能区。有关如何使用 API 的信息,请参阅Studio 活动 SDK


注意: UiPath.Activities.API包必须用作自定义项目中的开发依赖项。 阅读有关开发依赖项的更多信息。

构建自定义向导

以下示例显示了向导的定义,该向导在单击时会创建一个空序列:

using System.Activities;
using System.Windows;
using System.Windows.Input;
using UiPath.Studio.Activities.Api;
using UiPath.Studio.Activities.Api.Wizards;
namespace MyCustomActivityPack
{
    public static class WizardCreator
    {
        public static void CreateWizards(IWorkflowDesignApi workflowDesignApi)
        {
            CreateDemoWizard(workflowDesignApi);
        }
        private static void CreateDemoWizard(IWorkflowDesignApi workflowDesignApi)
        {
            var wizardApi = workflowDesignApi.Wizards;
            var wizardDefinition = new WizardDefinition()
            {
                // You can add other definitions here to create a dropdown.
                //ChildrenDefinitions.Add()
                Wizard = new WizardBase()
                {
                    RunWizard = RunWizard
                },
                DisplayName = "DemoWizardDisplayName",
                Shortcut = new KeyGesture(Key.F9, ModifierKeys.Control | ModifierKeys.Shift),
                IconUri = "Icons/RecordIcon",
                Tooltip = "DemoWizardTooltip"
            };
            var collection = new WizardCollection(); //Use a collection to group all of your wizards.
            collection.WizardDefinitions.Add(wizardDefinition);
            wizardApi.Register(collection);
        }
        private static Activity RunWizard()
        {
            if(MessageBox.Show("Do you want a sequence?", "This is a wizard window", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                return new System.Activities.Statements.Sequence()
                {
                    DisplayName = "The wizard generated this sequence"
                };
            }
            return null;
        }
    }
}using System.Activities;
using System.Windows;
using System.Windows.Input;
using UiPath.Studio.Activities.Api;
using UiPath.Studio.Activities.Api.Wizards;
namespace MyCustomActivityPack
{
    public static class WizardCreator
    {
        public static void CreateWizards(IWorkflowDesignApi workflowDesignApi)
        {
            CreateDemoWizard(workflowDesignApi);
        }
        private static void CreateDemoWizard(IWorkflowDesignApi workflowDesignApi)
        {
            var wizardApi = workflowDesignApi.Wizards;
            var wizardDefinition = new WizardDefinition()
            {
                // You can add other definitions here to create a dropdown.
                //ChildrenDefinitions.Add()
                Wizard = new WizardBase()
                {
                    RunWizard = RunWizard
                },
                DisplayName = "DemoWizardDisplayName",
                Shortcut = new KeyGesture(Key.F9, ModifierKeys.Control | ModifierKeys.Shift),
                IconUri = "Icons/RecordIcon",
                Tooltip = "DemoWizardTooltip"
            };
            var collection = new WizardCollection(); //Use a collection to group all of your wizards.
            collection.WizardDefinitions.Add(wizardDefinition);
            wizardApi.Register(collection);
        }
        private static Activity RunWizard()
        {
            if(MessageBox.Show("Do you want a sequence?", "This is a wizard window", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                return new System.Activities.Statements.Sequence()
                {
                    DisplayName = "The wizard generated this sequence"
                };
            }
            return null;
        }
    }
}
使用 MinimizeBeforeRun 属性在调用 RunWizard 之前最小化 Studio,并在 RunWizard 返回时还原。
RunWizardAsync 属性应用于异步执行向导。

将项目添加到 Studio

要使向导在 Studio 功能区可见,您需要将自定义活动发布到 NuGet 包中,并向 2019.10.1 或更高版本 Studio 中定义的订阅源提供该包。

步骤 1:创建 NuGet 包


  1. 启动NuGet Package Explorer
  2. 单击“创建新包 (Ctrl + N)”。随即会出现一个分割窗口,其中显示“包元数据”和“包内容”。我们需要在窗口的后一部分中添加所有依赖项。
  3. 右键单击“包内容”部分。系统随即会显示一个上下文菜单。
  4. 单击 “添加库文件夹” 请注意,系统会在“ 包内容 ”部分中创建一个新的库项目。
  5. 右键单击“ ”,然后选择“ 添加现有文件…”
  6. 加载项目的外部程序集 (.dll)。
  7. 单击 “编辑” >“编辑元数据”。 系统将显示“ 包元数据 ” 部分。
  8. 根据需要填写字段,以更好地描述项目。
  9. 填写“ID”字段,并确保包含关键字“活动”,以便在 Studio 的“管理包”窗口中显示该包。
  10. Click File > Save. In our case, the .nupkg file is created.
    Note: Be sure to create an intuitive folder structure for your activities. All empty folders inside the custom activity get removed when used with Orchestrator.
步骤 2:在 UiPath Studio 中安装 NuGet 包
创建.nupkg文件后,将其添加到 Studio 中的自定义订阅源,如此所述。

打开“管理包”窗口并安装包。 确保在 Studio 中启用自定义订阅源。

示例向导

只需点击以下链接即可下载示例,其中还包含创建 自定义活动设置的示例。

  • 构建自定义向导
  • 将项目添加到 Studio
  • 示例向导

此页面是否有帮助?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath 白色徽标
信任与安全
© 2005-2024 UiPath. All rights reserved.