I am attempting to have my model create an excel document in the windows directory that the model file is in. After that, I am attempting to read from this excel file. To do this without regard to what user account on the computer is using the model at the moment, I tried using the global windows environment variables in order to locate the current user's desktop, see example.
This does not work. Typing the absolute path (C:\users....\File.xlsx) works fine, however it doesn't solve the problem of multiple users. Writing to the root C:\ drive is not an option.
How do I have plant simulation create an Excel-file in the same directory that the model is run from, and what path should I type in the readExcelFile() method to find the excel file created?
Solved! Go to Solution.
you can use the function getenv to get the value of the environment variable USERPROFILE.
So something like this should work:
modelFile returns the full path and modelFileName, which is suitable in my application.
However there may be cases when just the filename is needed.
For future reference, and for others who may need this form, is there a way to get that?
(I realise that using string extraction may be the best solution)
And while this thread is open, (if there is a way) how can a method access its own name?
My reporting methods log the model name and execution timestamp, and it would also be useful for the reporting methods to identify their own names, to keep track of multiple nested reporting methods.