12 Replies Latest reply on May 9, 2011 7:28 PM by Wayne Matus

    Kickoff a task via the API

    Adam Lanners

      Is it possible / has anyone kicked off a task (for instance, the convert to PDF task) from a stand alone executable using the EPDM API?

       

      If so, could someone lead me in the right direction?

       

      Thanks,

      Adam

        • Re: Kickoff a task via the API
          Wayne Matus

          Adam, you can setup a task to be launched via the menu command. Would that work for you?

          Menu Command.png

            • Re: Kickoff a task via the API
              Adam Lanners

              Thanks for the response Wayne.

               

              Unfortunately the task is being kicked off from outside of EPDM. A quick use case would be, a user completes an action in our ECO program (managed outside of EPDM). This action causes an exe to run which will locate the file that the ECO was taken out on and move if from one state to another. When the file moves from the source state to the new state a PDF needs to be generated.

               

              I would put make the convert task as an action in the state transition but through testing I have found that the IEdmFile5.ChangeState method does not use the newest version of the file to create the PDF. Therefore I am trying to change the state and then kick off the task in my exe.

               

              Adam 

                • Re: Kickoff a task via the API
                  Wayne Matus

                  You might be able to use an IEdmFile5::GetFileCopy with a version parameter of 0 to get the latest version of the file before you change the state of the file in your task code.

                    • Re: Kickoff a task via the API
                      Adam Lanners

                      Hi Wayne,

                       

                      I had the same thought since the task kickoff is slightly delayed from when the file changes state I thought I could get the current version and the task would use the newest version to create the PDF.

                       

                      Turns out if I change the file's state and then call GetFileCopy I can watch it get the latest version. Here's the odd part, as soon as the task fires off the local file version reverts back one version and the task uses it to create the PDF. For instance, if the file is version 9 and I change it's state the version will become 10 and I can see on the machine where I'm running that task that it is getting version 10 but as soon as the task begins the local version kicks back to 9. (the task is being kicked off by a transition action)

                       

                      Very odd behavior. I could make a short video to better explain if needed.

                       

                      That's why I got the idea that I would remove the task execute out of the transistion action and call it manually after I call ChangeState and GetFileCopy but so far I haven't seen a way to call a task from the API.

                       

                      Thanks for your help.

                        • Re: Kickoff a task via the API
                          Jeremy Schmidt

                          I am doing a very similar process in one of my tasks.  I have a computer dedicated to creating PDFs so that the users don't have to wait for this process.  I looked for awhile for a way to start a new task from the API, posted the question in the forums, and didn't get much if anything for a response, so I assumed it wasn't possible.  So instead, I created a sub in the task that writes the version to a file on the server computer during the task launch.  This step runs instantly on the client machine performing the transition.  Then the server computer gets to the task, it reads the file with the version, gets that version usingGetFileCopy, and creates a PDF of that version.  It seems to work pretty well so far.

                            • Re: Kickoff a task via the API
                              Adam Lanners

                              Thanks Jeremy,

                               

                              Sounds like you are doing exactly what I want to do in that I will have a server dedicated to running the PDF convert tasks.

                               

                              Your response generated a couple questions for me:

                              So instead, I created a sub in the task that writes the version to a file on the server computer during the task launch. This step runs instantly on the client machine performing the transition.

                              If this step runs instantly on the client machine performing the transition do you have two tasks set up in the transaction? One task to write the current version to a temp file on the server (this task runs on the client machine) and then another task that is targeted to run on the server that converts the PDF? The second task is the one that you've added the subroutine to?

                               

                              Also, did you edit the convert task by using the "Advanced Scripting Options" portion in the task settings and add the subroutine there?

                               

                              I like your idea I just wanted to understand it a little better.

                              Thanks!

                                • Re: Kickoff a task via the API
                                  Jeremy Schmidt

                                  It is all contained within one task.  I added a hook for TaskLaunch in the GetAddInInfo sub:

                                   

                                   

                                  poCmdMgr.AddHook(EdmCmdType.EdmCmd_TaskLaunch)

                                   

                                   

                                  If poCmd.meCmdType = EdmCmdType.EdmCmd_TaskLaunch in my OnCmd sub, then it runs the sub to write the file to the server.  This hook is called right away and will will always run on the client computer.

                                   

                                  If poCmd.meCmdType = EdmCmdType.EdmCmd_TaskRun in my OnCmd sub, then it runs the sub to create the PDF file.  This hook is called when the task is started on the host computer will always run on that computer.

                                   

                                  You also need to make sure that the task will catch the TaskLaunch hook.  Here is my code in my TaskSetup sub:

                                   

                                  ' enable the task to run the initial part on the client computer and to run on a state change

                                  Dim objProperties As IEdmTaskProperties

                                  objProperties = poCmd.mpoExtra

                                  objProperties.TaskFlags = EdmTaskFlag.EdmTask_SupportsInitExec or EdmTaskFlag.EdmTask_SupportsChangeState

                                   

                                  Hope that helps.

                              • Re: Kickoff a task via the API
                                Wayne Matus

                                I do not think there is a way to start an EPDM task addin using the API.

                                 

                                No need to create a video of what you are seeing, I understand.

                                 

                                Question, Does your external program change the state of the file and then are you using the SolidWorks supplied Convert Task Add-in to create the PDF that is triggered by the state change of the file?

                                 

                                I remember a customer having an issue with the SolidWorks supplied Convert Task Add-in about a year ago. Even though the task was setup to get the latest version of the file before creating the pdf, it would not. I wonder if this issue is related to yours.

                                  • Re: Kickoff a task via the API
                                    Adam Lanners

                                    Question, Does your external program change the state of the file and then are you using the SolidWorks supplied Convert Task Add-in to create the PDF that is triggered by the state change of the file?

                                     

                                    Yes, the external program is responsible for changing the state and then the Convert Task Add-in creates the PDF started by the transaction between states. Sounds like it is the same problem that your customer had an issue with. Do you remember what they did for a work-around?

                                     

                                    More simply put, is there any way I can change the state from an external program and get a PDF generated from the newest version?

                                     

                                    Thanks for your help Wayne.

                                      • Re: Kickoff a task via the API
                                        Wayne Matus

                                        I remember now, the issue with the pdf not being created from the latest version was only when it was created from right mouse menu. It was not an issue when task was launched from a workflow transition. See knowledge base solution S-054713.

                                         

                                        Yes, the external program could change the state of a file and create a pdf. The issue you will run into though is that the computer that is running the external program would have to have SolidWorks on it to create the pdf. One possible way around this would be to use Microsoft Message Queing, similar to how you can program Workgroup PDM. Your external program would put a message in the que. A custom program on the server would monitor the que. It would read the message and create a pdf of the file.

                                         

                                        I think your best solution would be to follow what Jeremy did and create your own Task Add-in.