Passing unknown param inputs in a user command

Passing unknown param inputs in a user command

will_bishop
Not applicable
39 Views
6 Replies
Message 1 of 7

Passing unknown param inputs in a user command

will_bishop
Not applicable

[ FlexSim 16.2.0 ]

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.

2592-2016-09-22-17-08-32-flexsim-2016-user-commandsfsx.png

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++?

/**Custom Code*/


// parameter inputs
// (str col, str query[, node/num/str p1, node/num/str p2, ...])
string col = parstr(1);
string query_str = parstr(2);
int par_count = parqty();


// make a hacky 'query' call with the correct parameters (up to 8)
switch (par_count) 
{
	case 2: query(query_str);
	case 3: query(query_str, param(3)); break;
	case 4: query(query_str, param(3), param(4)); break;
	case 5: query(query_str, param(3), param(4), param(5)); break;
	case 6: query(query_str, param(3), param(4), param(5), param(6)); break;
	case 7: query(query_str, param(3), param(4), param(5), param(6), param(7)); break;	
	case 8: query(query_str, param(3), param(4), param(5), param(6), param(7), param(8)); break;	
	case 9: query(query_str, param(3), param(4), param(5), param(6), param(7), param(8), param(9)); break;	
	case 10: query(query_str, param(3), param(4), param(5), param(6), param(7), param(8), param(9), param(10)); break;	
	default: query(query_str); 
} 


// get first query value
var res = getqueryvalue(1, col);
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

Accepted solutions (1)
40 Views
6 Replies
Replies (6)
Message 2 of 7

joerg_vogel_HsH
Mentor
Mentor
0 Likes
Message 3 of 7

philboboADSK
Autodesk
Autodesk
Accepted solution

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

It's a good solution.



Phil BoBo
Sr. Manager, Software Development
Message 4 of 7

will_bishop
Not applicable

It does work......which is the first and most important step.

I'll be satisfied with it until I hit another similar case where things break down.

0 Likes
Message 5 of 7

arunTTT2P
Explorer
Explorer

Can you post a sample model?

0 Likes
Message 6 of 7

mischa_spelt
Advisor
Advisor

@Will Bishop - unrelated: you are missing a break in the first case (par_count == 2).

0 Likes
Message 7 of 7

will_bishop
Not applicable

Ah, thanks @Mischa Spelt! Good catch.

0 Likes