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 > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 04-27-2008
Paul Dowling Paul Dowling is offline
Flexsim User
 
Join Date: Aug 2007
Location: Sydney, Australia
Posts: 42
Downloads: 14
Uploads: 0
Thanks: 12
Thanked 4 Times in 4 Posts
Rep Power: 161
Paul Dowling is on a distinguished road
Default 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  
Old 04-27-2008
Tom David's Avatar
Tom David Tom David is offline
Flexsim User
 
Join Date: Aug 2007
Location: Schwaebisch Gmuend, Germany
Posts: 430
Downloads: 157
Uploads: 47
Thanks: 486
Thanked 450 Times in 233 Posts
Rep Power: 520
Tom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant future
Default

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  
Old 04-28-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

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  
Old 04-28-2008
Paul Dowling Paul Dowling is offline
Flexsim User
 
Join Date: Aug 2007
Location: Sydney, Australia
Posts: 42
Downloads: 14
Uploads: 0
Thanks: 12
Thanked 4 Times in 4 Posts
Rep Power: 161
Paul Dowling is on a distinguished road
Default

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


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.