Jump to content

Fixed write block

Recommended Posts

This fixed the outstanding bug where writing in an experiment would dump all csv files in the simulation root directory, ignoring the relative directories you specify in the file path in the file element. The fix was trivial, and I am sure I have raised it several times both on this forum. I made the fix a few months ago, and have kept meaning to post it here (if indeed I have not already). The problem with unofficial fixes is that it is another moving part to update, keep track of, and adds to installation complexity. I have lost previous fixes twice (due to fresh re-installs).

Essentially "fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName);" was the culprit.

I changed the "_writerFileName" directive from using the above variable to:

_writerFileName = "fileName + "_" + simioScenarioName + "_Rep" + simioReplicationNumber + fileExtension;"

I could do something neater (as the current output will have a ".csv" in the middle of the name), but did not spend any time on this. It would be appreciated if this was fixed and applied to the official write block (even if as a toggleable option), as due to the over-zealous licensing terms, the DLL will not load on an unlicensed client... meaning I have to choose between having the bug fixed and not dumping hundreds of thousands of CSV files in my simulation root... or causing clients considerable inconvenience by writing hundreds of thousands of CSV files into their simulation root.

Here is the relevant code extract in the file element:

            if (String.IsNullOrEmpty(fileName) == false)
               string fileRoot = null;
               string fileDirectoryName = null;
               string fileNameWithoutExtension = null;
               string fileExtension = null;

                   fileRoot = System.IO.Path.GetPathRoot(fileName);
                   fileDirectoryName = System.IO.Path.GetDirectoryName(fileName);
                   fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName);
                   fileExtension = System.IO.Path.GetExtension(fileName);
               catch (ArgumentException e)
                   data.ExecutionContext.ExecutionInformation.ReportError(String.Format("Failed to create runtime file element. Message: {0}", e.Message));

               string simioProjectFolder = _data.ExecutionContext.ExecutionInformation.ProjectFolder;
               string simioExperimentName = _data.ExecutionContext.ExecutionInformation.ExperimentName;
               string simioScenarioName = _data.ExecutionContext.ExecutionInformation.ScenarioName;
               string simioReplicationNumber = _data.ExecutionContext.ExecutionInformation.ReplicationNumber.ToString();

               if (String.IsNullOrEmpty(fileDirectoryName) || String.IsNullOrEmpty(fileRoot))
                   fileDirectoryName = simioProjectFolder;
                   fileName = fileDirectoryName + "\\" + fileName;

               _readerFileName = fileName;

               if (String.IsNullOrEmpty(simioExperimentName))
                   _writerFileName = fileName;
                   _writerFileName = fileName + "_" + simioScenarioName + "_Rep" + simioReplicationNumber + fileExtension;


Using relative file paths worked at one stage, and was later broken. Below are two threads with work around un-offical dlls that probably implement the fix nicer.

10/07/2012 - http://www.simio.com/forums/viewtopic.php?f=19&t=829

07/12/2012 - http://www.simio.com/forums/viewtopic.php?f=20&t=987



Share this post

Link to post
Share on other sites

Thanks for the feedback. The relative paths on experiments will be fixed the next sprint release (Sprint 98). The ExcelConnectElement.cs for the Excel Write step had the same issue. It will be fixed as well.

Share this post

Link to post
Share on other sites

What if I wanted each run to overwrite the output file? What it is doing now is writing output.csv file to:


What if I actually wanted to write to the output.csv file?

Thanks - Ricki.

Share this post

Link to post
Share on other sites