FlexScript code doubt

FlexScript code doubt

TiradoEduardo
Participant Participant
571 Views
7 Replies
Message 1 of 8

FlexScript code doubt

TiradoEduardo
Participant
Participant

Hi, I'm trying to customize a code that whenever there is a word on the cell (1,2), the value of the cell(3,1) changes directly to 2, in case it is empty, it will stay on 1. 

 

I'm trying with this code but im not getting any result: 

treenode tab = Model.find("Tools/GlobalTables/Operators");

 

int rows = gettablerows(tab);

 

for(int r = 1; r <= rows ; r++)
{
  string op2 = gettablestr(tab, r , 2);

  if(stringlen(op2)==0)
  {
  settablenum(tab, r, 3, 1);  
  }  
  else 
  {
    settablenum(tab, r , 3 , 2);
  }
}

 

 

0 Likes
Accepted solutions (1)
572 Views
7 Replies
Replies (7)
Message 2 of 8

kavika_faleumu
Autodesk
Autodesk

Hey @TiradoEduardo, have you tried using the Table API? This will allow you to more easily get and set data on a table. The commands you're using are deprecated (according to the documentation).

 

Also, you say "whenever there is a word on cell X", what do you mean by that? Is this table dynamically updating? If so, when are you rechecking the cell value for a word? Not checking the value when the table gets updated may be the source of the issue too.

0 Likes
Message 3 of 8

TiradoEduardo
Participant
Participant

Hi Kavika, haven't used the API yet, I'll check it out!

 

What I meant with the word on cell is because I'm using a GUI for modifying the number of connections on a dispatcher. So instead of writing : 1 or 2 operators in the cell of the table, I want that whenever something is written on the second cell, the third cell automatically changes to 2 ( 1 in the opposite case)

 

0 Likes
Message 4 of 8

kavika_faleumu
Autodesk
Autodesk

@TiradoEduardo, you could update the automatically changing cell to be some Flexscript that evaluates to a value based on the cell with a word in it. For example,

Table table = Table("MyTable");
int row = 1;
int wordCol = 1;
int operatorsCol = 2;

string word = table[row][wordCol];
return word == "" ? 1 : 2;

Setup: you have a Table called "MyTable", the cells you care about are in row 1, the changing word cell is in column 1, and the number of operators you want to change is in column 2. You can check to see what the "word" is in the word cell (i.e., table[1][1]) to see if anything is there. If nothing is there (word == ""), then return a 1. If something is there, then return a 2.

 

Here's a GIF showing how it would work.

 

Changing Table Data.gif

 

Some things to note:

1. This solution wouldn't scale very well since each cell would need different code for the current row and column. You could definitely set it up differently though.

2. It kinda sounds like you want to use a Parameter instead. With Model Parameters, you're able to easily change the number of operators and add connections at the same time.

Num Operators Parameter.gif

 

First, attach the Dispatcher to the Operator. Then add the Operator to a Group.

kavika_faleumu_0-1765819497994.png

Next, add a Model Parameter for your Operators. Click on the "Value" cell to edit the parameters.

kavika_faleumu_1-1765819535902.png

You can set a Lower and Upper bound for the value, set the reference to the Group, and then add a trigger. There is an "On Set" trigger for deleting and copying group members, so you can easily change the number of things in the group. In this case, it will delete all existing copies of the Operator except the original. Then it will duplicate the original (including its connections).

 

Hope this helps!

0 Likes
Message 5 of 8

TiradoEduardo
Participant
Participant

Hi, thanks for the quick response.

 

I'm not getting the same result with the code you sent. I originally wanted to use the parameters way but with the GUI, i couldn't make it work so I chose to work directly with the table. The thing also is that I have 10 stations where i want to apply the code.

 

Can you please attach the file where you worked with that code? To see what I am doing wrong. 

0 Likes
Message 6 of 8

kavika_faleumu
Autodesk
Autodesk
Accepted solution

Sure thing, I'll attach the model with this comment. I think parameters would be much easier than manually adjusting table cells and copy/pasting a bunch of code.

0 Likes
Message 7 of 8

TiradoEduardo
Participant
Participant

Great, thanks! Do you have any example on referencing a parameter on a customized GUI?

0 Likes
Message 8 of 8

kavika_faleumu
Autodesk
Autodesk

You can programmatically get the parameters within a model by calling

Model.parameters.parameterName

 replacing "parameterName" with the name of your parameter (NumOperators in my case). You should be able to use this in your custom GUI.

0 Likes