How do you get a workspace to appear in the workspace toolbox?

Name: Arthur Wilcke

Dear Mantid Developement Team, I am currently using Mantid at the ILL, and I have been writing a few scripts that would need me to be able to create my own Workspace from scratch. I have been able to use the CreateWorkspace algorithm, however it seems that one can only have one array for X and Y values, and I would like to have more… I have seen that the way to do this is the Workspace Factory, however I am unable to understand how to export the created workspace into my list of available workspaces in the gui… I have tried following the tutorial at, but I do not understand how to use the functions PyInit and PyExec to create my own workspace. I would very much apreciate your help, Regards, Arthur Wilcke.


The magic to getting workspace to appear in the workspaces toolboxs in the GUI is the add them to the AnalysisDataService.

This is done for you automatically if you set the workspace as an output property of an algorithm, but you can do it yourself with the following python command

AnalysisDataService.add("name to be listed in GUI",workspaceObject)

To try to better explain the examples There are where you are creating your own Algorithm (to see the full explanation start and follow the next links)

def PyInit(self):
  # Creates a generic output property
def PyExec(self):
  # A workspace with 5 rows with 9 bins & 10 bin boundaries
  # (i.e. a histogram)
  output_ws = WorkspaceFactory.create("Workspace2D", NVectors=5,
                                        XLength=10, YLength=9)
  self.setProperty("OutputWorkspace", output_ws)

Within a python class you create to be your python algorithm you define two methods PyInit, and PyExec.

In PyInit you include self.declareProperty statements to define all of the input and output properties of your algorithm.
The example above only has one property, an output workspace property, containing the result.

In PyExec you include the code to do whatever you want to do, in your case creating your workspace.
The example above does just that, it creates a simple workspace using WorkspaceFactory.create.
The self.setProperty(“OutputWorkspace”, output_ws) line sets the output workspace to the output property, which will handle adding it to the AnalysisDataService for you.

In between those two lines you could add whatever data you wanted to the workspace.

Let me know if you need any more help,
Nick Draper