ATTENTIONThis 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 |
|
Downloads |
Q&A Using Flexsim and building models |
#1
|
||||
|
||||
Open _TD models directly from the Windows Explorer with double click
Some of you guys might remember that there was sometimes a problem with my models (_TD) if they have been opened directly with double click from the windows explorer. That’s why I always said, you should never do it.
Today I searched for the source of the issue and expected it in my Model Control GUI, but luckily I found the problem after 15 minutes in the Visual Tool “Modelname”. I was reading the path and file name from the node tempfilename *string* sPathModelname = getnodestr(node("/exec/globals/nodevariables/tempfilename",up(model()))); If you start the model directly from the Explorer this node is not updated correctly (in my case it is: C:\Program Files (x86)\Flexsim4 Dev\userprojects) and did not have the path and model name stored. That’ also why the name is not shown correct. The key is to use the command currentfile() and also check if extract the model name from the string sPathModelname with stringcopy() to check that not a negative value is pass to the stringcopy command. Thanks to Phil for this information. Phil also puts a check now in the command stringcopy() to prevent that Flexsim will crash. I thought I let you know, because I updated now all my models with the new code, but I will not upload all the models again. If you see how many models I already uploaded, I guess, you understand why. I am pretty sure I will update all my models with v5, so I will not do it now. Clear statement: Opening Flexsim models directly from the Windows Explorer is possible and works; now even with my models (_TD) … Here is the old and new code, just if people are interested in what is changed now. Old code: Code:
/**TD: Show model name*/ treenode current = ownerobject(c); treenode textnode = parnode(1); // GET PATH AND MODEL NAME string sPathModelname = getnodestr(node("/exec/globals/nodevariables/tempfilename",up(model()))); // GET STRING LENGTH OF PathModelname int iStringLengthPathModelname = stringlen(sPathModelname); // GET PATH MODEL DIRECOTRY string sPathModelDir = modeldir; // GET STRING LENGTH OF PATH MODEL DIRCTORY int iStringLengthPathModelDir = stringlen(sPathModelDir); // GET MODELNAME STILL PLUS .fsm string sModelNameFSM = stringcopy(sPathModelname,iStringLengthPathModelDir + 1,iStringLengthPathModelname); // GET STRING LENGTH MODEL NAME FSM int iStringLengthModelNameFSM = stringlen(sModelNameFSM); // GET ONLY MODELNAME (WITHOUT FSM) string sModelName= stringcopy(sModelNameFSM,1,iStringLengthModelNameFSM - 4); // SET TEXT TO Modelname AND WRITE INTO TEXTNODE string text = sModelName; setnodestr(textnode,text); // RETURN ONE return 1; Code:
/**TD: Show model name*/ treenode current = ownerobject(c); treenode textnode = parnode(1); // GET PATH AND MODEL NAME string sPathModelname = currentfile(); // GET STRING LENGTH OF PathModelname int iStringLengthPathModelname = stringlen(sPathModelname); // GET PATH MODEL DIRECOTRY string sPathModelDir = modeldir(); // GET STRING LENGTH OF PATH MODEL DIRCTORY int iStringLengthPathModelDir = stringlen(sPathModelDir); // GET MODELNAME STILL PLUS .fsm string sModelNameFSM = ""; if(iStringLengthPathModelDir > 0) {sModelNameFSM = stringcopy(sPathModelname,iStringLengthPathModelDir + 1,iStringLengthPathModelname);} // GET STRING LENGTH MODEL NAME FSM int iStringLengthModelNameFSM = stringlen(sModelNameFSM); // GET ONLY MODELNAME (WITHOUT FSM) string sModelName = ""; if(iStringLengthModelNameFSM - 4 > 0) {sModelName = stringcopy(sModelNameFSM,1,iStringLengthModelNameFSM - 4);} // SET TEXT TO Modelname AND WRITE INTO TEXTNODE string text = sModelName; setnodestr(textnode,text); // RETURN ONE return 1;
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions." |
The Following 5 Users Say Thank You to Tom David For This Useful Post: | ||
zhang xin (11-18-2009) |
Thread | Thread Starter | Forum | Replies | Last Post |
Windows Vista | Jeff Nordgren | Installation | 3 | 04-22-2009 02:11 AM |
Double click to execute the onpress function | sophia yao | Q&A | 4 | 07-15-2008 08:53 PM |
Double load handling ASRS | Paul Dowling | Q&A | 8 | 05-06-2008 10:19 PM |
Unable to move the view by left-click dragging? | Regan Blackett | Tips and Tricks | 0 | 08-03-2007 10:01 AM |