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 > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 06-23-2015
David Chan David Chan is offline
Flexsim Distributor
 
Join Date: Sep 2007
Posts: 326
Downloads: 74
Uploads: 0
Thanks: 217
Thanked 73 Times in 44 Posts
Rep Power: 218
David Chan has a spectacular aura aboutDavid Chan has a spectacular aura aboutDavid Chan has a spectacular aura about
Default Question on copyvariable

Hi

I am trying to copy the exittrigger from one source to another using code.

This is what I used.

switch_selected(node("Source3", model()),1);

copyvariable(node("Source2", model()),node(">exittrigger", node("Source2", model())));

But an error appear "The variable that you specified does not exis on the highlighted object"

What does it mean and why this happen?

What is the right way of doing it?
__________________
Advent2 Labs
David
  #2  
Old 06-24-2015
sagar bolisetti's Avatar
sagar bolisetti sagar bolisetti is offline
Flexsim User
 
Join Date: Aug 2013
Location: Hyderabad,India
Posts: 160
Downloads: 145
Uploads: 0
Thanks: 124
Thanked 99 Times in 63 Posts
Rep Power: 150
sagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the rough
Default

Hi David,

This might be the code.You are not copying the variable to highlighted object but to itself.Other way to copy the variable into selected objects in the model is the command selectedobject() that gets the highlighted object.

switch_selected(node("Source3", model()),1);
copyvariable(node("Source3", model()),node(">exittrigger", node("Source2", model())));
or
copyvariable(selectedobject(ownerview(c)),node(">e xittrigger", node("Source2", model())));

Last edited by sagar bolisetti; 06-24-2015 at 07:53 AM.
The Following User Says Thank You to sagar bolisetti For This Useful Post:
David Chan (06-24-2015)
  #3  
Old 06-26-2015
David Chan David Chan is offline
Flexsim Distributor
 
Join Date: Sep 2007
Posts: 326
Downloads: 74
Uploads: 0
Thanks: 217
Thanked 73 Times in 44 Posts
Rep Power: 218
David Chan has a spectacular aura aboutDavid Chan has a spectacular aura aboutDavid Chan has a spectacular aura about
Default

sagar

First of all thanks for the reply. I have tried your suggestion. Unfortunately it did not work. what is ownerview(c)?
__________________
Advent2 Labs
David
  #4  
Old 06-27-2015
sagar bolisetti's Avatar
sagar bolisetti sagar bolisetti is offline
Flexsim User
 
Join Date: Aug 2013
Location: Hyderabad,India
Posts: 160
Downloads: 145
Uploads: 0
Thanks: 124
Thanked 99 Times in 63 Posts
Rep Power: 150
sagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the rough
Default

Hi David,

I am sorry selectedobject() does not gets the selected object(red bounding box) but the highlighted object(yellow bounding box) that won't work in this case.Ownerview() is the command that gets the topmost node of the view structure.In this code for source3 object I designate it as so().Please try the following code

Code:
  treenode object = so();
  switch_selected(object,1);
         {
  pt(getnodename(object));
  copyvariable(tonode(getnodename(object)),node(">exittrigger",node("Source2", model())));
         }
The Following 2 Users Say Thank You to sagar bolisetti For This Useful Post:
Jörg Vogel (06-27-2015)
  #5  
Old 06-27-2015
David Chan David Chan is offline
Flexsim Distributor
 
Join Date: Sep 2007
Posts: 326
Downloads: 74
Uploads: 0
Thanks: 217
Thanked 73 Times in 44 Posts
Rep Power: 218
David Chan has a spectacular aura aboutDavid Chan has a spectacular aura aboutDavid Chan has a spectacular aura about
Default

Sagar

Once again thanks for your help. By placing the above code recommended in the Script window, I have selected Source 3 as so(). The error given is that "No object is currently highlighted". Is there a miss?
__________________
Advent2 Labs
David
  #6  
Old 06-27-2015
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: 773
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

Just use createcopy:

createcopy(getvarnode(fromobj,varname),assertvaria ble(toobj,varname,1),1,0,0,1);
The Following 3 Users Say Thank You to Jason Lightfoot For This Useful Post:
sagar bolisetti (06-27-2015)
  #7  
Old 06-27-2015
David Chan David Chan is offline
Flexsim Distributor
 
Join Date: Sep 2007
Posts: 326
Downloads: 74
Uploads: 0
Thanks: 217
Thanked 73 Times in 44 Posts
Rep Power: 218
David Chan has a spectacular aura aboutDavid Chan has a spectacular aura aboutDavid Chan has a spectacular aura about
Default

Jason

Thanks. It works.

