Using the UiPath.Activities.API package from the Official feed (https://pkgs.dev.azure.com/uipath/Public.Feeds/_packaging/UiPath-Official/nuget/v3/index.json
), you can create and add your own custom activity project settings in Studio. For information on how to use the API, see About the Activities SDK.
重要
カスタム プロジェクトでは開発依存関係として UiPath.Activities.API パッケージを使用する必要があります。開発依存関係についてご覧ください。
Activity project settings encompass a set of options that can be adjusted on a project level directly from the Project Settings window.

アクティビティ設定の作成
以下のサンプルでは、音楽プレイヤーのサンプル アクティビティで使用する一連の設定を作成します。
タブとセクションの追加
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
- プロセスのフル パスを取得します。InitiatedBy
- ジョブのソース (Robot、Studio、Orchestrator など) を取得します。FolderId
- retrieves the folder id of the processFolderName
- retrieves the folder name of the processTenantId
- retrieves the tenant idTenantKey
- retrieves the tenant keyTenantName
- retrieves the tenant nameRobotName
- retrieves the robot nameLicenseType
- retrieves the robot license typeRuntimeGovernanceEnabled
- provides info if runtime governance is enabled or notInternalArguments
- retrieves any internal arguments of the processOrganizationId
- retrieves the organization idPictureInPictureMode
- retrieves the type of Picture in Picture mode used. The following values are available:Main
- the process runs in the main Windows sessionPictureInPictureSession
- the process runs in the PiP sessionPictureInPictureDesktop
- the process runs in PiP virtual desktop mode
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 パッケージのインストール
Once the .nupkg
file is created, add it to a custom feed in Studio, as explained here.
Open the Manage Packages window and install the package. Make sure the custom feed is enabled in Studio.
設定例
上記で作成したタブ、セクション、および設定をまとめて、[アクティビティのプロジェクト設定] ウィンドウに表示します。

Simply follow the link below to download the sample, which also contains an example of creating wizards.
2 か月前に更新