question

Luis Gustavo Freitas avatar image
0 Likes"
Luis Gustavo Freitas asked Eric M edited

Replacedata_s() parameter's addition

I'm struggling to make a search and replace code that read what to change by global table lookup, so a made a few notes about the command replacedata_s() that I'm using in my logic and I think could help others.

I'm working with equipment TAG, the global table ("ChangeTAG") contains 2 columns with the old and new tags (PX_09, PX_10 and PX_1040XX_09, PX_1040XX_10 for example), that must be changed in other global tables, object names... i.e. other nodes, and for that using replacedata_s() and replacename(). However I would like that the replacedata_s() do not change the strings in my "ChangeTAG" table, so instead of just provide the obj startnode as parameter, an option to give a obj stopnode or an exception to not access a node.

Another point, as you can see, by searching the PX_10 tag, the command replacedata_s() will replace not just the PX_10 tag but also PX_1040XX_09 and PX_1040XX_10, and as "ChangeTAG" is read by a for code (you can see the code bellow) the replacedata_s() will chage the table and depending on the sequence, the new PX_09 TAG change to PX_1040XX_1040XX_09 because the command replace substrings also, a parameter to choose between exact and approximate match would be very helpful.


Table v_gt_Change_Tags = Table("ChangeTAG");

for (int iTAG = 1; iTAG <= v_gt_Change_Tags.numRows; iTAG++){

  string v_str_Before = v_gt_Change_Tags[iTAG][1];

  string v_str_After = v_gt_Change_Tags[iTAG][2];

  replacedata_s(maintree(), v_str_Before, v_str_After);

  replacename(maintree(), v_str_Before, v_str_After);
}


For now I'm segregating the replace commands and the "ChangeTAG" reading into 2 for (to save the TAGs into an array before start to replace them), with the replace's for going thru every bottom node so I can make an if condition to not enter into "ChangeTAG" table. Accepting any ideas to reduce the code.

FlexSim 21.1.4
suggestionreplacefind and replacesearch and replace
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Eric M avatar image
0 Likes"
Eric M answered Eric M edited

Here are a couple of ideas that might simplify things a bit. Instead of using an if condition to skip certain nodes, just let the replacedata_s command replace everything and then immediately change the table back to what it was before. You can see how I did this in the first script.

As far as avoiding the difference between exact and approximate matches, I would just make sure the After column never has an exact match to anything in the Before column (it would be nice to have an exact vs approx option). I did this by making the After column "PX__" instead of "PX_".

I've attached a small model that I was using so you can see what I was thinking. The first script changes the names and the second script reverts back to the original values.

replacedata option.fsm


5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.