ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Flexsim Student Forum
FAQ Downloads Calendar Search Mark Forums Read

Flexsim Student Forum Forum for discussion for Flexsim Students using the Flexsim Textbook.

Reply
 
Thread Tools Display Modes
  #1  
Old 12-06-2012
mearjun mearjun is offline
Flexsim User
 
Join Date: Feb 2012
Posts: 123
Downloads: 5
Uploads: 0
Thanks: 27
Thanked 19 Times in 11 Posts
Rep Power: 113
mearjun will become famous soon enough
Default How to write a User Command ?

Can some one explain with a small example as to how to write a user command.. The info in the user manual is insufficient for a novice user like me.. a sample code or model will be really helpful..
Thanks..
Reply With Quote
  #2  
Old 12-07-2012
Esther Bennett Esther Bennett is offline
Flexsim User
 
Join Date: Mar 2008
Posts: 115
Downloads: 27
Uploads: 0
Thanks: 103
Thanked 116 Times in 50 Posts
Rep Power: 265
Esther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to all
Default

Hello,

I am not sure what is unclear to you, but if you just add a usercommand and press apply and then open a script window and the output console, you will see that when you call the user command in the script (command1() ) a message is printed to the output console (command1 executed).

Esther
Reply With Quote
  #3  
Old 12-07-2012
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 767
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

A recap posted here.
Reply With Quote
  #4  
Old 12-07-2012
mearjun mearjun is offline
Flexsim User
 
Join Date: Feb 2012
Posts: 123
Downloads: 5
Uploads: 0
Thanks: 27
Thanked 19 Times in 11 Posts
Rep Power: 113
mearjun will become famous soon enough
Default

here is what I am looking to do. The following read the code on the on processfinish trigger of the multiprocessor. And I have 25 multiprocessors.
/**RECORD WTBS AND UPDATE LOOP*/
treenode item = parnode(1);
treenode current = ownerobject(c);
int opnum = parval(2);
if (opnum != 8) setlabelnum(current,"Process",getlabelnum(current, "Process")+1);
int loop = getlabelnum(item,"Loop");
/**if (opnum == 3 && loop == 0) settablenum("WTBS",getlabelnum(item,"Patient Number"),1,time - getlabelnum(current,"Arrival Time"));*/
if (opnum == 2) freeoperators(centerobject(current,1),item);
if (opnum == 4) freeoperators(centerobject(current,2),item);
if (opnum == 4 && loop == 0 ) settablenum("WTBS",getlabelnum(item,"Patient Number"),1,getlabelnum(current,"WTBS"));
if (opnum == 6) freeoperators(centerobject(current,1),item);
if (opnum == 8) setlabelnum(item,"Loop",getlabelnum(item,"Loop") + 1);
if (opnum == 8) setlabelnum(current,"Loop",getlabelnum(current,"Lo op") + 1);


Now i want that I can convert all of this code into one command that I can write on the onprocessfinish trigger. So that next time I have to make a change I can simply change the user command instead of making a change then cpoying and pasting it everywhere.. so the question is:
What are going to be the parameters ?
What is going to be the code ? Does it work any different meaning do I have to declare different variables or anything?
That is why I had asked for an example. The post that is mentioned.. I have read it and could not get much..
Reply With Quote
  #5  
Old 12-07-2012
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 767
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

On each object's processfinishtrigger you'll have:

myprocesstrigger(current,item,opnum);


Then in the user command you set up the variables:

treenode current=parnode(1);
treenode item=parnode(2);
int opnum=parval(3);

In the parameters section you should enter something like:

(obj processor, obj item, num opnum)

..but here the names don't relate to the code, it's the types that are important as they're used to check you're passing the correct types when you call the command. The parameters do pop up when you're typing the command name so try and make them useful descriptions of the parameters you're meant to pass in.
Reply With Quote
The Following User Says Thank You to Jason Lightfoot For This Useful Post:
mearjun (12-07-2012)
  #6  
Old 12-07-2012
mearjun mearjun is offline
Flexsim User
 
Join Date: Feb 2012
Posts: 123
Downloads: 5
Uploads: 0
Thanks: 27
Thanked 19 Times in 11 Posts
Rep Power: 113
mearjun will become famous soon enough
Default

Thanks a ton for that explanation.. so the code inside the user command named myprocesstrigger or whatever I call it will be:

treenode current=parnode(1);
treenode item=parnode(2);
int opnum=parval(3);

if (opnum != 8) setlabelnum(current,"Process",getlabelnum(current, "Process")+1);
int loop = getlabelnum(item,"Loop");
/**if (opnum == 3 && loop == 0) settablenum("WTBS",getlabelnum(item,"Patient Number"),1,time - getlabelnum(current,"Arrival Time"));*/
if (opnum == 2) freeoperators(centerobject(current,1),item);
if (opnum == 4) freeoperators(centerobject(current,2),item);
if (opnum == 4 && loop == 0 ) settablenum("WTBS",getlabelnum(item,"Patient Number"),1,getlabelnum(current,"WTBS"));
if (opnum == 6) freeoperators(centerobject(current,1),item);
if (opnum == 8) setlabelnum(item,"Loop",getlabelnum(item,"Loop") + 1);
if (opnum == 8) setlabelnum(current,"Loop",getlabelnum(current,"Lo op") + 1);

and then rest is just text which I can call whatever I want..

It will be great if u could briefly explain how paraval and parnode commands work. I am not able to understand that from the user manual.. I have tons of other code which I would like to do this way as well. It will cut my work to 1/10th of what it is now..
Reply With Quote
  #7  
Old 12-08-2012
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 767
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

To get the parameters passed into a user command or nodefunction call you need to use parval(),parnode() or parstr() for each one to interpret numeric, object and string parameters respectively.

So if you call a function with something like:

myfunction( "Hello", 67, rank(model(),5) ) ;

you'd access those in the function with:

string greetingstr= parstr(1);
int thenumber=parval(2);
treenode anobject=parnode(3);

So you can use each to interpret the parameter - where the number in brackets is the nth parameter. You're just telling flexscript how to interpret each parameter.

For help on any function/command you can press F1 while the command is highlighted in a code window or the cursor positioned in it, so if you do that for the parval/node/str() functions you'll get a better description.
Reply With Quote
The Following 3 Users Say Thank You to Jason Lightfoot For This Useful Post:
Jörg Vogel (12-10-2012), mearjun (12-08-2012), Steven Hamoen (12-08-2012)
  #8  
Old 12-08-2012
mearjun mearjun is offline
Flexsim User
 
Join Date: Feb 2012
Posts: 123
Downloads: 5
Uploads: 0
Thanks: 27
Thanked 19 Times in 11 Posts
Rep Power: 113
mearjun will become famous soon enough
Default

Thanks a lot.. I think I have a much better idea now.. Agian thanks a ton...!!!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write coding for that? stmyint Container Terminal (CT) Library 5 10-29-2012 08:03 PM
findInCode User Command Jason Lightfoot User Development 19 05-21-2012 02:16 PM
Modified User Command Gui Esther Bennett Q&A 1 01-06-2010 03:55 AM
Can I write to the system console? Steven Hamoen Q&A 2 11-26-2008 06:37 AM
Dynamic script generation: Good Example with a User Command Naresh Yamani Tips and Tricks 2 05-16-2008 06:54 PM


All times are GMT -6. The time now is 12:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.