Issue
Making sure that there are no open documents before a new document is opened or that there is always just one open document when executing a job.
Solution
For powerJobs 19 or newer:
Open coolOrange.Applications.psm1 located in "C:\ProgramData\coolOrange\powerJobs\Modules"
For powerJobs 18 or earlier:
Open Setup_Job.ps1 located in "C:\ProgramData\coolOrange\powerJobs"
Add following line of code under the Register-Application cmdlet if you are using Inventor:
$powerJobs.Applications['Inventor'].RestartOptions.DocumentCloseCounts=1
If you are using InventorServer add this line of code under the Register-Application cmdlet:
$powerJobs.Applications['InventorServer'].RestartOptions.DocumentCloseCounts=1
This sets the Close-Document counter to 1, that means every time a Close-Document is executed, the application restarts and therefore you should always have just one open document. Note that Close-Document has to be executed for this to work. To ensure that it will always be executed there are 3 possibilities:
- Add Close-Document to the Setup_Job.ps1 which gets executed before every job
- Add Close-Document at the beginning of your job
- If the job crashes, Close-Document will not be executed. In that case you can catch the exception with a try catch and add Close-Document in the catch block:
try { <your code> } catch { Close-Document }
Remarks
This can affect the speed of the jobs being executed as the application is restarted after every Close-Document
See also
Close-Document (coolOrange Wiki)
About try catch finally (MSDN)