But just wonder if there is some problem with this command and how it works? It is being used in the Edit Selected Object -> Copy from Highlighted. Don't quite understand.
__________________
Advent2 Labs
David
  #8  
Old 06-29-2015
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: 773
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

There's no problem with the command - the second parameter is a node that contains the variable name as string data.
The Following User Says Thank You to Jason Lightfoot For This Useful Post:
David Chan (06-29-2015)
  #9  
Old 06-29-2015
David Chan David Chan is offline
Flexsim Distributor
 
Join Date: Sep 2007
Posts: 326
Downloads: 74
Uploads: 0
Thanks: 217
Thanked 73 Times in 44 Posts
Rep Power: 218
David Chan has a spectacular aura aboutDavid Chan has a spectacular aura aboutDavid Chan has a spectacular aura about
Default

Jason

Possible for you to show me how to use copyvariable to copy the exittrigger from Source2 to Source3. Because I keep have the error saying the variable does not exist in the highlighted object.

Thanks
__________________
Advent2 Labs
David
  #10  
Old 06-29-2015
sagar bolisetti's Avatar
sagar bolisetti sagar bolisetti is offline
Flexsim User
 
Join Date: Aug 2013
Location: Hyderabad,India
Posts: 160
Downloads: 145
Uploads: 0
Thanks: 124
Thanked 99 Times in 63 Posts
Rep Power: 150
sagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the rough
Default

Hi David
We usually copy variables from highlighted object to selected object and the same we have to write in the form of code.The error we get because I have not set any highlighted object.The highlighted can be set by using the command setselectedobject() like switch_selected() for red selected objects .This highlighted object is accessed by the command selectedobject() and this command should be used in the first parameter of copyvariable.I was misunderstood the parameters of the copyvariable till yesterday.The two parameters of copyvariable belong to the same object that is highlighted and the variablenamenode are copied to selected object.But before using this copyvariable, we need to set the “selected” flag on the node.Thanks to Jason for suggesting createcopy() command that avoids writing redundant code.

I just tried a small model but not successful yet.In this model if the input of sink is greater than 49 I want this copy operation to take place between highlighted and selected object.Someone may be able to put me in right direction.

Code:
treenode item = parnode(1);
treenode current = ownerobject(c);
int port = parval(2);
treenode object1 = inobject(current,1);
treenode object2 = c;
if(getinput(current)>49)
{
setselectedobject(ownerview(c),object2);//highlight object    
switch_selected(object1,1);    
if(switch_selected(object1,-1));//check to see if it is selected
copyvariable(selectedobject(ownerview(c)),node(">entrytrigger",c));
deselectall();//Deselects all objects in the model
stop();
}
Attached Files
File Type: fsm Copy variable.fsm (14.4 KB, 349 views)
The Following User Says Thank You to sagar bolisetti For This Useful Post:
David Chan (06-30-2015)
  #11  
Old 06-29-2015
Jörg Vogel's Avatar
Jörg Vogel Jörg Vogel is offline
Flexsim User
 
Join Date: Sep 2007
Location: Hannover, Germany
Posts: 643
Downloads: 35
Uploads: 0
Thanks: 802
Thanked 665 Times in 410 Posts
Rep Power: 642
Jörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond repute
Default

Hello David,

possibly you copied not the complete source code, but if it is your using code, you should write a slash "/" in front of the object name in the node-command.

Quote:
Originally Posted by David Chan View Post

switch_selected(node("Source3", model()),1);
Because of the missing slash the engine can't find the variable. And beware of this mistake, you have had in every node-reference.

switch_selected(node("/Source3", model()),1);

Jörg
The Following User Says Thank You to Jörg Vogel For This Useful Post:
David Chan (06-30-2015)
  #12  
Old 06-30-2015
David Chan David Chan is offline
Flexsim Distributor
 
Join Date: Sep 2007
Posts: 326
Downloads: 74
Uploads: 0
Thanks: 217
Thanked 73 Times in 44 Posts
Rep Power: 218
David Chan has a spectacular aura aboutDavid Chan has a spectacular aura aboutDavid Chan has a spectacular aura about
Default

Jorge,

Thanks. I have tried. It did not has any difference. When you use the sampler, the node is given without the /. So I am unsure that is problem.

try out.

Thanks
__________________
Advent2 Labs
David
  #13  
Old 06-30-2015
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: 773
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

If you're just copying from one known object to another and not using a selection set, then why are you interested in finding the highlighted, selecting the target and using the command that is purposed for the GUI interface?

If it's for ease of reading your code, create a user command: copyVariable(<fromobj>, <toobj>,<variablename>)

