Simio
  • Fixed write block

  • Do you have objects, models, libraries, path decorators, textures, symbols, custom API code, documentation, or anything else others might find useful? Please attach it here with a brief description.
Do you have objects, models, libraries, path decorators, textures, symbols, custom API code, documentation, or anything else others might find useful? Please attach it here with a brief description.
 #4970  by jdoran
 Sun Jan 05, 2014 7:25 pm
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:
Code: Select all
            if (String.IsNullOrEmpty(fileName) == false)
            {
                string fileRoot = null;
                string fileDirectoryName = null;
                string fileNameWithoutExtension = null;
                string fileExtension = null;

                try
                {
                    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;
                else
                    _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
Attachments
(59.39 KiB) Downloaded 554 times
(6.11 KiB) Downloaded 527 times
 #4985  by gtwirth
 Thu Jan 09, 2014 2:25 pm
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.
 #4988  by jdoran
 Thu Jan 09, 2014 4:29 pm
Great!
 #4990  by jzhou
 Thu Jan 09, 2014 10:14 pm
It's great. it save us a lot of time to assign long path name
 #7549  by rgingalls
 Mon Jun 13, 2016 3:36 pm
What if I wanted each run to overwrite the output file? What it is doing now is writing output.csv file to:
output_Scenario1_Rep1.csv

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

Thanks - Ricki.