オフィシャル フィード (https://www.myget.org/F/workflow
) から提供される UiPath.Activities.API パッケージを使用して、Studio でアクティビティのカスタム プロジェクト設定を独自に作成、追加できます。
重要
カスタム プロジェクトでは開発依存関係として UiPath.Activities.API パッケージを使用する必要があります。開発依存関係についてご覧ください。
アクティビティのプロジェクト設定には、[プロジェクト設定] ウィンドウから直接、プロジェクト レベルで調整可能な一連のオプションが含まれます。

API の使用法
アクティビティが Studio に読み込まれると、IWorkflowDesignApi
は次のようないくつかの方法で参照できます。
IRegisterMetadata
の実装にpublic void Initialize(object api)
メソッドを追加します。このメソッドはアクティビティの読み込みプロセスで呼び出され、読み込まれたアクティビティは後で使用するためapi
パラメーターを保存します。IRegisterWorkflowDesignApi
を実装するクラスを定義します。IRegisterWorkflowDesignApi.Initialize(IWorkflowDesignApi api)
メソッドはアクティビティの読み込みプロセスで呼び出され、読み込まれたアクティビティは後で使用するためapi
パラメーターを保存します。このメソッドを使用する場合、Studio の 2019.6 以降のバージョンでしかパッケージを読み込むことができません。api
オブジェクトへの参照を、context.Services.GetService<IWorkflowDesignApi>()
を呼び出すことで取得します。ここで、context
は、通常アクティビティの設計者がアクセス可能な System.Activities.Presentation.EditingContext です。
フィーチャー キーのチェック
必要な機能キーがサポートされているかどうかを調べるために、DesignFeatureKeys
に対して予備チェックを実行することが重要です。
2019.10.1 時点で Studio がサポートしている機能キーは以下のとおりです。これは、将来のバージョンで変更される可能性があります。
namespace UiPath.Studio.Activities.Api
{
/// <summary>
/// Supported Studio feature keys.
/// </summary>
public static class DesignFeatureKeys
{
/// <summary>
/// Studio 19.8
/// </summary>
public const string Settings = nameof(Settings) + "V1";
/// <summary>
/// Studio 19.8
/// </summary>
public const string Theme = nameof(Theme) + "V1";
/// <summary>
/// Studio 19.8
/// </summary>
public const string Wizards = nameof(Wizards) + "V1";
/// <summary>
/// Studio 19.8
/// </summary>
public const string AccessProvider = nameof(AccessProvider) + "V1";
/// <summary>
/// Studio 19.10
/// </summary>
public const string Telemetry = nameof(Telemetry) + "V1";
}
}
フィーチャーをチェックするには、IWorkflowDesignApi
の参照に対して HasFeature
メソッドを呼び出す必要があります。これを行わないと、Studio のより古いバージョンでは、関連する API メソッドの呼び出しが MissingMemberException または MissingMethodException で失敗する可能性があります。
IWorkflowDesignApi studioActivitiesApi;
// How to check for a feature.
if (studioActivitiesApi.HasFeature(UiPath.Studio.Activities.Api.DesignFeatureKeys.Settings))
{
// Call Method or lambda that is using specific feature
// This ensures that the code is JIT compiled only after the feature check
}
アクティビティ設定の作成
以下のサンプルでは、音楽プレイヤーのサンプル アクティビティで使用する一連の設定を作成します。
タブとセクションの追加
using UiPath.Studio.Activities.Api;
using UiPath.Studio.Activities.Api.Settings;
namespace MyCustomActivityPack
{
public static class SettingsCreator
{
// This is the key used to reference a tab, even across packages.
internal const string CategoryKey = "DemoTabUniqueKey";
// This is the key used to reference the setting, even across packages.
internal const string CommentTextKey = CategoryKey + ".Comment";
internal const string PresetKey = CategoryKey + ".Preset";
internal const string ShuffleKey = CategoryKey + ".Shuffle";
public static void CreateSettings(IWorkflowDesignApi workflowDesignApi)
{
var settingsApi = workflowDesignApi.Settings;
// Add the category (a tab in the settings page)
var category = new SettingsCategory()
{
Description = "Settings Sample",
Header = "Settings Sample",
Key = CategoryKey
};
settingsApi.AddCategory(category);
AddMusicPlayerSection(settingsApi, category);
AddMiscSettings(settingsApi, category);
上記のコードは、[アクティビティのプロジェクト設定] ウィンドウにタブとセクションを追加します。タブのツールチップ上にカーソルを置くと、タブについての説明が表示されます。

設定の追加
- 展開可能な設定セクション
private static SettingsSection AddMusicPlayerSection(IActivitiesSettingsService settingsApi, SettingsCategory category)
{
var section = new SettingsSection()
{
Description = "Settings for a music player",
IsExpanded = true, //set this to control default expansion
Title = "Music Player Settings",
// the key of a section has to be unique only within the category
Key = "Player"
};
settingsApi.AddSection(category, section);
AddSimpleBoolean(settingsApi, section);
AddSingleChoice(settingsApi, section);
return section;
}
次のような結果が得られます。

- Boolean 値のラジオ ボタン
private static void AddSimpleBoolean(IActivitiesSettingsService settingsApi, SettingsSection section)
{
var booleanSetting = new SingleValueEditorDescription<bool>
{
DefaultValue = true,
Description = "If active, the playlist is shuffled",
// The value returned by GetDisplayValue should be localized
GetDisplayValue = b => b ? "On" : "Off",
Key = ShuffleKey,
Label = "Shuffle"
};
settingsApi.AddSetting(section, booleanSetting);
}
次のような結果が得られます。

- 複数の値選択リスト
private static void AddSingleChoice(IActivitiesSettingsService settingsApi, SettingsSection category)
{
var booleanSetting = new SingleValueSelectorDescription
{
DefaultValue = "pop",
Values = new[] { "classic", "pop", "rock" },
Description = "Sample single choice setting",
// The value returned by GetDisplayValue should be localized
GetDisplayValue = choice => choice + " music",
Key = PresetKey,
Label = "Mixer Preset"
};
settingsApi.AddSetting(category, booleanSetting);
}
次のような結果が得られます。

- 検証機能付きのテキスト入力フィールド
private static void AddSimpleString(IActivitiesSettingsService settingsApi, SettingsSection section)
{
var simpleStringSetting = new SingleValueEditorDescription<string>()
{
Description = "A free text comment that can't contain the word 'invalid'",
// The GetDisplayValue obtains a localized screen representation of the underlying setting value.
GetDisplayValue = LocalizeSimpleSettingValue,
IsReadOnly = false,
DefaultValue = "There is no comment",
Label = "Comment",
Validate = ValidateSimpleStringSetting,
Key = CommentTextKey
};
// Add the setting to the section.
// A setting may also be directly added on a category. It will appear as a setting without a section (top level setting)
settingsApi.AddSetting(section, simpleStringSetting);
}
private static string LocalizeSimpleSettingValue(string s) => $"A localized value of `{s}`";
private static string ValidateSimpleStringSetting(string arg)
{
if (arg?.ToLowerInvariant().Contains("invalid") == true)
{
return "The sample string setting is invalid if it contains the `invalid` keyword";
}
return string.Empty;
}
次のような結果が得られます。

プロセス ID とログを取得する
IExecutorRuntime
参照に適用されるメソッドを使用して、ロボットが実行中のプロセスの ID 情報と実行ログを取得できます。以下のメソッドを使用できます。
IRunningJobInformation
- 実行中のプロセスに関する情報を収集します。以下のプロパティをサポートしています。JobID
- プロセス ID を取得します。ProcessName
- プロセス名を取得します。ProcessVersion
- プロセスのバージョンを取得します。WorkflowFilePath
- プロセスのフル パスを取得します。
LogMessage
- 指定した ログ レベルに基づいてロボット実行ログを生成します。ログの詳細については、こちらのページをご覧ください。以下のプロパティがサポートされています。EventType
- 取得するログ レベルです。Message
- 表示するメッセージです。
次のコードは、LogMessage
メソッドの使用例です。
public class MyLogMessageActivity : CodeActivity
{
protected override void Execute(CodeActivityContext context)
{
var executorRuntime = context.GetExtension<IExecutorRuntime>();
var jobInfo = executorRuntime.RunningJobInformation;
executorRuntime.LogMessage(new LogMessage
{
EventType = TraceEventType.Warning,
Message = $"Job {jobInfo.JobId}: My log message from workflow {jobInfo.WorkflowFilePath}"
});
}
}
Studio へのプロジェクトの追加
Studio の [アクティビティのプロジェクト設定] ウィンドウに設定を表示させるには、カスタム アクティビティを NuGet パッケージにパブリッシュして、このパッケージを Studio バージョン 2019.10.1 以降で定義したフィードで利用できるようにする必要があります。
NuGet パッケージの作成

- NuGet Package Explorer を起動します。
- [Create a new package] (Ctrl + N) をクリックします。[Package metadata] と、[Package contents] を示す分割ウィンドウが表示されます。後者のセクションに、すべての依存関係を追加する必要があります。
- [Package contents] セクションを右クリックします。コンテキスト メニューが表示されます。
- [Add lib folder] をクリックします。新しい [lib] 項目が、[Package contents] セクションに作成されます。
- [lib] を右クリックして、[Add Existing File…] を選択します。
- プロジェクトの外部アセンブリ (.dll) を読み込みます。
- [Edit] > [Edit Metadata] をクリックします。[Package metadata] セクションが表示されます。
- プロジェクトの適切な説明をフィールドに入力します。
- [Id] フィールドに入力し、キーワード Activities が含まれていることを確認します。これにより、Studio の [パッケージを管理] ウィンドウにパッケージが表示されるようになります。
- [File] > [Save] をクリックします。このケースでは、
.nupkg
ファイルが作成されます。
注:
アクティビティには、直感的なフォルダー構造を作成してください。Orchestrator で使用すると、カスタム アクティビティ内の空のフォルダーはすべて削除されます。
UiPath Studio への NuGet パッケージのインストール
.nupkg
ファイルを作成したら、こちらの説明に従い、これを Studio のカスタム フィードに追加します。
[パッケージを管理] ウィンドウを開き、パッケージをインストールします。カスタム フィードが Studio で有効化されていることを確認します。
設定例
上記で作成したタブ、セクション、および設定をまとめて、[アクティビティのプロジェクト設定] ウィンドウに表示します。

下記のリンクをクリックしてサンプルをダウンロードします。サンプルには、ウィザードの作成例も含まれています。
2 年前に更新