Create a new Job using EditorScripts Class

One thing that I like to do is copy a segment of code in a Job and debug it there. It’s like a safe place, where you can test/debug the code, without worrying that some unknown variables might influence the process. And since I use it quite often, I wrote a nifty function, to automate it a bit by adding this small method to the EditorScripts Class. In case you don’t know what the EditorSpripts does and how it works here is a previous post explaining the Class

 

Here is what it does: Let’s say you found a select statement that you would like to run, without the rest of the code in the method. You just select the code you are interested in, click on the createNewJob under Scripts -> WorkFlow, add a new for the new Job and voila! your new Job is ready.

newJobTool

 

Here is the code

 

public void WorkFlow_createNewJob(Editor editor)
{
    //dialog variables
    Dialog dialog;
    DialogField jobName;
    Str20 strJobName;
    //editor variables needed for selection
    Editor newJobEditor;
    str selectedText;
    //variables needed to create the new Job
    TreeNode treeNode;
    xInfo xInfo = new xInfo();
    //creating the dialog for the name of the job
    dialog = new Dialog("WorkFlow - Create Job");
    jobName = dialog.addField("str20");
 
    if (dialog.run())
    {
        strJobName = jobName.Value();
    }
 
    //getting the selected text from the editor
    selectedText += EditorScripts::getSelectedText(editor);
 
    //creating the job
    treeNode = xInfo.rootNode();
    treeNode = treeNode.AOTfindChild("Jobs");
    treeNode.AOTadd(strJobName);
 
    //treeNode holds our freshly made Job
    treeNode = treeNode.AOTfindChild(strJobName);
    //opens the job
    treeNode.AOTedit(3,1);
 
    //newJobEditor is the editor of the created Job
    newJobEditor = Editor::open('\Jobs\\' + strJobName);
 
    //inserting the selected text in the new Job
    newJobEditor.insertString(selectedText);
}

Hope you enjoyed my post and in case you have a question don’t hesitate to leave a comment.

Posted in Tools.

Leave a Reply

Your email address will not be published. Required fields are marked *