<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to get a label using a variable? in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583792#M81125</link>
    <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;You forgot the less than character in your for loop end condition:&lt;/P&gt;&lt;PRE&gt;for (int i = 1; i = headers.numCols; i++)&lt;/PRE&gt;&lt;P&gt;but should be&lt;/P&gt;&lt;PRE&gt;for (int i = 1; i &amp;lt;= headers.numCols; i++)&lt;/PRE&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 19 May 2023 21:33:39 GMT</pubDate>
    <dc:creator>Matthew_Gillespie</dc:creator>
    <dc:date>2023-05-19T21:33:39Z</dc:date>
    <item>
      <title>How to get a label using a variable?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583789#M81122</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 23.1.0 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;I am trying to use a string variable in a reference to a patient label, to check the value of multiple labels inside a loop inside of an Assign Labels object.&lt;/P&gt;
 &lt;P&gt;When tokens enter this Assign Labels, they have several labels set to 0 or 1 depending on whether they need certain imaging tests.&lt;/P&gt;
 &lt;P&gt;The new label value should be a 0 if all of several labels are set to 0, or 1 if there are any labels set to 1.&lt;/P&gt;
 &lt;P&gt;I am currently assigning these labels to the patient (they are "xray", "ct", etc. 0/1 for each) and trying to evaluate them by referencing the list in a table, as pictured below:&lt;/P&gt;
 &lt;PRE&gt;/**Custom Code*/&lt;BR /&gt;Object current = param(1);
Object patient = current;
treenode activity = param(2);
Token token = param(3);
Variant assignTo = param(4);
string labelName = param(5);
treenode processFlow = ownerobject(activity);

print(patient);


int imgCount = 0; // set count of imaging processes to 0

// check the table of imaging assignment values for imaging names
Table headers = Model.find("Tools/GlobalTables/ptFlowPcts");

print(headers);
print(headers.numCols);

for (int i = 1; i = headers.numCols; i++){ // loop through the number of columns
&amp;nbsp; &amp;nbsp; string img = headers.getColHeader(i); // get the column name (imaging type) for each loop
&amp;nbsp; &amp;nbsp; imgCount += patient.img; // try to get the 0 or 1 value of this label
}
if (imgCount = 0){
&amp;nbsp; &amp;nbsp; return 0; // return 0 (no) only if there are no imaging called for
}
else{
&amp;nbsp; &amp;nbsp; return 1; // return 1 if one or more imaging is called for
}&lt;/PRE&gt;
 &lt;P&gt;The question at hand is: how can i reference a label on a patient using a variable, so that I can check an arbitrary number of labels in a code block? I have tried a few different things:&lt;/P&gt;
 &lt;UL&gt;&lt;LI&gt;&lt;PRE&gt;label(patient, img)&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;&lt;PRE&gt;patient.img&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;&lt;PRE&gt;patient."img"&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;&lt;PRE&gt;patient.labels[img].value&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;&lt;PRE&gt;patient.labels[img].evaluate()&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;... and every other combination I could come up with.&lt;/LI&gt;&lt;LI&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;/UL&gt;
 &lt;P&gt;Some of them led to a crash, some just threw an exception saying the label didn't exist. I am at the point where I just have to say I don't know how this should work.&lt;/P&gt;
 &lt;P&gt;---&lt;/P&gt;
 &lt;P&gt;Ideally I would just have a label that contains an array with a list of imaging randomly assigned based on our client data. And now that I think about it, I should be able to do that with code. But I'd still like to know better how to do what I described above.&lt;/P&gt;
 &lt;P&gt;Thanks in advance, you are all always so helpful!&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 18 May 2023 22:05:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583789#M81122</guid>
      <dc:creator>cphilpottX22K5</dc:creator>
      <dc:date>2023-05-18T22:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a label using a variable?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583790#M81123</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;The correct way to get a label node from a string variable is&lt;/P&gt;&lt;PRE&gt;patient.labels[img]&lt;/PRE&gt;&lt;P&gt;Then to get the value off that node you can use .value or .evaluate() if you want it to execute a FlexScript node:&lt;/P&gt;&lt;PRE&gt;patient.labels[img].value
patient.labels[img].evaluate()&lt;/PRE&gt;&lt;P&gt;Here's an example model that demonstrates it working&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68321-labelfromstring.fsm" target="_blank"&gt;LabelFromString.fsm&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 18 May 2023 23:01:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583790#M81123</guid>
      <dc:creator>Matthew_Gillespie</dc:creator>
      <dc:date>2023-05-18T23:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a label using a variable?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583791#M81124</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;It turns out that I was getting the label correctly. It only threw an exception when I tried one of the invalid ways to get the label.&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
 &lt;P&gt;The code is crashing in the for loop. For some reason the following bit returns a seemingly infinite number of empty lines:, even when headers.numCols is replaced with a low integer like 5&lt;/P&gt;
 &lt;PRE&gt;
  &lt;UL&gt;&lt;LI&gt;for (int i = 1; i = headers.numCols; i++){ // loop through the number of columns&lt;/LI&gt;&lt;LI&gt;&amp;nbsp; &amp;nbsp; string img = headers.getColHeader(i); // get the column name (imaging type) for each loop&lt;/LI&gt;&lt;/UL&gt;&lt;/PRE&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 19 May 2023 21:23:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583791#M81124</guid>
      <dc:creator>cphilpottX22K5</dc:creator>
      <dc:date>2023-05-19T21:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a label using a variable?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583792#M81125</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;You forgot the less than character in your for loop end condition:&lt;/P&gt;&lt;PRE&gt;for (int i = 1; i = headers.numCols; i++)&lt;/PRE&gt;&lt;P&gt;but should be&lt;/P&gt;&lt;PRE&gt;for (int i = 1; i &amp;lt;= headers.numCols; i++)&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 19 May 2023 21:33:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583792#M81125</guid>
      <dc:creator>Matthew_Gillespie</dc:creator>
      <dc:date>2023-05-19T21:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a label using a variable?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583793#M81126</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Thanks. I had figured this out and meant to update but looks like I never came back to it.
&lt;/DIV&gt;</description>
      <pubDate>Tue, 06 Jun 2023 20:43:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-get-a-label-using-a-variable/m-p/13583793#M81126</guid>
      <dc:creator>cphilpottX22K5</dc:creator>
      <dc:date>2023-06-06T20:43:22Z</dc:date>
    </item>
  </channel>
</rss>

