Lab 2.1: Job Configuration File and Job Execution Script
Time Estimates for Completion
Create the initial version of the SimpleModelGeometryCheck job.
Description:
5 minutes
Lab exercise:
15 minutes
Description
Create a new job type to check a model's geometry.
Lab Exercise
In this lab you will create a new XML job configuration file, and write a LISP script to perform the model geometry check.
You won't see any changes to Creo Elements/Direct Model Manager when you complete this lab. It is only the first step in creating the new job type. Each of the following labs adds more functionality.
Create SimpleModelGeometryCheckJob.xml
Create SimpleModelGeometryCheckJob.xml in the C:\Program Files\PTC\Creo Elements\Direct Manager Server 20.6\taskagent\jobconfig directory:
<?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>
The job type modeling.simplegeometrycheck must be unique and the modeling prefix defines that this job should be sent to Creo Elements/Direct Modeling for execution. The display name Simple Model Geometry Check is optional, and may be localized. See Localization for information on how to localize the display name.
* 
The job type prefix drafting defines Creo Elements/Direct Drafting as the target for job execution.
* 
Job schedules (tasks) stored in the database use the job type to find the corresponding job configuration. Changing the job type in the XML configuration file causes previously created job schedules with the former job type to fail!
Write the SimpleModelGeometryCheckTemplate.lsp script
Create the SimpleModelGeometryCheckTemplate.lsp file in the C:\Program Files\PTC\Creo Elements\Direct Manager Server 20.6\taskagent\modeling directory for the Creo Elements/Direct Modeling LISP script to check the model's geometry. (Click here for a file that you can copy and paste.)
(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)
)
)
Using placeholders for job parameters in scripts and macros
Scripts and macros are templates that also can contain placeholders for job parameters. A placeholder for a job parameter consists of the parameter name with a leading and trailing % character. For example, the placeholder %ModelFile% would be replaced by the value of the job parameter ModelFile. Placeholders are replaced by the corresponding job parameter values on the server side before execution. A list of parameters used and provided by job data exporters, job result handlers, and job options can be found in their API documentation.
Macro and script execution
Creo Elements/Direct Drafting jobs directly execute the macro specified as StartScriptTemplate (after replacing placeholders).
When executing Creo Elements/Direct Modeling jobs, Creo Elements/Direct Modeling starts in a special mode that executes the run-job method in the LISP script specified as StartScriptTemplate. Therefore, a LISP script must have a run-job function with a single parameter specifying the directory containing the job data. In this special mode all exceptions and errors are caught and can be retrieved with the LISP function get-automation-error.
Job execution scripts and macros must also write an index.xml that is used by job result handlers. The index.xml describes the job execution result. For details regarding the result index.xml see Lab 2.4: Implementing a Job Result Handler.
* 
ModelingJobExporter expects LISP scripts in the C:\Program Files\PTC\Creo Elements\Direct Manager Server 20.6\taskagent\modeling directory, DrawingJobExporter expects macros in the C:\Program Files\PTC\Creo Elements\Direct Manager Server 20.6\taskagent\drafting directory.
Was this helpful?