Code:
treenode fromobj=parval(1);
treenode toobj=parval(2);
string varname=parstr(3);
createcopy(getvarnode(fromobj,varname),assertvaria ble(toobj,varname,1),1,0,0,1);
The Following 2 Users Say Thank You to Jason Lightfoot For This Useful Post:
sagar bolisetti (06-30-2015)
  #14  
Old 06-30-2015
David Chan David Chan is offline
Flexsim Distributor
 
Join Date: Sep 2007
Posts: 326
Downloads: 74
Uploads: 0
Thanks: 217
Thanked 73 Times in 44 Posts
Rep Power: 218
David Chan has a spectacular aura aboutDavid Chan has a spectacular aura aboutDavid Chan has a spectacular aura about
Default

Sagar,

thanks. I kept having an error on the command ownerview(c). Try to run your model with out the "if" requirement. Check if you have the error too.

David
__________________
Advent2 Labs
David
  #15  
Old 06-30-2015
sagar bolisetti's Avatar
sagar bolisetti sagar bolisetti is offline
Flexsim User
 
Join Date: Aug 2013
Location: Hyderabad,India
Posts: 160
Downloads: 145
Uploads: 0
Thanks: 124
Thanked 99 Times in 63 Posts
Rep Power: 150
sagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the rough
Default

Hi David,

Probably it has to do something with the VIEW tree to get the path of the trigger in the first parameter of setselectedobject().Btw you no longer require slash before the object name in Flexsim 7.See this Post
The Following User Says Thank You to sagar bolisetti For This Useful Post:
Jörg Vogel (06-30-2015)
  #16  
Old 06-30-2015
Jörg Vogel's Avatar
Jörg Vogel Jörg Vogel is offline
Flexsim User
 
Join Date: Sep 2007
Location: Hannover, Germany
Posts: 643
Downloads: 35
Uploads: 0
Thanks: 802
Thanked 665 Times in 410 Posts
Rep Power: 642
Jörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond repute
Default

Hello Sagar,

I think it has more to do with getting an object highlighted by command [yellow frame]. Selecting an object works [red frame], but how to write a source code wherein the simple procedure is implemented clicking with the mouse pointer on an object.

Jörg
The Following 2 Users Say Thank You to Jörg Vogel For This Useful Post:
sagar bolisetti (06-30-2015)
  #17  
Old 06-30-2015
arunkrmahadeva's Avatar
arunkrmahadeva arunkrmahadeva is offline
CCS, India
 
Join Date: Sep 2013
Location: India
Posts: 71
Downloads: 67
Uploads: 0
Thanks: 285
Thanked 101 Times in 51 Posts
Rep Power: 145
arunkrmahadeva is a jewel in the rougharunkrmahadeva is a jewel in the rougharunkrmahadeva is a jewel in the rougharunkrmahadeva is a jewel in the rough
Default

Hi all,

If we use activedocumentnode() command as parameter 1 in the setselectedobject command, the second parameter, which is an object will be yellow highlighted.

treenode acc = activedocumentnode();
setselectedobject(acc,current);

In the attached model, the setselectedobject command is selecting the object which is the 2nd parameter. Moreover, the owner view of the object going to be selected is the perspective view. So when I use activedocumentnode(), it returns a reference to the perspective view, which is the active document node. If I am wrong anywhere, please correct me.

Regards,

Arun KR
Attached Files
File Type: fsm Yellow Select_Code.fsm (14.5 KB, 335 views)

Last edited by arunkrmahadeva; 06-30-2015 at 10:42 AM. Reason: adding more description
The Following 3 Users Say Thank You to arunkrmahadeva For This Useful Post:
sagar bolisetti (06-30-2015)
  #18  
Old 06-30-2015
sagar bolisetti's Avatar
sagar bolisetti sagar bolisetti is offline
Flexsim User
 
Join Date: Aug 2013
Location: Hyderabad,India
Posts: 160
Downloads: 145
Uploads: 0
Thanks: 124
Thanked 99 Times in 63 Posts
Rep Power: 150
sagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the roughsagar bolisetti is a jewel in the rough
Default

Hi Jorg,

Absolutely!In the midway of solving this problem after going through some relevant commands I realized that these commands are more for developers than for regular users like getting the node associated with the window.I am happy that i have learnt few commands.
@Arun:Thanks,that’s the right command.Somemore information while using this command activedocumentnode()
https://www.flexsim.com/community/fo...77&postcount=4

Last edited by sagar bolisetti; 06-30-2015 at 11:29 PM.
The Following User Says Thank You to sagar bolisetti For This Useful Post:
David Chan (07-01-2015)

Tags
copyvariable



All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.