question

Will Bishop avatar image
2 Likes"
Will Bishop asked Will Bishop commented

Passing unknown param inputs in a user command

I am writing a user command ("query_getqueryvalue") that acts as a wrapper for the "query" command and "getqueryvalue" command -- this will run a query and get the first result value in one call.

I am wondering how to pass an unknown number of command inputs onto the 'query' command, since that function accepts an unknown number of inputs as dynamic query parameters (using the $ syntax). I basically want to pass any extra "..." command inputs (past the first 2) onto the internal 'query' call.

Right now I'm doing a hacky solution (below) that checks the number of inputs (with 'parqty()') and uses a switch statement to pass the right number of inputs onto 'query'. Is there a better way to do this in flexscript/C++?

  1. /**Custom Code*/
  2.  
  3.  
  4. // parameter inputs
  5. // (str col, str query[, node/num/str p1, node/num/str p2, ...])
  6. string col = parstr(1);
  7. string query_str = parstr(2);
  8. int par_count = parqty();
  9.  
  10.  
  11. // make a hacky 'query' call with the correct parameters (up to 8)
  12. switch (par_count)
  13. {
  14. case 2: query(query_str);
  15. case 3: query(query_str, param(3)); break;
  16. case 4: query(query_str, param(3), param(4)); break;
  17. case 5: query(query_str, param(3), param(4), param(5)); break;
  18. case 6: query(query_str, param(3), param(4), param(5), param(6)); break;
  19. case 7: query(query_str, param(3), param(4), param(5), param(6), param(7)); break;
  20. case 8: query(query_str, param(3), param(4), param(5), param(6), param(7), param(8)); break;
  21. case 9: query(query_str, param(3), param(4), param(5), param(6), param(7), param(8), param(9)); break;
  22. case 10: query(query_str, param(3), param(4), param(5), param(6), param(7), param(8), param(9), param(10)); break;
  23. default: query(query_str);
  24. }
  25.  
  26.  
  27. // get first query value
  28. var res = getqueryvalue(1, col);
  29. return(res);

See attached for a zip of my library "project" in response to @Arun KR -- this includes the source model file (source.fsx), along with input data and the output .fsl library file. The model includes this custom User Command.

tableusercommands.zip

FlexSim 16.2.0
user command
· 4
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

Phil BoBo avatar image
1 Like"
Phil BoBo answered Will Bishop commented

Your hacky solution may not be pretty, but it should work fine.

It's a good solution.

· 1
5 |100000

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