Running Task Add-in on multiple files or multiple selections

Hi everyone,
I’m coding a new task add-in
I want to run task add-in on multiple files or multiple selections at right-click menu-item or during state transition.

But Add-in works only first selection file.
how can i get list of all selections.

I have a switch case in the OnCmd()

    // Entry point for the add-in, any of the .AddHook(EdmCmdType) type events will
    // come through this handler.
//    public void OnCmd(ref EdmCmd poCmd, ref System.Array ppoData)
    public void OnCmd(ref EdmCmd poCmd, ref EdmCmdData[] ppoData)
.....
          case EdmCmdType.EdmCmd_TaskRun:
            OnTaskRun(ref poCmd, ref ppoData);
            break;
.....

And then in the OnTaskRun method I iterate through the array of ppoData objects

  foreach (EdmCmdData cmdData in ppoData)
      {
        int objID = cmdData.mlObjectID1;
        int ParentFolderID = cmdData.mlObjectID2;
        string StrSourcePath = cmdData.mbsStrData1;
        string configName = cmdData.mbsStrData2;
        int edmObjTyp = cmdData.mlLongData1;
        if (edmObjTyp != (int)EdmObjectType.EdmObject_File)
        {
          throw new Exception("EdmObjectType not File");
        }
 //Do whatever you need to du utilizing the data in the cmdData object.
....

That seems to be working fine for me.

Edit: helpful help page:
https://help.solidworks.com/2019/english/api/epdmapi/epdm.interop.epdm~epdm.interop.epdm.edmcmddata.html

2 Likes
  1. You need your IEdmTaskProperties’s flag to equal to this: (int)EdmTaskFlag.EdmTask_SupportsChangeState + (int)EdmTaskFlag.EdmTask_SupportsInitExec
  2. You need to add a menu item on TaskSetup hook via the IEdmTaskProperties (mpo.Extra) in order to invoke the add-in from a right click menu.
  3. On TaskRun or TaskLaunch, the affected files are in the ppoData just like @bnemec outlined in his answer.
4 Likes

Thank you @AmenJlili , I was trying to find the other stuff that is needed to make that work but it’s been so long ago that I forgot and couldn’t find it.

I have a super framework for PDM task. Will be sharing it soon.

1 Like

@bnemec Thank you very much.

You are welcome. Thanks for marking your thread solved.