LoginSignup
4
2

More than 3 years have passed since last update.

【RPA】UiPathで湯婆婆を実装してみる

Last updated at Posted at 2020-11-25

はじめに

令和のHello World!と呼ばれる湯婆婆を、RPAソフトのUiPathでも実装してみます。
 原作者様: Javaで湯婆婆を実装してみる - Qiita

Uipath とは

業務を自動化するRPAツールの1つで、部品を組み立てながら処理を書いていきます。
Uipathのベースは「WWF(Windows Workflow Foundation)※」になっていて、Uipathの中で使用する部品や処理はVB・C#で記述することができます。

※ Microsoft製のワークフロー基盤システム。「SharePoint」や「Dynamics365」などのワークフロー実装にも使われており、通称「WF」(WWFだとパンダマークの世界自然保護基金になってしまうため)。

仕様

  • 湯婆婆の「名前を書きな」をメッセージボックスで表示します。ボタンは「OK」のみ表示。
  • 「OK」ボタン押下で「名前入力ダイアログ」を表示。
  • 湯婆婆が奪い取る文字を考え、新しい名前が言い渡される。

コード

UiPathStudio(エディタ)で見るとこんな感じ。

image.png

作成されたxamlファイルは下記。

yubaba.xaml
<Activity mc:Ignorable="sap sap2010" x:Class="Main" mva:VisualBasic.Settings="{x:Null}" sap:VirtualizedContainerService.HintSize="1579.33333333333,1137.33333333333" sap2010:WorkflowViewState.IdRef="ActivityBuilder_1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:ui="http://schemas.uipath.com/workflow/activities" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <TextExpression.NamespacesForImplementation>
    <scg:List x:TypeArguments="x:String" Capacity="26">
      <x:String>System.Activities</x:String>
      <x:String>System.Activities.Statements</x:String>
      <x:String>Microsoft.VisualBasic</x:String>
      <x:String>System</x:String>
      <x:String>System.Collections</x:String>
      <x:String>System.Collections.Generic</x:String>
      <x:String>UiPath.Core</x:String>
      <x:String>UiPath.Core.Activities</x:String>
      <x:String>System.Collections.ObjectModel</x:String>
      <x:String>System.Activities.DynamicUpdate</x:String>
      <x:String>System.Reflection</x:String>
      <x:String>System.Runtime.InteropServices</x:String>
      <x:String>System.Linq</x:String>
    </scg:List>
  </TextExpression.NamespacesForImplementation>
  <TextExpression.ReferencesForImplementation>
    <scg:List x:TypeArguments="AssemblyReference" Capacity="52">
      <AssemblyReference>System.Activities</AssemblyReference>
      <AssemblyReference>System</AssemblyReference>
      <AssemblyReference>Microsoft.VisualBasic</AssemblyReference>
      <AssemblyReference>mscorlib</AssemblyReference>
      <AssemblyReference>System.Core</AssemblyReference>
      <AssemblyReference>System.ValueTuple</AssemblyReference>
      <AssemblyReference>Microsoft.Bcl.AsyncInterfaces</AssemblyReference>
      <AssemblyReference>System.Memory</AssemblyReference>
      <AssemblyReference>UiPath.System.Activities</AssemblyReference>
      <AssemblyReference>UiPath.OCR.Activities.Design</AssemblyReference>
      <AssemblyReference>UiPath.UIAutomationCore</AssemblyReference>
      <AssemblyReference>System.ComponentModel.Composition</AssemblyReference>
      <AssemblyReference>System.ServiceModel</AssemblyReference>
      <AssemblyReference>UiPath.UiAutomation.Activities</AssemblyReference>
      <AssemblyReference>UiPath.System.Activities.Design</AssemblyReference>
      <AssemblyReference>System.Collections.Immutable</AssemblyReference>
    </scg:List>
  </TextExpression.ReferencesForImplementation>
  <Sequence DisplayName="Sequence - Yubaba" sap:VirtualizedContainerService.HintSize="376,972.666666666667" sap2010:WorkflowViewState.IdRef="Sequence_1">
    <Sequence.Variables>
      <Variable x:TypeArguments="x:String" Name="inputName" />
      <Variable x:TypeArguments="x:String" Name="newName" />
      <Variable x:TypeArguments="x:Int32" Name="nameIndex" />
    </Sequence.Variables>
    <sap:WorkflowViewStateService.ViewState>
      <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
      </scg:Dictionary>
    </sap:WorkflowViewStateService.ViewState>
    <ui:TypeInto ClickBeforeTyping="{x:Null}" DelayBefore="{x:Null}" DelayBetweenKeys="{x:Null}" DelayMS="{x:Null}" EmptyField="{x:Null}" SendWindowMessages="{x:Null}" SimulateType="{x:Null}" Activate="True" AlterIfDisabled="True" DisplayName="文字を入力 - 何もしないUI操作(前面フォーカス)" sap:VirtualizedContainerService.HintSize="334,96" sap2010:WorkflowViewState.IdRef="TypeInto_1" Text="%[k(ctrl)]">
      <ui:TypeInto.Target>
        <ui:Target ClippingRegion="{x:Null}" Element="{x:Null}" Selector="{x:Null}" Id="785dab0c-3977-4997-8e13-0aa0d41be876">
          <ui:Target.TimeoutMS>
            <InArgument x:TypeArguments="x:Int32" />
          </ui:Target.TimeoutMS>
          <ui:Target.WaitForReady>
            <InArgument x:TypeArguments="ui:WaitForReady" />
          </ui:Target.WaitForReady>
        </ui:Target>
      </ui:TypeInto.Target>
    </ui:TypeInto>
    <ui:MessageBox ChosenButton="{x:Null}" Buttons="Ok" Caption="湯婆婆" DisplayName="メッセージ ボックス - 契約書" sap:VirtualizedContainerService.HintSize="334,58.6666666666667" sap2010:WorkflowViewState.IdRef="MessageBox_1" Text="[&quot;契約書だよ。そこに名前を書きな。働かせてやる。&quot;]" />
    <ui:InputDialog Options="{x:Null}" OptionsString="{x:Null}" DisplayName="入力ダイアログ - 契約書" sap:VirtualizedContainerService.HintSize="334,244.666666666667" sap2010:WorkflowViewState.IdRef="InputDialog_1" IsPassword="False" Label="[String.Format(&quot;甲は乙を・・・をすることを・・・右のとおり約定をかわ・・・・{0}{0}甲 油屋当主 湯婆婆{0}乙:(名前を入力)&quot;, ControlChars.CrLf)]" Title="契約書">
      <ui:InputDialog.Result>
        <OutArgument x:TypeArguments="x:String">[inputName]</OutArgument>
      </ui:InputDialog.Result>
    </ui:InputDialog>
    <ui:MessageBox ChosenButton="{x:Null}" Buttons="Ok" Caption="湯婆婆" DisplayName="メッセージ ボックス - 入力した名前の確認" sap:VirtualizedContainerService.HintSize="334,58.6666666666667" sap2010:WorkflowViewState.IdRef="MessageBox_2" Text="[String.Format(&quot;フン。{0}というのかい?贅沢な名だねぇ。&quot;, inputName)]" />
    <Assign DisplayName="代入 - 名前の切り出し位置" sap:VirtualizedContainerService.HintSize="334,62" sap2010:WorkflowViewState.IdRef="Assign_1">
      <Assign.To>
        <OutArgument x:TypeArguments="x:Int32">[nameIndex]</OutArgument>
      </Assign.To>
      <Assign.Value>
        <InArgument x:TypeArguments="x:Int32">[new System.Random().Next(0,inputName.Length)]</InArgument>
      </Assign.Value>
    </Assign>
    <Assign DisplayName="代入 - 新しい名前" sap:VirtualizedContainerService.HintSize="334,62" sap2010:WorkflowViewState.IdRef="Assign_2">
      <Assign.To>
        <OutArgument x:TypeArguments="x:String">[newName]</OutArgument>
      </Assign.To>
      <Assign.Value>
        <InArgument x:TypeArguments="x:String">[inputName.Substring(nameIndex,1)]</InArgument>
      </Assign.Value>
    </Assign>
    <ui:MessageBox ChosenButton="{x:Null}" Buttons="Ok" Caption="湯婆婆" DisplayName="メッセージ ボックス - 新しい名前" sap:VirtualizedContainerService.HintSize="334,58.6666666666667" sap2010:WorkflowViewState.IdRef="MessageBox_3" Text="[String.Format(&quot;今からおまえの名前は {0} だ。いいかい、{0} だよ。分かったら返事をするんだ、{0}!!&quot;, newName)]" />
  </Sequence>
</Activity>

実行

image.png
image.png
image.png
image.png

クラッシュ湯婆婆

入力がないとエラーになります(仕様通り)
image.png

終わりに

令和のHello World!なので「誰でも分かる&初心者でも書けるシンプル実装」にしてみました。

せっかくRPAで作っているので「手書き入力をAIOCRで読み取る」とか「入力フォームで湯婆婆画像を表示する」等を書いてみると面白いかもしれません。それはまたの機会に。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2