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

/**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

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.

Arun Kr avatar image Arun Kr commented ·

Can you post a sample model?

0 Likes 0 ·
Mischa Spelt avatar image Mischa Spelt commented ·

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

0 Likes 0 ·
Will Bishop avatar image Will Bishop Mischa Spelt commented ·

Ah, thanks @Mischa Spelt! Good catch.

0 Likes 0 ·

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.

Will Bishop avatar image Will Bishop commented ·

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 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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