ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Tips and Tricks
Downloads

Tips and Tricks Share helpful modeling ideas

  #1  
Old 08-03-2007
Regan Blackett Regan Blackett is offline
Flexsim Consultant, Forum Moderator
 
Join Date: Jul 2007
Posts: 14
Downloads: 19
Uploads: 16
Thanks: 0
Thanked 14 Times in 6 Posts
Rep Power: 183
Regan Blackett will become famous soon enoughRegan Blackett will become famous soon enough
Default How to get a full path of the current open Flexsim model file.

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:


Code:
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:

Code:
string winTitle = getviewtext((treenode)systemwindow(0));
  #2  
Old 03-31-2008
Sung Kim Sung Kim is offline
Flexsim User
 
Join Date: Jan 2008
Location: York, PA
Posts: 85
Downloads: 70
Uploads: 0
Thanks: 70
Thanked 9 Times in 6 Posts
Rep Power: 160
Sung Kim is on a distinguished road
Default modeldir command

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?
  #3  
Old 03-31-2008
Jeff Nordgren's Avatar
Jeff Nordgren Jeff Nordgren is offline
Technical Support Manager
 
Join Date: Jul 2007
Location: Orem, UT
Posts: 65
Downloads: 79
Uploads: 0
Thanks: 40
Thanked 21 Times in 17 Posts
Rep Power: 233
Jeff Nordgren is just really niceJeff Nordgren is just really niceJeff Nordgren is just really niceJeff Nordgren is just really nice
Default

Quote:
Originally Posted by Sung Kim View Post
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.
__________________
Jeff
Flexsim Support
  #4  
Old 04-01-2008
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

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
__________________
thats not normal.
  #5  
Old 04-01-2008
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

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.
  #6  
Old 04-17-2008
Regan Blackett Regan Blackett is offline
Flexsim Consultant, Forum Moderator
 
Join Date: Jul 2007
Posts: 14
Downloads: 19
Uploads: 16
Thanks: 0
Thanked 14 Times in 6 Posts
Rep Power: 183
Regan Blackett will become famous soon enoughRegan Blackett will become famous soon enough
Default

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:

Code:
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

Code:
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.

Last edited by Regan Blackett; 04-17-2008 at 10:25 AM.
The Following User Says Thank You to Regan Blackett For This Useful Post:
Jörg Vogel (08-01-2014)
  #7  
Old 04-17-2008
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

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
  #8  
Old 04-17-2008
Regan Blackett Regan Blackett is offline
Flexsim Consultant, Forum Moderator
 
Join Date: Jul 2007
Posts: 14
Downloads: 19
Uploads: 16
Thanks: 0
Thanked 14 Times in 6 Posts
Rep Power: 183
Regan Blackett will become famous soon enoughRegan Blackett will become famous soon enough
Default

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.



All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.