演習 2.1:ジョブ設定ファイルとジョブ実行スクリプト
推定所要時間
SimpleModelGeometryCheck ジョブの最初のバージョンを作成する
説明:
5 分
演習:
15 分
説明
モデルの図形をチェックする新しいジョブタイプを作成します。
演習
この演習では、新しい XML ジョブ設定ファイルを作成し、モデル図形のチェックを実行する LISP スクリプトを作成します。
この演習を完了した時点では、Creo Elements/Direct Model Manager は変更されていません。これは、新しいジョブタイプ作成の最初のステップにすぎません。以降の各演習で、さらに機能を追加します。
SimpleModelGeometryCheckJob.xml の作成
C:\Program Files\PTC\Creo Elements\Direct Manager Server 20.7\taskagent\jobconfig ディレクトリに SimpleModelGeometryCheckJob.xml を作成します。
<?xml version="1.0" encoding="UTF-8"?>
<Job type="modeling.simplegeometrycheck" has_result_data="true">
<DisplayName>Simple Model Geometry Check</DisplayName>
<Exporter java_class="com.osm.automation.ModelingJobExporter">
<StartScriptTemplate>SimpleModelGeometryCheckTemplate.lsp</StartScriptTemplate>
<ModelLoadRule catalog="model" msg_num="728">Highest Revisions</ModelLoadRule>
</Exporter>
<ResultHandler java_class="com.osm.automation.SaveToFileSystemJobResultHandler">
<TargetDirectory>C:\taskagent</TargetDirectory>
</ResultHandler>
</Job>
ジョブタイプ modeling.simplegeometrycheck は、一意なものにする必要があります。また、このジョブを Creo Elements/Direct Modeling に送信して実行することをプレフィックス modeling で定義します。表示名 Simple Model Geometry Check は任意で、ローカライズできます。表示名をローカライズする方法については、「ローカライズ」を参照してください。
* 
ジョブタイププレフィックス drafting で、ジョブ実行のターゲットとして Creo Elements/Direct Drafting を定義します。
* 
データベースに保管されているジョブスケジュール (タスク) は、ジョブタイプを使用して対応するジョブ設定を探します。XML 設定ファイル内のジョブタイプを変更すると、前のジョブタイプで以前に作成されたジョブスケジュールは失敗します。
SimpleModelGeometryCheckTemplate.lsp スクリプトの作成
モデルの図形をチェックする Creo Elements/Direct Modeling LISP スクリプトとして、C:\Program Files\PTC\Creo Elements\Direct Manager Server 20.7\taskagent\modeling ディレクトリに SimpleModelGeometryCheckTemplate.lsp ファイルを作成します(ここをクリックして表示されるファイルから、コードをコピーアンドペーストできます)。
(in-package :frame2)
;;-------------------------
;; utilities
;;-------------------------
(load "JobUtilities.lsp")
;;------------------------------------------------------------------------------
;; This is the routine that is called by the automation framework in Modeling.
;; When this routine is called, the current directory of Modeling is the one
;; where the input data can be found.
;;
;; parameter : <ouptput-directory> directory for output data
;; return : <error-message> return value 'nil' ==> success
;;------------------------------------------------------------------------------
(defun run-job (output-directory)
(let* (
;; parameters provided by the job
(check-type :minimal_check)

;; the item to check
(part-to-check nil)

;; variables for XML serialization
(results-element (xml:xml-list-create-element "results"))
(xml-file (create-path output-directory "index.xml"))

;; variables for writing the output file
(file-zipname "model.pkg") ;; the real name of the result file in the ZIP archive
(file-path (create-path output-directory file-zipname)) ;; the path of the result file
(file-name file-zipname)
)

;;---------------------------------------------
;; load input & call the part checker
;;---------------------------------------------
(load-job-data "%ModelFile%")
(setf part-to-check (oli:sd-inq-obj-children (get-all-at-top)))
(k2-ui::check_part :objects part-to-check check-type :labels :on :keep_labels :on)
(collect-check-results (frame2:getres) results-element)
;; -------------------
;; write result data
;; -------------------
;; write the annotated model
(frame2::save-all-in-package file-path)
;; and make a corresponding entry in the index.xml
(xml:xml-list-add-child results-element (make-result-file-element "PKG" :file file-zipname :name file-name))
;;------------------------------------------------------------------------
;; write the index.xml
;; write-xml-to-list serializes the list into XML (see JobUtilities.lsp)
;;------------------------------------------------------------------------
(write-xml-list-to-file results-element xml-file)

;;------------------------------
;; return = nil means 'no error'
;;------------------------------
(get-automation-error)
) ; let
)
(defun collect-check-results (part-check-result results-element)
(let* (
(error-entries (cdr (assoc k2-ui::*body-check-error-string* part-check-result)))
(model-state (if (> (length error-entries) 0) "model_corrupt" "model_ok"))
)
(xml:xml-list-add-attribute results-element "modelcheck" model-state)
)
)
スクリプトとマクロ内のジョブパラメータにプレースホルダを使用する
スクリプトとマクロはテンプレートで、ジョブパラメータのプレースホルダを含めることもできます。ジョブパラメータのプレースホルダは、パラメータ名の先頭と末尾に % 文字が付いたものです。たとえば、プレースホルダ %ModelFile% は、ジョブパラメータ ModelFile の値で置き換えられます。プレースホルダは、実行の前に、サーバ側の対応するジョブパラメータ値で置き換えられます。ジョブデータエクスポータ、ジョブ結果ハンドラ、およびジョブオプションが使用および提供するパラメータの一覧は、それぞれの API マニュアルを参照してください。
マクロとスクリプトの実行
Creo Elements/Direct Drafting ジョブは、プレースホルダを置換した後、StartScriptTemplate として指定されたマクロを直接実行します。
Creo Elements/Direct Modeling ジョブを実行すると、Creo Elements/Direct Modeling が特殊なモードで起動し、StartScriptTemplate として指定された LISP スクリプトの run-job メソッドを実行します。そのため、LISP スクリプトには、ジョブデータを格納したディレクトリを指定する 1 つのパラメータを付けて run-job 関数を記述する必要があります。この特殊モードでは、すべての例外とエラーが捕捉されます。これらは LISP 関数 get-automation-error によって取得できます。
ジョブ実行スクリプトおよびマクロは、ジョブ結果ハンドラが使用する index.xml も作成する必要があります。index.xml にはジョブ実行結果が記述されます。作成される index.xml の詳細については、「演習 2.4: ジョブの結果ハンドラの実装」を参照してください。
* 
ModelingJobExporter では C:\Program Files\PTC\Creo Elements\Direct Manager Server 20.7\taskagent\modeling ディレクトリに LISP スクリプトを置く必要があります。また、DrawingJobExporter では C:\Program Files\PTC\Creo Elements\Direct Manager Server 20.7\taskagent\drafting ディレクトリにマクロを置く必要があります。
これは役に立ちましたか?