Batch Task Plugin Development Question: At the Settings UI is there a way to programmatically access the project file(s) you are running the batch task upon?

I have a batch task to apply to a file but I only want it to apply to a specific set of file types. If the user attempts to configure the settings in a manner that is not applicable to the file type they are running the batch task on I would like to stop them before they hit the 'finish' button.

If I try to run and code on the TaskSettingControl page that attempts to access ProjectFile settings (ProjectFile _projectFile in TaskFiles) I will get an error that 'Object reference not set to an instance of an object '. This same code will work fine once I am into the 'Execute' phase of the Batch Task Plugin (after hitting the finish button).

Is there any way to 'know' the file selected for the Batch Task at the Settings UI page?

  • Hi Kurt

    It depends what view you are in and also, how the batch task is run.
    For example, if the user is in the files view and selects certain files to run the batch task, you can use the following code:
    var filesController = SdlTradosStudio.Application.GetController<FilesController>();

    var selectedFiles = filesController.SelectedFiles.Where(f => f.Role == FileRole.Translatable);

    See the following link for an example:
    github.com/.../ProjectFileManager.cs
  • Hello Jesse and thank you for the feedback,

    Unfortunately the insight (and nicely written code) is not applicable. Let me see if I can offer a clearer definition of my issue.

    I have a custom batch task plugin. When you launch the batch task (this is after a user has selected the file(s) to run the batch task on) a user is presented with three forms in succession:

    1. Batch Tasks Form - which gives them a choice to switch from the task they have already chosen.
    2. Settings Form (code: mybatchtaskSettingsControl.cs)- Here I present a custom interface allowing them to select an XSL style sheet and provide any required parameters the style sheet may require.
    3. Performing Tasks Form (code: mybatchtask.cs) - At this point the Task is run and results are reported.

    I have working code that will tell me the name, path, etc. of the chosen task file(s). That code successfully performs during the 'Performing Tasks Form'. That same code will not work while on the 'Settings Form'. It will always return the error 'object reference not set to an instance of an object'. I have tried variations of the code (even creating classes to wrap it), all of which work at 'Performing Tasks Form', but none of them work while at the 'Settings Form' It appears that I am unable to create certain objects while at the 'Settings Form'

    I want to know the task files at this stage so that I can verify a particular style sheet can be applied to the chosen task file(s). Is there anyway to access the names and paths of the task files chosen by the user while at the Settings Form?

    Again, thank you for your assistance!
  • Hi Kurt Deutschbein (KurtDeutschbein)

    The reason you are getting an "object reference not set to and instance..." error is because the task is not initialized yet.
    This happens *after* you close the settings form. There is no way to change this behavior.

    Now, my code example shows how to acquire the files selected in the files view.
    If the user runs the batch task from the files view, this allows you to get the task files chosen by the user.

    Hopefully thats clear! Let me know if I am misunderstanding anything.

  • Thank you Jesse! I was pretty sure what I wanted to do could not be done. So, I can move to getting the selected files at the files view. Would it be possible for you to point me in the direction as to how I put a hook into running code at the file view? Is this a particular type of plugin? Is there a particular bit of documentation that provides me with information as to where I can intercept user activity in SDL Trados? Thank you for your help.