PDA

View Full Version : How to get a full path of the current open Flexsim model file.


Regan Blackett
08-03-2007, 12:07 PM
Unfortunately, there is no direct command to do that. However, since the model file path is in the title of the Flexsim window. You may use the following command to get the Flexsim window title, then parse it to get the path. See:


string winTitle = getviewtext(systemwindow(0));
pt("Window title is ");pt(winTitle);pr();
string fullModelPath = stringpart(winTitle,10,stringlen(winTitle));
pt("Model file path is ");pt(fullModelPath);pr();Note the above code will work in the script window as Flexscript. In C++, you have to modify the first line to the following to be able to compile it:

string winTitle = getviewtext((treenode)systemwindow(0));

Sung Kim
03-31-2008, 02:12 PM
I found modeldir flexscript command. Based on the description, it is supposed to return the path of the currently open model's directory. I tried it, but null value is returned.

pt(modeldir());pr();

Could anybody tell what is wrong?

Jeff Nordgren
03-31-2008, 02:45 PM
I found modeldir flexscript command. Based on the description, it is supposed to return the path of the currently open model's directory. I tried it, but null value is returned.

pt(modeldir());pr();

Could anybody tell what is wrong?


Are you looking in the output console or in the Script window? It will "print" to the output console. It works fine on my machine.

Brandon Peterson
04-01-2008, 11:01 AM
Sung,

If you want to see the directory in the script window just put in the following code:

modeldir()

And then hit Execute. Please note, that if you do this when you are viewing a blank model or a model that has not been saved yet then you will get NULL as the answer because there is no model directory yet. You have to load a model that has been saved or save the model you are looking at first.

Good Luck,
Brandon

Anthony Johnson
04-01-2008, 11:51 AM
Also, you can use the currentfile() command to access the full model path. Note that when Regan initially posted (August 2007), these commands did not exist, so the very first post for this thread was correct at the time it was posted, but modeldir() and currentfile() now give you access to the path of the model and its directory. These commands were added to 4.3.

Regan Blackett
04-17-2008, 09:53 AM
It's also important to note that modeldir() appears to behave differently on MS Vista compared to XP. Under Vista calling modeldir() will return something like "C:\Program Files\Flexsim4\userprojects\", note the trailing slash at the end of the userprojects directory. Under XP that slash is omitted, and would appear like: "C:\Program Files\Flexsim4\userprojects". Where this gets important is if you wanted to get access to a file that was in the same directory as the model and did the following:


string path = concat(modeldir(),"myfile");
pt(path);pr();
Under Vista, this would be fine, since it'll give the proper trailing slash, so the result would read: "C:\Program Files\Flexsim4\userprojects\myfile". However under XP, the result would read "C:\Program Files\Flexsim4\userprojectsmyfile". If you're using XP, you would have to add the slash yourself as follows


string path = concat(modeldir(),"\\myfile");
pt(path);pr();
Note the double slash since a single slash is an "escape" character. It'd probably be a good rule of thumb to just do things the XP way to avoid any confusion, since any extra slashes in the path string will be ignored.

Lars-Olof Leven
04-17-2008, 10:14 AM
Hi Regan,

Are you sure about the behaviour of modeldir() under XP?
When I try modeldir() on my system that is Win XP, I get
a trailing slash. I get "C:\Program Files\Flexsim4\userprojects\"
under XP.

Lars-Olof

Regan Blackett
04-17-2008, 10:39 AM
I've heard from a couple of people now that they are getting the correct trailing slash when using modeldir under XP. Which is troubling since, I'd "discovered" the inconsistency during a support issue this morning where the user's XP machine wasn't adding the trailing slash, but my Vista machine was. The way we fixed the issue was by adding slashes to the file name he was concating with.