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 |
#1
|
|||
|
|||
Checking to see if a label exists
Hi,
I was wondering how i check to see if a label exists. Have tried objectexists(label(item,"sampleLabel")) but it doesn't work, (presumeably because a label isn't an object but a variable?) I have also tried an if statement querying the label value but it appears neither the if or else blocks are entered if the label doesn't exist. Thanks Paul |
#2
|
||||
|
||||
Paul,
I am not sure what happens in your case but for me it is working. I used the following code in an OnEntry trigger and the print in the Output Console is as expected. if(objectexists(label(item,"sampleLabel"))) {pr();pt("Label exists!");} else {pr();pt("Label does not exists!");} The return you get from objectexists() is 1 (TRUE) or 0 (FALSE). I am sure you know that labels because they are strings are case sensitive. So it makes a difference if you write SampleLabel or sampleLabel. Anyway, please try again and tell us what you figure out. Good success. tom the (A)tom P.S.: objectexists() works for nodes so it does not matter if it is a label, a variable or an object.
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions." |
The Following User Says Thank You to Tom David For This Useful Post: | ||
Paul Dowling (04-28-2008) |
#3
|
||||
|
||||
Some points to keep in mind:
1) If a label doesn't exist it will return 0 as it's value. 2) Labels are nodes inside of the "labels" node inside of the object. The objectexists() command is checking to see if the node exists or not, so it doesn't matter if you pass it an actual object node or any other type of node. 3) Instead of the label name you can use its rank in the label, getlabelnum/str, and setlabelnum/str commands. This reduces the chance or spelling the label name wrong but increases the chance of getting the wrong label if you are unsure of its rank. Based on your post I would make a quick check of your if statements to make sure that you are using "==" and not "=". The double equal sign is a check for equallity and the single equal sign is used for setting onething equal to another. This is a common mistake. The formula Tom provided should get you the result you are looking for. If you are checking to see if the label does not exist, simply put a "!" infront of the "objectexists" command in Tom's forumula. Good Luck, Brandon
__________________
thats not normal. |
The Following User Says Thank You to Brandon Peterson For This Useful Post: | ||
Paul Dowling (04-28-2008) |
#4
|
|||
|
|||
Thanks Tom/ Brandon,
Unfortuneately i didn't keep my original model i was testing this stuff in but i have clearly stuffed something up (wouldn't be the first time i used an assignment operator by mistake i admit) Tom your code worked perfectly and i also tried it using your first point Brandon to achieve the same thing (returning a value of 0 if it doesn't exist) and both worked perfectly. Nice to know that object is a generic term for all nodes, my malfunctioning model had me second guessing myself there... Cheers Paul |
Thread | Thread Starter | Forum | Replies | Last Post |
Checking nodeedge status | Maurits Brandt | Q&A | 4 | 09-15-2008 05:43 AM |